Skip to main content

SKY-D222 · AI-code defects

Dependency hallucination

Critical

CRITICAL when the package does not exist in its registry. HIGH when it exists but its name is one letter away from a popular package, such as reqeusts for requests (a possible typosquat).

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 while block_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 done lists it as advice unless unknown_imports = "block" is set under [tool.skylos.done.checks].
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/webhooks.py · PythonReported on line 4
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

app/webhooks.py: same as in the flagged example.

stripe_webhook_guard.py · Python
"""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 None

Why 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

package.json · JSONReported on line 7
{  "name": "checkout-api",  "version": "1.0.0",  "private": true,  "dependencies": {    "express": "4.21.2",    "express-csrf-shield": "2.1.0"  }}

Not flagged

package.json · JSON
{  "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

  1. 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 ImportError that have a fallback.
  2. 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 the SKYLOS_PRIVATE_DEPS_ALLOW environment variable are skipped.
  3. Manifests and install commands: reads requirements.txt, pyproject.toml, package.json, go.mod and other manifests up to three folders deep, plus pip install name==1.0, npm install name@1.0 and go get lines in shell scripts, Dockerfiles, .github/workflows files 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.
  4. 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, lodash and others): HIGH. Version missing: SKY-D225.
  5. 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 .npmrc registry, 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.

Fix · Python
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-url in requirements.txt, an .npmrc registry), or list the names in SKYLOS_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] with workspace = true or a path.
  • 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.