<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
---
name: detecting-dependency-namespace-attacks
description: >-
  Detect namespace attacks on package registries including scope squatting,
  package name collision across ecosystems, and organizational namespace
  hijacking that enable dependency substitution attacks.
domain: cybersecurity
subdomain: supply-chain-security
tags:
  - namespace-attacks
  - scope-squatting
  - package-collision
  - registry-security
  - namespace-hijacking
  - dependency-substitution
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1195.002"]
---

# Detecting Dependency Namespace Attacks

## Overview

Namespace attacks exploit how package managers resolve names across public and
private registries. This includes scope/organization squatting on npm, namespace
collision between ecosystems (PyPI vs. conda), and hijacking abandoned or expired
organizational namespaces. These attacks enable dependency substitution without
triggering standard security controls.

Mode: `[MODE: RED]` — Detect and analyze namespace attack vectors across package ecosystems.

## Prerequisites

| Requirement | Details |
|---|---|
| npm CLI for registry queries | Required |
| pip for PyPI queries | Required |
| curl for API access | Required |
| jq for JSON processing | Required |
| Python 3.10+ with `requests`, `packageurl-python` | Required |

## Key Concepts

### Scope Squatting Detection

```bash
# Check if organizational scopes exist on public npm
curl -s "https://registry.npmjs.org/@internal-org" | jq '.error // "SCOPE_EXISTS"'

# List packages under a scope
npm search --json @company-name/ 2>/dev/null | jq '.[].name'

# Detect private packages available on public registry
for pkg in $(jq -r '.dependencies | keys[]' package.json); do
  status=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/$pkg")
  echo "$pkg: $status"
done
```

### Cross-Ecosystem Collision

```bash
# Check if package name exists on both npm and PyPI
check_collision() {
  npm_status=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/$1")
  pypi_status=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/$1/json")
  echo "$1: npm=$npm_status pypi=$pypi_status"
}
check_collision "my-package"

# Verify Go module namespace ownership
curl -s "https://pkg.go.dev/github.com/org/module" | grep -i "not found"
```

### Namespace Ownership Verification

```bash
# Verify npm org membership
npm org ls my-org --json 2>/dev/null | jq 'keys'

# Check PyPI project ownership
curl -s "https://pypi.org/pypi/package-name/json" | jq '{
  author: .info.author,
  author_email: .info.author_email,
  maintainer: .info.maintainer,
  home_page: .info.home_page
}'

# Verify GitHub org ownership for Go modules
gh api orgs/org-name --jq '{login, description, verified}'
```

## Workflow

### Step 1: Scan for namespace attack vectors

```bash
node scripts/agent.js --action scan --manifest /tmp/target --output /tmp/scan-result.json
```

### Step 2: Verify namespace ownership across registries

```bash
node scripts/agent.js --action verify --manifest /tmp/target --output /tmp/verify-result.json
```

### Step 3: Generate namespace security assessment

```bash
node scripts/agent.js --action report --manifest /tmp/target --output /tmp/report-result.json
```

## Detection

```yaml
title: Dependency Namespace Attacks Detection
id: c6ef451d-a8c9-448f-9465-669a27a8a681
status: experimental
description: Detects suspicious activity related to detecting dependency namespace attacks techniques in supply chain security context
logsource:
  category: process_creation
  product: linux
detection:
  selection:
    CommandLine: "*detecting*dependency*"
  condition: selection
level: medium
tags:
  - attack.t1195.002
  - attack.initial_access
falsepositives:
  - Package manager performing routine dependency resolution
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Dependency Namespace Attacks Detection | linux/process_creation | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1195.002 |

## Verification

- [ ] Internal package names do not collide with public registries
- [ ] Organizational scopes are claimed on all relevant registries
- [ ] No abandoned or expired namespaces in dependency tree
- [ ] Cross-ecosystem name collisions documented and mitigated
- [ ] Registry scoping configured for private packages

## References

- [npm Scope Documentation](https://docs.npmjs.com/about-scopes)
- [PyPI Namespace Policy](https://pypi.org/policy/)
- [Dependency Confusion Research](https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610)
- [Go Module Namespace](https://go.dev/ref/mod)
