Skip to content

Fix npm-http-dependency false positive on metadata URL fields#778

Merged
christophetd merged 2 commits into
v3from
fix/npm-http-dependency-metadata-url-fp
Jun 18, 2026
Merged

Fix npm-http-dependency false positive on metadata URL fields#778
christophetd merged 2 commits into
v3from
fix/npm-http-dependency-metadata-url-fp

Conversation

@christophetd

@christophetd christophetd commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

The npm-http-dependency rule flags packages whose package.json contains a plain http:// URL that isn't a recognized metadata field, on the assumption it's a dependency specifier (#http_plain > #http_meta), but some legitimate package.json files matched, especially some with nested author.url keys (see regression test)

The npm-http-dependency rule treats any plain http:// value that is not a
known metadata field as a dependency URL (#http_plain > #http_meta). Nested
metadata objects (author, repository, bugs, funding) carry their URL under a
"url" key, which was missing from the allowlist, so packages with an
http author/repo URL (e.g. "author": { "url": "http://..." }) were
falsely flagged.

Add "url" to the metadata-field allowlist and extend the benign fixture to
cover author/repository/bugs URLs over http.
@christophetd christophetd requested a review from a team as a code owner June 17, 2026 15:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 611b193b88

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Plain-http URLs in package metadata fields (author/repo/homepage).
// `url` covers the nested URL key used by author/repository/bugs/funding
// objects (e.g. "author": { "url": "http://..." }), a common false positive.
$http_meta = /"(url|web|website|homepage|funding|bugs|email|wiki|blog|docs|documentation|repository|author|maintainers|contributors|logo|image)"\s*:\s*"http:\/\// nocase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep dependency key url from bypassing the rule

If a package depends on the npm package named url with a plain-HTTP specifier such as "dependencies": {"url": "http://evil.example/pkg"}, this new allowlist entry makes the same string count as both $http_plain and $http_meta. Because the condition only fires on #http_plain > #http_meta, the single suspicious dependency is no longer reported unless it also matches the IP/archive-specific patterns; before this change it was caught. The url allowance needs to be constrained to metadata object contexts rather than any key named url.

Useful? React with 👍 / 👎.

@christophetd christophetd Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in 0e975e1: the bare url allowlist entry is replaced with a dedicated $http_meta_url pattern that matches the nested url key only inside a metadata object (author, repository, bugs, funding, contributors, maintainers). A dependency literally named url with a plain-http specifier ("dependencies": {"url": "http://..."}) is reported again. Added a positive fixture (threat-npm-http-dependency.url-dep.json) to lock this in.

Addresses review feedback: allowlisting any key named "url" let a dependency
literally named "url" with a plain-http specifier ("dependencies": {"url":
"http://..."}) count as both $http_plain and $http_meta, so it was no longer
reported. Replace the bare "url" allowlist entry with $http_meta_url, which
matches the nested "url" key only inside a metadata object (author, repository,
bugs, funding, contributors, maintainers). A url dependency over http is caught
again, while benign metadata URLs stay suppressed.

Add a positive fixture covering the url-as-dependency case.
@christophetd christophetd merged commit 2414f1c into v3 Jun 18, 2026
5 checks passed
@christophetd christophetd deleted the fix/npm-http-dependency-metadata-url-fp branch June 18, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants