GeezerVison is showing github.com — Add npm risky_new_dependency metadata rule by christophetd · Pull Request #779 · DataDog/guarddog
Conversation
Adds an npm metadata rule, risky_new_dependency, that flags a package whose scanned version introduced a dependency that is itself high risk.
How it works
- Diff vs the previous version (no extra fetch). The registry metadata GuardDog already downloads contains every version's
dependencies plus a time map. The detector takes the version published just before the scanned one and computes newly-added dependency names (a version bump of an existing dep is not "new").
- Each new dependency is scanned as a real package, sandboxed identically to the parent. The sub-scan runs as a subprocess
guarddog npm scan <dep>, taking the same CLI path; the parent's sandbox decision is propagated via the GUARDDOG_SUBSCAN_SANDBOX env var. In-process scanning couldn't match the parent's sandbox (applied once, permanently).
- Source-code rules only. The sub-scan excludes all metadata rules: a maliciously introduced dependency shows up in its code, and metadata rules (typosquatting, manifest-mismatch, …) were the dominant FP source. Excluding metadata also excludes this rule, so the check can't recurse.
- Threshold. The parent is flagged when a new dep scores >=
GUARDDOG_NEW_DEPENDENCY_RISK_THRESHOLD (default 5.0). It's a normal metadata rule, so it counts toward issues/exit codes and renders through all reporters.
Evidence that it doesn't add noise
I scanned the top 1k packages on npm, plus a sample of 2k amongst the top 1-to-20k most popular packages (total 3k packages). In the current state:
- 169/3000 introduced a new dependency in their latest version (with regards to the second to last version)
- Out of these 169 newly-introduced dependency, 1 would have matched the threshold 5/10 (@chakra-ui/react for the new
@ark-ui/[email protected] dependency))
Evidence that it would detect real threats
Axios: The payload was delivered through a new dependency plain-crypto-js, which GuardDog flags with score >= 5 when scanning with source code rules only:
$ poetry run guarddog npm scan https://github.com/DataDog/malicious-software-packages-dataset/raw/refs/heads/main/samples/npm/malicious_intent/plain-crypto-js/4.2.1/2026-03-31-plain-crypto-js-v4.2.1.zip --zip-password infected --sandbox
(...)
Assessment: Suspicious (5.3/10)
Mastra: Backdoored a bunch of packages by adding the easy-day-js dependency. This rule would have caught it too, since it flags easy-day-js with a score >= 5:
$ poetry run guarddog npm scan https://github.com/DataDog/malicious-software-packages-dataset/raw/refs/heads/main/samples/npm/malicious_intent/easy-day-js/1.11.22/2026-06-17-easy-day-js-v1.11.22.zip --zip-password infected --sandbox
(...)
Assessment: High risk (7.3/10)
Sample output
Open questions / discussion
- So far we retrieve the previous version as "last version published before the currently scanned one, based on publishing time". We might want to do it based on semver versioning, but in the general case, they should be equivalent
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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: 282b3c84c7
ℹ️ 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".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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: f499dfd32a
ℹ️ 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".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
- Default: 5.0
|
|
|
"""
|
|
|
NEW_DEPENDENCY_RISK_THRESHOLD: float = float(
|
|
|
os.environ.get("GUARDDOG_NEW_DEPENDENCY_RISK_THRESHOLD", 5.0)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Flags dependencies newly introduced in a package version (relative to the
previous published version) that are themselves high risk. The previous
version is derived from the registry 'time' map; any dependency name present
in the scanned version but absent from the previous one is scanned as a
standalone package via a subprocess invocation of guarddog, so it is sandboxed
identically to the parent. The sub-scan runs source-code rules only (all
metadata rules excluded, which also excludes this rule, preventing recursion),
and the parent is flagged when a new dependency scores at or above the
configurable threshold (GUARDDOG_NEW_DEPENDENCY_RISK_THRESHOLD, default 7.0).
Also extracts shared npm version-resolution helpers into guarddog/utils/npm.py
(reused by the project scanner) and stops the human-readable reporter from
emitting an empty location line for metadata findings.
With the sub-scan running source-code rules only, the 5.0-6.9 (suspicious)
band was empty of false positives across 3000 popular npm packages, so the
metadata noise that previously justified a 7.0 default is gone. Lower the
default to 5.0 to catch genuinely suspicious newly-added dependencies.
…endency
Addresses review feedback:
- The new-dependency diff and sub-scan now resolve npm aliases to the real
package (e.g. "x": "npm:evil@1" scans evil, not x). Because the diff is
built from resolved package names, an alias retargeted to a different package
under the same key is also detected.
- optionalDependencies are now included alongside dependencies (npm installs
them by default), closing an install-time coverage gap. devDependencies stay
excluded (not installed for consumers).
Alias handling (NPM_ALIAS_PATTERN / resolve_npm_alias) is lifted into
guarddog/utils/npm.py and reused by the project scanner.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|