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: do not report bun.lockb when bun.lock is beside it (#224)

Alimaf523c92e786b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce1c2b9..87c6f79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+- Dependencies: a binary `bun.lockb` is no longer named when a text `bun.lock` sits beside it in
+ the same folder; the text lockfile was already read, so the old binary one is not an unchecked
+ dependency.
- Dependencies: a binary `bun.lockb` (bun before 1.2) is now named in the report
(`Not checked, binary lockfile: bun.lockb. Run bun install --save-text-lockfile to write
bun.lock.`). It used to be skipped without a word, which read like a clean result.
diff --git a/src/deps.rs b/src/deps.rs
index 63cb692..7e3d9c8 100644
--- a/src/deps.rs
+++ b/src/deps.rs
@@ -107,6 +107,9 @@ fn parser(name: &str) -> Option<Parser> {
})
}
+/// bun's text lockfile (bun 1.2 and later), the one packages are read from.
+pub const BUN_TEXT_LOCKFILE: &str = "bun.lock";
+
/// bun's binary lockfile, written before bun 1.2. It cannot be read for
/// packages, so the scan names it instead of passing over it in silence.
pub const BUN_BINARY_LOCKFILE: &str = "bun.lockb";
diff --git a/src/engine.rs b/src/engine.rs
index 899eaf5..7fed4ea 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -186,6 +186,12 @@ pub fn scan_files(root: &Path, include_tests: bool) -> Scanned {
})
});
let mut scanned = out.into_inner().unwrap();
+ // A binary bun.lockb next to a text bun.lock has already been migrated:
+ // the text lockfile was read, so naming the old one would be misleading.
+ scanned.lockfiles_binary.retain(|rel| {
+ let sibling = base.join(rel).with_file_name(deps::BUN_TEXT_LOCKFILE);
+ !sibling.exists()
+ });
scanned.packages.sort();
scanned.packages.dedup();
scanned.lockfiles_too_large.sort();
diff --git a/tests/scan.rs b/tests/scan.rs
index d1b30b6..63b8ad0 100644
--- a/tests/scan.rs
+++ b/tests/scan.rs
@@ -364,6 +364,29 @@ fn binary_bun_lockfile_is_named() {
assert_eq!(report.packages_checked, 0);
}
+#[test]
+fn binary_bun_lockfile_is_omitted_when_a_text_lockfile_sits_next_to_it() {
+ let root = std::env::temp_dir().join(format!("safe-anything-bun-both-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&root);
+ std::fs::create_dir_all(root.join("a")).unwrap();
+ std::fs::create_dir_all(root.join("b")).unwrap();
+ for name in ["bun.lock", "a/bun.lock"] {
+ std::fs::write(
+ root.join(name),
+ r#"{"lockfileVersion":1,"workspaces":{},"packages":{}}"#,
+ )
+ .unwrap();
+ }
+ for name in ["bun.lockb", "a/bun.lockb", "b/bun.lockb"] {
+ std::fs::write(root.join(name), b"\0bun-lockfile").unwrap();
+ }
+ let report = safe_anything::scan(&root, &safe_anything::Options::offline()).unwrap();
+ let _ = std::fs::remove_dir_all(&root);
+ // Only the lone binary lockfile is named; the one beside bun.lock is not.
+ assert_eq!(report.lockfiles_binary, ["b/bun.lockb"]);
+ assert_eq!(report.packages_checked, 0);
+}
+
#[test]
fn lockfile_over_the_limit_is_named() {
let root = std::env::temp_dir().join(format!("safe-anything-huge-lock-{}", std::process::id()));