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.

feat(deps): read bun.lock in the dependency check (#197)

Pranav Aryad6e3995f50aa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 75cb4dc..8837a56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@
``sql<Row[]>`...` ``). The tag receives the values apart from the query text and binds them.
An untagged template literal and a raw tag (`String.raw`, `sql.raw`, `sql.unsafe`) are still
reported.
+- Dependencies: `bun.lock` (bun's text lockfile, bun 1.2 and later) is read. A repository with
+ only that lockfile used to report `0 packages checked against OSV.dev`. Workspace, git, file
+ and tarball entries are skipped, like in the other lockfiles.
- Secrets: `secret.hardcoded-password` no longer lets a placeholder-like value elsewhere on the
line hide a real password. The placeholder check now only looks at the value right after the
matched name, so `connect(user="testuser", password="...")` and
diff --git a/README.md b/README.md
index dc109e5..34165fa 100644
--- a/README.md
+++ b/README.md
@@ -115,7 +115,7 @@ The full list is in [docs/rules.md](docs/rules.md).
| **Agent setups** | `bypassPermissions` and `--dangerously-skip-permissions`, pre-approved `Bash`, `enableAllProjectMcpServers`, MCP servers run with unpinned `npx`/`uvx`/`docker`, MCP tokens in plain text, remote MCP over `http://`, `curl \| sh` in hooks and skills, prompt-injection text, skills that read `~/.ssh` or cloud credentials, invisible Unicode in instructions. [More](docs/agent-setups.md) |
| **Mobile** | Android `debuggable`, `allowBackup`, cleartext traffic, exported content providers, WebView file access and JS bridges, world-readable files; iOS ATS turned off; tokens in UserDefaults, SharedPreferences, AsyncStorage or localStorage |
| **Config** | Docker (unpinned base, root, secrets in `ENV`, `ADD <url>`), `curl \| sh` in scripts, Dockerfiles and workflow `run:` steps, GitHub Actions (`pull_request_target`, `write-all`, actions on `@main`, script injection from PR titles), privileged containers, `hostNetwork`, Terraform (open ingress, public buckets, S3 public access blocks turned off, public or unencrypted databases), nginx autoindex, TLS 1.0/1.1 |
-| **Dependencies** | every locked version in `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `pnpm-lock.yaml`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.lock`, `pdm.lock`, `Pipfile.lock`, `go.mod`, `Gemfile.lock`, `composer.lock` and `pubspec.lock`, checked against [OSV.dev](https://osv.dev), with the nearest fixed version |
+| **Dependencies** | every locked version in `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.lock`, `pdm.lock`, `Pipfile.lock`, `go.mod`, `Gemfile.lock`, `composer.lock` and `pubspec.lock`, checked against [OSV.dev](https://osv.dev), with the nearest fixed version |
<p align="center">
<img src="docs/assets/nextjs-public-env.gif" alt="safe-anything on the with-mqtt-js example from the Next.js repository: 2 high findings, an MQTT password read from a NEXT_PUBLIC_ variable in app/page.tsx and environment.d.ts, which Next.js ships in the client bundle." width="820">
diff --git a/src/deps.rs b/src/deps.rs
index ed2a355..e79dc9c 100644
--- a/src/deps.rs
+++ b/src/deps.rs
@@ -94,6 +94,7 @@ fn parser(name: &str) -> Option<Parser> {
"package-lock.json" | "npm-shrinkwrap.json" => npm_lock,
"yarn.lock" => yarn_lock,
"pnpm-lock.yaml" => pnpm_lock,
+ "bun.lock" => bun_lock,
"cargo.lock" => |f, t| toml_packages(f, t, "crates.io", true),
"poetry.lock" | "uv.lock" | "pdm.lock" => |f, t| toml_packages(f, t, "PyPI", false),
"go.mod" => go_mod,
@@ -156,6 +157,111 @@ fn npm_lock(file: &FileInfo, text: &str) -> Vec<Package> {
out
}
+#[derive(Deserialize)]
+struct BunLock {
+ #[serde(default, deserialize_with = "ordered")]
+ packages: Option<Ordered>,
+}
+
+/// bun's text lockfile (bun 1.2 and later). It is JSONC: bun writes a comma after the
+/// last entry of every object and array. Each `packages` value is an array whose first
+/// item is `name@version` for a registry package, or `name@workspace:...`,
+/// `name@github:...`, `name@file:...` and the like for one that is not.
+fn bun_lock(file: &FileInfo, text: &str) -> Vec<Package> {
+ let Ok(json) = serde_json::from_str::<BunLock>(&jsonc_to_json(text)) else {
+ return Vec::new();
+ };
+ let lines = Text::new(text);
+ let mut out = Vec::new();
+ let mut cursor = 0;
+ for (key, entry) in json.packages.iter().flat_map(|Ordered(p)| p) {
+ let Some(spec) = entry.get(0).and_then(Value::as_str) else {
+ continue;
+ };
+ // The name can start with `@` (a scope), so split at the last one.
+ let Some((name, version)) = spec.rsplit_once('@') else {
+ continue;
+ };
+ if name.is_empty()
+ || !version.starts_with(|c: char| c.is_ascii_digit())
+ || version.contains([':', '/'])
+ {
+ continue;
+ }
+ // The workspaces section above lists the same names as `"name": "range"`, so
+ // look for the key followed by its array.
+ let needle = format!("\"{key}\": [");
+ let at = if text[cursor..].contains(&needle) {
+ find_from(text, &mut cursor, &needle)
+ } else {
+ find_from(text, &mut cursor, &format!("\"{key}\""))
+ };
+ out.push(pkg("npm", name, version, file, lines.line_of(at)));
+ }
+ out
+}
+
+/// Turns JSONC into JSON: drops `//` and `/* */` comments and the comma before a
+/// closing `}` or `]`. Line breaks are kept.
+fn jsonc_to_json(src: &str) -> String {
+ let mut out = String::with_capacity(src.len());
+ let mut chars = src.chars().peekable();
+ let mut in_str = false;
+ // Where the last comma sits in `out`, while only whitespace has followed it.
+ let mut comma: Option<usize> = None;
+ while let Some(c) = chars.next() {
+ if in_str {
+ out.push(c);
+ if c == '\\' {
+ out.extend(chars.next());
+ } else if c == '"' {
+ in_str = false;
+ }
+ continue;
+ }
+ match c {
+ '/' if chars.peek() == Some(&'/') => {
+ for n in chars.by_ref() {
+ if n == '\n' {
+ out.push('\n');
+ break;
+ }
+ }
+ }
+ '/' if chars.peek() == Some(&'*') => {
+ chars.next();
+ let mut prev = ' ';
+ for n in chars.by_ref() {
+ if n == '\n' {
+ out.push('\n');
+ }
+ if prev == '*' && n == '/' {
+ break;
+ }
+ prev = n;
+ }
+ }
+ ',' => {
+ comma = Some(out.len());
+ out.push(c);
+ }
+ '}' | ']' => {
+ if let Some(at) = comma.take() {
+ out.replace_range(at..=at, " ");
+ }
+ out.push(c);
+ }
+ c if c.is_whitespace() => out.push(c),
+ c => {
+ comma = None;
+ in_str = c == '"';
+ out.push(c);
+ }
+ }
+ }
+ out
+}
+
fn yarn_lock(file: &FileInfo, text: &str) -> Vec<Package> {
let mut out = Vec::new();
let mut current: Option<String> = None;
@@ -691,6 +797,63 @@ mod tests {
}
}
+ fn bun(text: &str) -> Vec<(String, String, usize)> {
+ parse_lockfile(&FileInfo::new("bun.lock"), text)
+ .into_iter()
+ .map(|p| (p.name, p.version, p.line))
+ .collect()
+ }
+
+ #[test]
+ fn bun_lock_reads_registry_packages_and_skips_the_rest() {
+ let text = r#"{
+ "lockfileVersion": 1,
+ "workspaces": {
+ "": { "name": "app", "dependencies": { "lodash": "^4.17.20", }, },
+ },
+ "packages": {
+ "@types/node": ["@types/[email protected]", "", {}, "sha512-x"],
+ "lodash": ["[email protected]", "", {}, "sha512-x"],
+ "app": ["app@workspace:."],
+ "debug": ["debug@github:debug-js/debug#1a2b3c4", {}, "x"],
+ "local": ["local@file:../local", {}],
+ "tar": ["tar@https://example.com/tar-1.0.0.tgz", {}, "x"],
+ "alias": ["[email protected]", "", {}, "sha512-x"],
+ "ui/lodash": ["[email protected]", "", {}, "sha512-x"],
+ }
+}"#;
+ assert_eq!(
+ bun(text),
+ [
+ ("@types/node".to_string(), "22.10.1".to_string(), 7),
+ ("lodash".to_string(), "4.17.20".to_string(), 8),
+ ("left-pad".to_string(), "1.3.0".to_string(), 13),
+ ("lodash".to_string(), "3.10.1".to_string(), 14),
+ ]
+ );
+ }
+
+ #[test]
+ fn bun_lock_reads_comments_and_one_line_files() {
+ let text = "// written by bun\n{\"packages\": { /* one */ \"ms\": [\"[email protected]\", \"\", {}, \"x\"] }}";
+ assert_eq!(bun(text), [("ms".to_string(), "2.1.3".to_string(), 2)]);
+ // A `,}` or `//` inside a string is text, not syntax.
+ let text = r#"{"packages": {"a,}": ["[email protected]", "http://x/,]", {}, "x"],}}"#;
+ assert_eq!(bun(text), [("a".to_string(), "1.0.0".to_string(), 1)]);
+ }
+
+ #[test]
+ fn bun_lock_that_is_not_an_object_of_arrays_gives_nothing() {
+ for text in [
+ "",
+ "not json",
+ "{\"packages\": []}",
+ "{\"packages\": {\"a\": \"[email protected]\", \"b\": [], \"c\": [1], \"d\": [\"no-version\"]}}",
+ ] {
+ assert_eq!(bun(text), [], "{text}");
+ }
+ }
+
#[test]
fn npm_keys_out_of_byte_order_keep_their_lines() {
let text = "{\"packages\": {
diff --git a/tests/fixtures/deps/EXPECTED b/tests/fixtures/deps/EXPECTED
index c3ddcb2..ea70c8c 100644
--- a/tests/fixtures/deps/EXPECTED
+++ b/tests/fixtures/deps/EXPECTED
@@ -10,3 +10,4 @@ dart/pubspec.lock:24 dependency.known-vulnerability
yarn/yarn.lock:6 dependency.known-vulnerability
py/poetry.lock:5 dependency.known-vulnerability
pipenv/Pipfile.lock:22 dependency.known-vulnerability
+bun/bun.lock:20 dependency.known-vulnerability
diff --git a/tests/fixtures/deps/bun/bun.lock b/tests/fixtures/deps/bun/bun.lock
new file mode 100644
index 0000000..af450b7
--- /dev/null
+++ b/tests/fixtures/deps/bun/bun.lock
@@ -0,0 +1,28 @@
+{
+ "lockfileVersion": 1,
+ "workspaces": {
+ "": {
+ "name": "my-app",
+ "dependencies": {
+ "lodash": "^4.17.20",
+ "ms": "^2.1.3",
+ },
+ },
+ "packages/ui": {
+ "name": "ui",
+ },
+ },
+ "packages": {
+ "@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-x"],
+
+ "debug": ["debug@github:debug-js/debug#1a2b3c4", {}, "debug-js-debug-1a2b3c4"],
+
+ "lodash": ["[email protected]", "", {}, "sha512-x"],
+
+ "ms": ["[email protected]", "", {}, "sha512-x"],
+
+ "ui": ["ui@workspace:packages/ui"],
+
+ "ui/ms": ["[email protected]", "", {}, "sha512-x"],
+ }
+}
diff --git a/tests/scan.rs b/tests/scan.rs
index 7c972ee..ba11229 100644
--- a/tests/scan.rs
+++ b/tests/scan.rs
@@ -275,8 +275,9 @@ fn deps() {
// as a dependency): the `my-app@workspace:.` entry in web/yarn.lock, and the
// gems in the `GIT` and `PATH` sections of rb/Gemfile.lock, and the editable
// git checkout of `requests` in pipenv/Pipfile.lock. Only the gems in its two
- // `GEM` sections count.
- check_with("deps", options, Some(27));
+ // `GEM` sections count. In bun/bun.lock the `ui@workspace:` and `debug@github:`
+ // entries are skipped the same way.
+ check_with("deps", options, Some(31));
}
/// Writes a package-lock.json listing `n` packages, padded with a long