GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add npm risky_new_dependency metadata rule by christophetd · Pull Request #779 · DataDog/guarddog

Conversation

@christophetd

@christophetd christophetd commented Jun 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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))
image

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

image

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.

All reactions
@christophetd
christophetd requested a review from a team as a code owner June 17, 2026 15:28
@christophetd
christophetd marked this pull request as draft June 17, 2026 15:29
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Jun 17, 2026
View reviewed changes

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

Copy link
Copy Markdown

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.

All reactions
Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@christophetd
christophetd marked this pull request as ready for review June 17, 2026 16:13
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Jun 17, 2026
View reviewed changes

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

Copy link
Copy Markdown

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.

All reactions
Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

christophetd
christophetd commented Jun 17, 2026
View reviewed changes
Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

sobregosodd
sobregosodd reviewed Jun 19, 2026
View reviewed changes
Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@christophetd
christophetd force-pushed the feat/npm-risky-new-dependency-rule branch from f499dfd to d4b660b Compare June 23, 2026 11:32
sobregosodd
sobregosodd reviewed Jun 29, 2026
View reviewed changes
Comment thread guarddog/analyzer/metadata/npm/risky_new_dependency.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread guarddog/utils/config.py
- Default: 5.0
"""
NEW_DEPENDENCY_RISK_THRESHOLD: float = float(
os.environ.get("GUARDDOG_NEW_DEPENDENCY_RISK_THRESHOLD", 5.0)

@sobregosodd sobregosodd Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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.

same about documenting:
https://github.com/DataDog/guarddog#configuration-via-environment-variables

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@christophetd christophetd Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

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.

agreed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@christophetd christophetd Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

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.

done in 80b5464

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sobregosodd
sobregosodd previously approved these changes Jul 8, 2026
View reviewed changes
christophetd added 6 commits July 8, 2026 16:10
@christophetd
Add npm risky_new_dependency metadata rule
999a50e
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.
@christophetd
Lower risky_new_dependency default threshold to 5.0
9c487f1
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.
@christophetd
Resolve npm aliases and include optionalDependencies in risky_new_dep…
e9aacd9
…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.
@christophetd
Reuse RiskLabel enum for risky_new_dependency label phrasing
69fa222
@christophetd
Document new environment variable
93b6d6d
@christophetd
Autogenerate rules docs
8cb2465
@christophetd
christophetd dismissed sobregosodd’s stale review via 8cb2465 July 8, 2026 14:14
@christophetd
christophetd force-pushed the feat/npm-risky-new-dependency-rule branch from 0ec615d to 8cb2465 Compare July 8, 2026 14:14
sobregosodd
sobregosodd approved these changes Jul 8, 2026
View reviewed changes
@christophetd
christophetd merged commit 8d5f5c8 into v3 Jul 8, 2026
8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@christophetd
christophetd deleted the feat/npm-risky-new-dependency-rule branch July 8, 2026 14:29
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#978
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments
@sobregosodd sobregosodd sobregosodd approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@christophetd @sobregosodd
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.