Skip to content

Commit b48eb17

Browse files
committed
fix(security): vuln-scan false positive from checking declared semver range instead of resolved version
_parse_bun_lock() collected packages from TWO sources: workspaces.dependencies (declared semver ranges from package.json, e.g. '^9.0.0') AND packages (resolved concrete versions from the lockfile, e.g. '9.0.2'). Both were fed into the same vulnerability-matching loop as if they were equally valid 'installed versions'. _compare_versions()'s _parse_ver() extracts leading digits per dot-separated segment via regex ^(\d+) — for '^9.0.0', the first segment '^9' has no leading digit (the caret isn't stripped), so it silently parses to 0. This makes '^9.0.0' compare as if it were '0.0.0', matching ANY '<X.Y.Z' vulnerable_range regardless of the real installed version. Found via real-codebase validation (Coretax-Auto-Downloader KDS backend): jsonwebtoken reported 'installed_version': '^9.0.0' against 'vulnerable_range': '<9.0.0' — 9.0.0 is not less than 9.0.0, so this was a false positive purely from checking the declared range string. Fix: only collect from the 'packages' (resolved) section — remove the workspaces.dependencies collection entirely, since it duplicates data already present (correctly, as concrete versions) in 'packages'. Verified: total vuln findings 22 -> 13, jsonwebtoken false positives (4) eliminated entirely.
1 parent 6f5ee05 commit b48eb17

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

scripts/vulnscan_engine.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,14 +3471,18 @@ def _parse_bun_lock(content: str) -> List[Tuple[str, str]]:
34713471
except json.JSONDecodeError:
34723472
return packages
34733473

3474-
# Extract from workspaces dependencies (top-level declared deps)
3475-
workspaces = data.get("workspaces", {})
3476-
for ws_name, ws_data in workspaces.items():
3477-
for dep_type in ("dependencies", "devDependencies"):
3478-
deps = ws_data.get(dep_type, {})
3479-
for name, version in deps.items():
3480-
if name and version:
3481-
packages.append((name, version))
3474+
# Note: workspaces.dependencies/devDependencies are declared semver RANGES
3475+
# from package.json (e.g. "^9.0.0", "~1.2.0") — not concrete installed
3476+
# versions. They must NOT be checked directly against vulnerable_range:
3477+
# _is_version_vulnerable()/_compare_versions() parse a leading "^"/"~" as
3478+
# a non-digit, silently truncating "^9.0.0" to [0,0,0] and making the
3479+
# package match ANY "<X.Y.Z" vulnerability range, regardless of the real
3480+
# installed version. Found via real-codebase validation: jsonwebtoken
3481+
# "installed_version": "^9.0.0" (the declared range) was flagged against
3482+
# "vulnerable_range": "<9.0.0" — 9.0.0 is not less than 9.0.0, so this was
3483+
# a false positive purely from checking the range string instead of the
3484+
# resolved version. Only the "packages" section below (resolved installs)
3485+
# has concrete versions suitable for vulnerability matching.
34823486

34833487
# Extract from packages (resolved packages with exact versions)
34843488
# Format: "pkg-name": ["pkg-name@version", "", {...}, "hash"]

0 commit comments

Comments
 (0)