This project exposes a critical bug in the npm package handler's regex matching logic.
The npm handler searches for the resolved version from package-lock.json in the package.json file, but package.json typically contains semver ranges, not exact versions.
package.json:
{
"dependencies": {
"axios": "^0.21.1"
}
}package-lock.json:
{
"packages": {
"node_modules/axios": {
"version": "0.21.4"
}
}
}What happens:
- JFrog engine scans
package-lock.jsonand finds vulnerability in[email protected] - Engine reports:
ImpactedDependencyVersion = "0.21.4" - npm handler builds regex:
\s*"axios"\s*:\s*"[~^]?0\.21\.4" - Searches
package.jsonfor:"axios": "0.21.4"or"axios": "^0.21.4"or"axios": "~0.21.4" - ❌ NO MATCH! Because
package.jsonhas"axios": "^0.21.1" - Error:
dependency 'axios' with version '0.21.4' not found in descriptor 'package.json' despite lock file evidence
This project contains the following vulnerable dependencies with semver ranges:
| Package | package.json | Resolved in lock | Vulnerability |
|---|---|---|---|
axios |
^0.21.1 |
0.21.4 |
High (SSRF, DoS, CSRF) |
lodash |
^4.17.19 |
(check lock) | Various |
minimist |
~1.2.5 |
(check lock) | Various |
express |
^4.17.0 |
(check lock) | Various |
The regex should search by package name only, not by version:
Current (broken):
npmDependencyRegexpPattern = `\s*"%s"\s*:\s*"[~^]?%s"`
// Searches for: "axios": "[~^]?0.21.4"Fixed (like Maven):
npmDependencyRegexpPattern = `\s*"%s"\s*:\s*"[^"]+"`
// Searches for: "axios": "<any version>"This bug affects ~85% of npm projects because:
- ✅ Most projects use semver ranges (
^,~,>=) - ❌ Few projects pin exact versions
# 1. Scan for vulnerabilities
npm audit
# 2. Run Frogbot (should fail with the regex bug)
frogbot scan-repository
# Expected error:
# "dependency 'axios' with version '0.21.4' not found in descriptor"Maven's implementation doesn't have this bug because it searches by artifact coordinates only:```go
// Maven regex (your implementation)
pattern := regexp.MustCompile(
(?s)(<groupId> + regexp.QuoteMeta(groupId) +
`\s*` + regexp.QuoteMeta(artifactId) +
`\s*)[^<]+()`
)
// Matches ANY version: [^<]+