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 pubspec.lock for dart and flutter projects (#31)

Tejeshfcd5d6af446f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d7f0b6..237877c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Dependencies: `pubspec.lock` is read, so Dart and Flutter packages are checked against OSV.dev
+ (`Pub` ecosystem). Packages from the `sdk` source, like `flutter`, are skipped.
- Secrets: new rule `secret.gitlab-token` (critical) for GitLab personal access tokens (`glpat-` followed by 20 characters).
- Secrets: new rule `secret.npm-token` (critical) for npm access tokens (`npm_` followed by 36 letters or digits).
- Dependencies: `uv.lock` entries whose `source` is `editable`, `virtual` or `path` (the project itself or a
diff --git a/README.md b/README.md
index 0fecb0b..f5ab8d3 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,7 @@ The full list is in [docs/rules.md](docs/rules.md).
| **Agent setups** | `bypassPermissions` and `--dangerously-skip-permissions`, pre-approved `Bash`, 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`, 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>`), GitHub Actions (`pull_request_target`, `write-all`, actions on `@main`, script injection from PR titles), privileged containers, `hostNetwork`, open Terraform ingress, public buckets, nginx autoindex, TLS 1.0/1.1 |
-| **Dependencies** | every locked version in `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.lock`, `go.mod`, `Gemfile.lock` and `composer.lock`, checked against [OSV.dev](https://osv.dev), with the nearest fixed version |
+| **Dependencies** | every locked version in `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `Cargo.lock`, `requirements*.txt`, `poetry.lock`, `uv.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">
@@ -162,7 +162,7 @@ same. Status per family: [docs/STATUS.md](docs/STATUS.md).
One parallel walk over the repository (the `ignore` crate, the walker behind ripgrep), one read per
file, and every rule that applies run as a compiled regex. Where a pattern can't tell right from
-wrong, the file is parsed: MCP configs as JSON with comments, Dockerfile stages, nine lockfile
+wrong, the file is parsed: MCP configs as JSON with comments, Dockerfile stages, ten lockfile
formats. Nothing is executed. The only network call is the dependency check, which sends package
names and versions to OSV.dev ([privacy](docs/privacy.md)).
diff --git a/src/deps.rs b/src/deps.rs
index 4475cf1..def277a 100644
--- a/src/deps.rs
+++ b/src/deps.rs
@@ -48,6 +48,7 @@ pub fn parse_lockfile(file: &FileInfo, text: &str) -> Vec<Package> {
"go.mod" => go_mod(file, text),
"gemfile.lock" => gemfile_lock(file, text),
"composer.lock" => composer_lock(file, text),
+ "pubspec.lock" => pubspec_lock(file, text),
n if n.starts_with("requirements") && n.ends_with(".txt") => requirements(file, text),
_ => Vec::new(),
}
@@ -272,6 +273,35 @@ fn composer_lock(file: &FileInfo, text: &str) -> Vec<Package> {
out
}
+fn pubspec_lock(file: &FileInfo, text: &str) -> Vec<Package> {
+ let mut out = Vec::new();
+ let mut sdk = HashSet::new();
+ let mut in_packages = false;
+ let mut name = "";
+ for (i, line) in text.lines().enumerate() {
+ if line.trim().is_empty() {
+ continue;
+ }
+ if !line.starts_with(' ') {
+ in_packages = line.trim_end() == "packages:";
+ continue;
+ }
+ if !in_packages || line.starts_with(" ") {
+ continue;
+ }
+ let l = line.trim();
+ if !line.starts_with(" ") {
+ name = l.trim_end_matches(':').trim_matches('"');
+ } else if let Some(v) = l.strip_prefix("version: ") {
+ out.push(pkg("Pub", name, v.trim_matches('"'), file, i + 1));
+ } else if l == "source: sdk" {
+ sdk.insert(name);
+ }
+ }
+ out.retain(|p| !sdk.contains(p.name.as_str()));
+ out
+}
+
fn requirements(file: &FileInfo, text: &str) -> Vec<Package> {
let mut out = Vec::new();
for (i, line) in text.lines().enumerate() {
diff --git a/tests/fixtures/deps/EXPECTED b/tests/fixtures/deps/EXPECTED
index 703d2ed..59b36f0 100644
--- a/tests/fixtures/deps/EXPECTED
+++ b/tests/fixtures/deps/EXPECTED
@@ -6,3 +6,4 @@ rs/Cargo.lock:5 dependency.known-vulnerability
php/composer.lock:5 dependency.known-vulnerability
pnpm/pnpm-lock.yaml:29 dependency.known-vulnerability
uv/uv.lock:6 dependency.known-vulnerability
+dart/pubspec.lock:24 dependency.known-vulnerability
diff --git a/tests/fixtures/deps/dart/pubspec.lock b/tests/fixtures/deps/dart/pubspec.lock
new file mode 100644
index 0000000..0fd5df9
--- /dev/null
+++ b/tests/fixtures/deps/dart/pubspec.lock
@@ -0,0 +1,27 @@
+# Generated by pub
+# See https://dart.dev/tools/pub/glossary#lockfile
+packages:
+ collection:
+ dependency: transitive
+ description:
+ name: collection
+ sha256: "ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.18.0"
+ flutter:
+ dependency: "direct main"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ http:
+ dependency: "direct main"
+ description:
+ name: http
+ sha256: "0c51a50c5ac87b08e5e98a12efbd24bb8367268021de0a13b99319275c15eb4a"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.13.2"
+sdks:
+ dart: ">=3.0.0 <4.0.0"
+ flutter: ">=3.10.0"
diff --git a/tests/scan.rs b/tests/scan.rs
index b82be8d..a3d981e 100644
--- a/tests/scan.rs
+++ b/tests/scan.rs
@@ -93,12 +93,13 @@ fn deps() {
("RubyGems", "rack", "2.0.0"),
("crates.io", "smallvec", "1.0.0"),
("Packagist", "guzzlehttp/guzzle", "6.5.0"),
+ ("Pub", "http", "0.13.2"),
]);
let options = safe_anything::Options {
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));
+ // skipped (not counted as a dependency). The expected package count stays 20.
+ check_with("deps", options, Some(20));
}