SKY-D222 · AI-code defects
Dependency hallucination
A hallucinated dependency is a package the code imports or a manifest lists that does not exist in the package registry, because a coding agent invented a plausible name. SKY-D222 checks Python imports against PyPI, and the entries of requirements.txt, pyproject.toml, package.json and go.mod, plus pip install, npm install and go get commands, against PyPI, npm and the Go module proxy.
- Languages
- Python, JavaScript/TypeScript (npm), Go modules, install commands in scripts, Dockerfiles, CI files and docs
- Turned on by
skylos . --ai-defects(or-a) with network access to PyPI, the npm registry and the Go module proxy- Quality gate
- counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). Counts toward
max_ai_defects. A CRITICAL finding fails the gate on its own whileblock_ai_defect_severities(under[tool.skylos.gate]) keeps its default["CRITICAL"]; the HIGH look-alike finding only counts. The agent hook (skylos verify) blocks on it.skylos donelists it as advice unlessunknown_imports = "block"is set under[tool.skylos.done.checks]. - Finding type
- review
Why it matters
The install fails at best. At worst someone registers the invented name first ("slopsquatting"), and the next pip install runs their code on your laptop or in CI with your credentials. Attackers watch for the names agents tend to invent.
What Skylos flags
import os from flask import Flask, abort, requestfrom stripe_webhook_guard import verify_event app = Flask(__name__)WEBHOOK_SECRET = os.environ["STRIPE_WEBHOOK_SECRET"] @app.post("/webhooks/stripe")def stripe_webhook(): event = verify_event(request.data, request.headers, WEBHOOK_SECRET) if event is None: abort(400) return {"received": event["id"]}What Skylos leaves alone
"""Our own wrapper around Stripe's webhook signature check.""" import stripe def verify_event(payload, headers, secret): signature = headers.get("Stripe-Signature", "") try: return stripe.Webhook.construct_event(payload, signature, secret) except (ValueError, stripe.error.SignatureVerificationError): return NoneWhy Skylos leaves it alone
The same import is fine here because the project ships stripe_webhook_guard.py itself. Skylos resolves local modules first and asks PyPI only about names that are not part of the project, the standard library or an installed package.
More languages
JSON
Flagged
{ "name": "checkout-api", "version": "1.0.0", "private": true, "dependencies": { "express": "4.21.2", "express-csrf-shield": "2.1.0" }}Not flagged
{ "name": "checkout-api", "version": "1.0.0", "private": true, "dependencies": { "express": "4.21.2", "express-rate-limit": "7.4.0" }}Why Skylos leaves it alone
express-rate-limit is a real npm package, so the registry answers and nothing is reported. express-csrf-shield in the flagged version has no entry in the npm registry at all.
How Skylos decides
- Python imports: for each top-level module a file imports, skips the standard library, the project's own modules and folders, names an installed or declared distribution provides (it reads installed metadata and, for declared packages, the file list of their wheels on PyPI), and imports inside
try/except ImportErrorthat have a fallback. - For a name left over, asks
https://pypi.org/simple/<name>/(also with_turned into-). A 404 for a name longer than two characters and not all capitals is reported as CRITICAL on the import line. If a declared distribution could not be inspected, the import is reported as a possible hallucination under SKY-D223 instead. Names in theSKYLOS_PRIVATE_DEPS_ALLOWenvironment variable are skipped. - Manifests and install commands: reads
requirements.txt,pyproject.toml,package.json,go.modand other manifests up to three folders deep, pluspip install name==1.0,npm install name@1.0andgo getlines in shell scripts, Dockerfiles,.github/workflowsfiles and shell blocks in Markdown. Only entries with a version (==,~=,>=or an npm or Go version) are checked, and only PyPI, npm and Go packages have a registry check. - Asks the PyPI JSON API, the npm registry or the Go module proxy for the package and version. Package missing: CRITICAL. Package present but its name is one edit away from a popular package (
flask,requests,express,lodashand others): HIGH. Version missing: SKY-D225. - Skips entries the registry cannot answer (network error, timeout), manifests that use a private index (
--index-url,--extra-index-url, a[[tool.poetry.source]], an.npmrcregistry,PIP_INDEX_URL=), and ecosystems without a checker. Answers are cached in.skylos/cache/dependency_versions.json.
How to fix it
Find the real package that does the job and use its documented API, or write the helper yourself. Never pip install or npm install an unknown name to make the error go away: if someone has registered it, that runs their code.
import os import stripefrom flask import Flask, abort, request app = Flask(__name__)WEBHOOK_SECRET = os.environ["STRIPE_WEBHOOK_SECRET"] @app.post("/webhooks/stripe")def stripe_webhook(): signature = request.headers.get("Stripe-Signature", "") try: event = stripe.Webhook.construct_event( request.data, signature, WEBHOOK_SECRET ) except (ValueError, stripe.error.SignatureVerificationError): abort(400) return {"received": event["id"]}When it can be wrong
- A private package installed from your own index is reported when the manifest does not say so. Name the index in the manifest (
--index-urlinrequirements.txt, an.npmrcregistry), or list the names inSKYLOS_PRIVATE_DEPS_ALLOW, comma-separated. - An import name that differs from its distribution name, used by a package that is neither installed nor declared, can be reported when no PyPI project has the import name. Declaring the distribution in the manifest settles it.
- A package of your own repository that is not published, listed with a version in
pyproject.toml("acme-billing-core==2.4.0"), is reported unless a local source names it, for example[tool.uv.sources]withworkspace = trueor apath. - Without network access the registry check cannot answer and nothing is reported, so an offline scan finds no hallucinated packages.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
On the Python import line, with the reason the package is real:
Python from stripe_webhook_guard import verify_event # skylos: ignore[SKY-D222] internal index[tool.skylos] ignore = ["SKY-D222"]turns the rule off for the project.