Sub topic 11
Registry defenses and organizational dependency policy
This chapter covers controls that sit outside the developer's machine: what public registries do about malicious names, and what an organization can enforce so a hallucinated name never reaches an install command. It assumes you have read the chapters on the attack chain, verification, and lockfiles, hash pinning, and restricted install scripts. You should be comfortable with pip, npm, and editing config files such as pip.conf and .npmrc.
What registries can and cannot do
A public registry is a first-come, first-served namespace. If nobody owns the name fastjson-utils, anyone with an account can publish it. A registry cannot tell whether a name was registered because a model keeps inventing it. A brand-new package with a plausible name looks the same as a legitimate new project.
Registries do run defenses, and they help in three ways:
- Account security. PyPI requires two-factor authentication for maintainers. npm requires it for publishing privileged packages and offers it for others. This protects real packages from takeover. It does not stop a new malicious package.
- Publisher identity and provenance. PyPI's Trusted Publishing lets a project publish from a specific CI workflow without a long-lived token. npm provenance statements, and PyPI attestations, link a release to the source repository and build that produced it. A consumer can check that link. A freshly registered slopsquat can also publish provenance, so a valid statement shows where the code came from but not that the code is safe.
- Reactive takedown. Both registries accept malware reports, remove packages, and sometimes replace a removed name with a placeholder so it cannot be re-registered by an attacker. This works, but it is slow compared with an install that happens seconds after a model suggests a name.
Some defenses are name-based. npm rejects new names that differ from an existing name only by punctuation or case, for example reactnative when react-native exists. PyPI normalizes names, so My_Package, my-package, and my.package refer to the same project. These rules help against typosquatting. They do nothing for a name that is not close to anything, which is exactly what a hallucinated name often is.
The conclusion is that a registry reduces the number of bad packages but cannot guarantee a given name is safe. The organization has to add its own gate.
Put a gate between developers and the public registry
The most effective organizational control is a single controlled path for dependencies. Developers, CI jobs, and AI agents install from an internal registry proxy (such as Artifactory, Nexus, AWS CodeArtifact, devpi, or Verdaccio) rather than directly from PyPI or npmjs.org. The proxy fetches from the public registry only for packages that policy allows.
This design has several properties that matter for slopsquatting:
- A hallucinated name that is not on the allowlist fails at the proxy, even if an attacker has already registered it.
- The failure is visible and cheap. The developer sees a blocked install and a ticket instead of a compromised laptop.
- The proxy keeps a cached copy of approved versions, so a later takedown or malicious re-upload upstream does not change what your builds receive.
- Network rules can enforce the path. If build machines and agent sandboxes can reach only the proxy, a stray
pip installagainst the public index cannot succeed.
Point clients at the proxy
Configure clients so the proxy is the only index. For pip, use index-url and avoid extra-index-url. With two indexes, pip picks the highest version across both, which is the mechanism behind dependency confusion.
# /etc/pip.conf (or ~/.config/pip/pip.conf)
[global]
index-url = https://packages.example.internal/simple/For npm, set the default registry in .npmrc. If you publish internal packages under a scope, map that scope explicitly and reserve the same scope name on the public registry so nobody else can take it.
# .npmrc
registry=https://packages.example.internal/npm/
@acme:registry=https://packages.example.internal/npm-internal/Commit these files to the repository so a fresh checkout is already configured. Also set them in CI images and agent sandboxes. A developer's laptop config is the weakest place to rely on.
Allowlists and new-dependency review
An allowlist is a list of package names the organization has approved. It can be strict (only listed names resolve) or advisory (unlisted names trigger review in CI). Start advisory if a strict list would block too much work, then tighten.
The check below compares a requirements file with an allowlist and fails when a name is missing. It normalizes names the way PyPI does, so Typing_Extensions and typing-extensions match. It skips comments and option lines such as --hash=....
import re
import sys
from pathlib import Path
def normalize(name):
return re.sub(r"[-_.]+", "-", name).lower()
def read_names(path):
names = set()
for line in Path(path).read_text().splitlines():
line = line.split("#", 1)[0].strip()
if not line or line.startswith("-"):
continue
match = re.match(r"[A-Za-z0-9][A-Za-z0-9._-]*", line)
if match:
names.add(normalize(match.group()))
return names
if __name__ == "__main__":
allowlist = read_names(sys.argv[1])
requested = read_names(sys.argv[2])
unapproved = sorted(requested - allowlist)
for name in unapproved:
print(f"NOT APPROVED: {name}")
sys.exit(1 if unapproved else 0)Run it as python check_allowlist.py allowlist.txt requirements.txt in CI. Because the lockfile-compiled requirements.txt includes transitive dependencies, the check covers packages nobody typed by hand. That is useful: a new transitive name is a signal worth a look.
A check like this is only half of the control. The other half is process:
- A pull request that adds or changes a dependency manifest or lockfile requires review from a named owner. Use
CODEOWNERSonrequirements*.txt,pyproject.toml,package.json, and lockfiles. - The reviewer applies the verification steps from the earlier chapter: does the package exist, how old is it, who maintains it, does the repository link back to it.
- The reviewer records the decision and adds the name to the allowlist, with the approved version range.
- Changes made by an AI agent follow the same path. The pull request description should say which dependencies were added and who or what suggested them.
Delay brand-new releases
Most malicious packages are caught within hours or days of publication, by registry staff, scanners, or other users. A minimum-age rule exploits this. The proxy or package manager refuses versions published less than, for example, seven days ago.
This is a trade-off. You get a window in which others discover the problem, but you also delay legitimate security patches. Most teams solve that with an exception path for urgent fixes.
Some tools support this directly. pnpm has minimumReleaseAge, measured in minutes, and uv has exclude-newer, which ignores versions uploaded after a given timestamp.
# pnpm-workspace.yaml: ignore versions published in the last 7 days
minimumReleaseAge: 10080# pyproject.toml: resolve only against versions uploaded before this time
[tool.uv]
exclude-newer = "2026-11-21T00:00:00Z"Age rules are especially good against slopsquatting. The attacker registers the hallucinated name after observing the model's output, so the package is by definition young. Age alone is not proof of safety, though. An attacker can register a name and wait. Treat age as one signal next to the allowlist.
Control what agents are allowed to do
Policy has to name AI tools explicitly, because they change who decides to add a dependency. Reasonable rules include:
- Agents may edit manifests but may not run installs with network access to anything except the internal proxy.
- Install commands from agents run in a sandbox with no credentials, no cloud tokens, and no SSH keys in the environment. A malicious install script then has little to steal.
- New dependency names suggested by a model are treated as unverified input and listed in the pull request for human review.
- Install scripts are disabled by default in CI (
npm ci --ignore-scripts, with a documented exception list for packages that need a build step).
Reserve and monitor your own names
Slopsquatting is not limited to public libraries. If models are likely to guess your internal package or product names, for example acme-internal-auth, an attacker can register them publicly. Defensive steps:
- Register placeholder packages for your internal names on public registries, or claim your npm scope.
- Search the registries periodically for new packages that contain your company or product name.
- Log blocked requests at the proxy. A spike of denied requests for the same unknown name is a cheap early warning that a model is suggesting it, and it tells you which names to investigate or reserve.
Choosing how strict to be
| Control | Stops | Cost | Typical fit |
|---|---|---|---|
| Strict allowlist at proxy | Any unapproved name, including hallucinated ones | Review queue, slower onboarding of new libraries | Regulated or high-value environments |
| Advisory CI allowlist check | Unreviewed additions reaching main | Developers can still install locally | Most product teams |
| Minimum release age | Very new malicious uploads | Delayed patches, needs exception path | Everywhere, as a default |
| Proxy-only network egress | Bypassing the gate with direct installs | Network engineering effort | CI and agent sandboxes |
| Reserved names and scopes | Squatting on your own names | Small ongoing upkeep | Any org with internal packages |
No single row is enough. The allowlist handles known names, age handles the window between registration and discovery, and network rules keep people from skipping both.
Common mistakes
- Using
extra-index-urlwith pip. It lets a public package with a higher version number beat your internal one. - Letting the allowlist grow without review. If approvals are rubber-stamped, the list becomes a record of whatever people installed rather than a control.
- Trusting provenance as a safety verdict. It proves origin. A malicious author can have a clean build pipeline.
- Protecting CI but not laptops and agent sandboxes. The first install of a hallucinated name usually happens locally.
- No exception path. If urgent fixes are impossible, people route around the proxy, and you lose both the control and the visibility.
Exercise
Your team configures pip with index-url pointing at the internal proxy and extra-index-url pointing at PyPI "as a fallback." Name two problems this causes for slopsquatting and dependency confusion defenses, and state the fix.
Show answer
First, pip treats both indexes equally and chooses the highest version, so a malicious public package with a higher version number than an internal package of the same name wins (dependency confusion). Second, any name not on the allowlist can still be resolved from PyPI directly, so a registered slopsquat bypasses the proxy gate entirely. The fix is to remove extra-index-url and let the proxy be the only index, with the proxy deciding which public packages it will fetch.
Exercise
A coding agent adds fastjson-utils to requirements.in. The CI allowlist check fails. List the steps a reviewer should take before adding the name to the allowlist, and say what extra information the proxy logs can provide.
Show answer
The reviewer confirms the package exists on the registry, checks its first upload date, release count, maintainers, and whether its linked repository points back to the package, and decides whether a well-known library already does the job. If it is not needed or looks suspicious, the reviewer rejects it and has the agent use an approved library. If approved, the reviewer records the version range and adds the normalized name to the allowlist. The proxy logs show whether other developers or agents requested the same unknown name, which suggests a model is repeatedly suggesting it and that the name may be worth reporting or reserving.