From 0b0bb5cc72d4de5ebddb373882ee4c98a8484a38 Mon Sep 17 00:00:00 2001 From: Tony Jagodka Date: Thu, 12 Nov 2026 12:21:05 -0600 Subject: [PATCH] fix(sc1): skip requirement ranges recorded in npm lockfiles SC1 ran its range patterns over package-lock.json and npm-shrinkwrap.json, so each range an installed package declares for its own dependencies was reported as an unpinned dependency of the skill. The lockfile pins those to exact versions. package.json ranges are still reported. Fixes #1104 Signed-off-by: Tony Jagodka --- CHANGELOG.md | 1 + .../analyzers/static_patterns_supply_chain.py | 5 +- ..._static_patterns_supply_chain_lockfiles.py | 47 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e2a212f2..8f56dee59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 2.12.0 (Unreleased) ### Features/Bug Fixes +* fix(sc1): stop reporting the requirement ranges recorded inside `package-lock.json` and `npm-shrinkwrap.json` as unpinned dependencies; the lockfile pins every install, and `package.json` ranges are still reported (#1104) * fix(deps): bump the locked `pyasn1` from 0.6.4 to 0.6.5 (CVE-2026-119194, CVE-2026-119195, CVE-2026-119196, CVE-2026-119197), `cryptography` from 49.0.0 to 50.0.2 (CVE-2026-69247) and the `[mcp]` extra's `pyjwt` from 2.13.0 to 2.15.1 (CVE-2026-102268 and related advisories) (#1146) * fix(deps): bump the locked `langgraph` from 1.2.6 to 1.2.20 (and `langgraph-checkpoint` 4.1.1 to 4.3.1, which it requires) past GHSA-3fx2-cqw9-xr3c; the locked `langgraph-sdk` 0.4.10 was already patched (#1078) * fix(pi): accept scans from symlinked workspace roots while preserving the CLI's checks on symlinks below the workspace. Custom YARA rules loaded with `--yara-rules-dir` cannot use `include`; place each rule directly in the selected directory. diff --git a/src/skillspector/nodes/analyzers/static_patterns_supply_chain.py b/src/skillspector/nodes/analyzers/static_patterns_supply_chain.py index a86deaf7e..da4d25601 100644 --- a/src/skillspector/nodes/analyzers/static_patterns_supply_chain.py +++ b/src/skillspector/nodes/analyzers/static_patterns_supply_chain.py @@ -2639,7 +2639,10 @@ def line_number(start: int) -> int: tag = [PatternCategory.SUPPLY_CHAIN.value] is_dep_file = _is_dependency_manifest(file_path) - if is_dep_file: + # An npm lockfile pins every install to an exact version. The ranges it also + # records are the installed packages' own declared requirements, so they are + # not unpinned dependencies of the skill. + if is_dep_file and not _is_npm_lockfile(file_path): for pattern, confidence in SC1_PATTERNS: matches = ( static_runner.iter_paragraph_matches diff --git a/tests/nodes/analyzers/test_static_patterns_supply_chain_lockfiles.py b/tests/nodes/analyzers/test_static_patterns_supply_chain_lockfiles.py index 4d9dc662d..973318d85 100644 --- a/tests/nodes/analyzers/test_static_patterns_supply_chain_lockfiles.py +++ b/tests/nodes/analyzers/test_static_patterns_supply_chain_lockfiles.py @@ -110,6 +110,53 @@ def test_toml_lock_parser_returns_empty_for_malformed_toml(): assert supply_chain._extract_packages_from_toml_lock(content) == [] +_NPM_LOCK_WITH_TRANSITIVE_RANGES = """{ + "name": "demo", + "version": "1.0.0", + "lockfileVersion": 3, + "packages": { + "": { + "name": "demo", + "version": "1.0.0", + "dependencies": { + "ajv": "8.17.1" + } + }, + "node_modules/ajv": { + "version": "8.17.1", + "dependencies": { + "fast-deep-equal": "^3.1.3" + }, + "peerDependencies": { + "react": "*" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3" + } + } +} +""" + + +@pytest.mark.parametrize("path", ["package-lock.json", "mcp/npm-shrinkwrap.json"]) +def test_npm_lockfile_requirement_ranges_are_not_unpinned_dependencies(path): + findings = supply_chain.analyze(_NPM_LOCK_WITH_TRANSITIVE_RANGES, path, "json") + + assert not [finding for finding in findings if finding.rule_id == "SC1"] + + +def test_package_json_ranges_are_still_unpinned_dependencies(): + content = '{"dependencies": {"ajv": "^8.17.1", "react": "*"}}' + + findings = supply_chain.analyze(content, "package.json", "json") + + assert {finding.matched_text for finding in findings if finding.rule_id == "SC1"} == { + '"ajv": "^8.17.1"', + '"react": "*"', + } + + @pytest.mark.parametrize("path", ["package.json", "package-lock.json", "npm-shrinkwrap.json"]) @pytest.mark.parametrize("is_cached", [True, False], ids=["present-empty", "missing"]) def test_node_distinguishes_empty_dependency_file_from_missing_cache_entry(