Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(deps): skip workspace/link/portal/file entries in yarn.lock (#21)

pethapixels-create2f5aefe2ee47
diff --git a/src/deps.rs b/src/deps.rs
index 9a2f344..4475cf1 100644
--- a/src/deps.rs
+++ b/src/deps.rs
@@ -97,10 +97,21 @@ fn yarn_lock(file: &FileInfo, text: &str) -> Vec<Package> {
.unwrap_or("")
.trim()
.trim_matches('"');
- current = first
- .rfind('@')
- .filter(|&i| i > 0)
- .map(|i| first[..i].to_string());
+ // A workspace, link, portal or file descriptor (e.g. `my-app@workspace:.`) is not a
+ // package fetched from the registry. Its `version` is a local placeholder like
+ // `0.0-0-use.local`, and sending the name to OSV can match an unrelated public
+ // package. `npm_lock` already skips `link: true`; do the same here.
+ let local = ["@workspace:", "@link:", "@portal:", "@file:"]
+ .iter()
+ .any(|sep| first.contains(sep));
+ current = if local {
+ None
+ } else {
+ first
+ .rfind('@')
+ .filter(|&i| i > 0)
+ .map(|i| first[..i].to_string())
+ };
} else if let (Some(name), Some(v)) = (&current, line.trim().strip_prefix("version ")) {
out.push(pkg("npm", name, v.trim_matches('"'), file, i + 1));
current = None;
diff --git a/tests/fixtures/deps/web/yarn.lock b/tests/fixtures/deps/web/yarn.lock
new file mode 100644
index 0000000..82bb4be
--- /dev/null
+++ b/tests/fixtures/deps/web/yarn.lock
@@ -0,0 +1,8 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"my-app@workspace:.":
+ version "0.0.0-use.local"
+ resolved "file:."
+ linkType soft
\ No newline at end of file
diff --git a/tests/scan.rs b/tests/scan.rs
index 77e5e14..b82be8d 100644
--- a/tests/scan.rs
+++ b/tests/scan.rs
@@ -98,5 +98,7 @@ fn deps() {
advisories: Some(Box::new(known)),
include_tests: false,
};
+ // The web/yarn.lock fixture contains a `my-app@workspace:.` entry that must be
+ // skipped (not counted as a dependency). The expected package count stays 18.
check_with("deps", options, Some(18));
}