Skip to content

Prevent stale npm metadata false positives in threat detection#35148

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-stale-npm-metadata
May 27, 2026
Merged

Prevent stale npm metadata false positives in threat detection#35148
pelikhan merged 6 commits into
mainfrom
copilot/fix-stale-npm-metadata

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

Threat detection was classifying some npm dependency updates as malicious using stale registry assumptions (e.g., version non-existence). This change updates the malicious-patch criteria so npm lockfile alerts require validation against current npm metadata, including tarball URL and integrity consistency.

  • Threat detection prompt hardening (actions/setup/md/threat_detection.md)

    • Added explicit npm lockfile validation requirements before flagging malicious dependencies.
    • Requires fetching live metadata (npm view <package>@<version> --json or equivalent registry endpoint).
    • Requires all three checks to align with current registry data:
      • version exists,
      • resolved matches official tarball URL,
      • integrity matches official hash.
    • Explicitly treats stale-version claims as false positives when metadata matches.
  • npm registry domain allowlist (pkg/workflow/data/ecosystem_domains.json, pkg/workflow/domains.go)

    • Added registry.npmjs.org to the threat-detection ecosystem domains so detection runs can reach the npm registry for read-only package validation (npm view, integrity/tarball checks).
    • Registry access is restricted to metadata lookups only — installs are not permitted during detection runs.
  • Regression guard on template contract (pkg/workflow/threat_detection_file_access_test.go, pkg/workflow/domains_test.go)

    • Added/updated template assertions to ensure npm metadata validation guidance remains present in the threat-detection prompt.
    • Updated domain allowlist tests to reflect that registry.npmjs.org is now a required detection domain.
- **npm Lockfile Validation** (for `package-lock.json` changes):
  - Fetch current npm metadata using `npm view <package>@<version> --json`
  - Confirm version exists
  - Confirm `resolved` matches official tarball URL
  - Confirm `integrity` matches official hash
  - Treat stale-version claims as false positives when all checks match

Copilot AI and others added 3 commits May 27, 2026 06:55
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix threat detection for stale npm metadata Prevent stale npm metadata false positives in threat detection May 27, 2026
Copilot AI requested a review from mnkiefer May 27, 2026 07:04
@mnkiefer mnkiefer marked this pull request as ready for review May 27, 2026 07:13
Copilot AI review requested due to automatic review settings May 27, 2026 07:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the threat-detection prompt to reduce stale npm metadata false positives when evaluating package-lock.json dependency updates, and adds a regression test to preserve that prompt contract.

Changes:

  • Adds npm lockfile validation guidance requiring current registry metadata checks.
  • Adds template assertions for the new npm validation guidance.
  • Updates the generated compiler threat-spec optimizer lock workflow, including its schedule metadata.
Show a summary per file
File Description
actions/setup/md/threat_detection.md Adds npm metadata validation instructions to the malicious dependency criteria.
pkg/workflow/threat_detection_file_access_test.go Adds a test asserting the prompt contains the npm validation guidance.
.github/workflows/daily-compiler-threat-spec-optimizer.lock.yml Refreshes generated workflow metadata and schedule output.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread actions/setup/md/threat_detection.md
Comment thread .github/workflows/daily-compiler-threat-spec-optimizer.lock.yml Outdated
…ge validation

Add registry.npmjs.org to the threat-detection ecosystem domains so that
detection runs can perform read-only npm package validation (e.g. verifying
lockfile integrity hashes via `npm view`). This does not permit registry
access for installs — only metadata lookups during threat analysis.

Update the GetThreatDetectionAllowedDomains comment and tests accordingly.

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI requested a review from mnkiefer May 27, 2026 08:05
@mnkiefer
Copy link
Copy Markdown
Collaborator

@copilot Revert changes to daily-compiler-threat-spec-optimizer.lock.yml.

…inal state

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2026

@copilot Revert changes to daily-compiler-threat-spec-optimizer.lock.yml.

Done — reverted in 2924050.

@mnkiefer mnkiefer requested review from lpcox and pelikhan May 27, 2026 09:23
@pelikhan pelikhan merged commit 1f7c4df into main May 27, 2026
@pelikhan pelikhan deleted the copilot/fix-stale-npm-metadata branch May 27, 2026 10:02
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.

Threat detection false positive: stale npm metadata

4 participants