Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.
Rust ai-agentsclaude-codeclaude-code-pluginclicodexcursordevsecopsmcposvowasprustsastsecret-scanningsecretssecuritysecurity-scannersql-injectionvulnerabilityvulnerability-scannerxss
feat(secrets): detect age private keys (#158)
bardrop39e28dcd68bd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4d6a9d2..eb072d3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,8 @@## Unreleased+- Secrets: new rule `secret.age-key` (critical) for age private keys (`AGE-SECRET-KEY-1` followed by+ 58 upper-case Bech32 characters), which decrypt every file encrypted to them, SOPS files included.- Secrets: when a line holds more than one secret or more than one finding, all secrets on thatline are now masked in every finding on it (two tokens of one kind, tokens of different kinds, atoken beside a `NEXT_PUBLIC_` or `VITE_` secret, another rule's finding on the same line such asdiff --git a/README.md b/README.mdindex c944101..2634e97 100644--- a/README.md+++ b/README.md@@ -20,7 +20,7 @@ Every finding comes with the line, the reason and the fix.</p><a href="https://github.com/erkamyaman/safe-anything"><img src="https://img.shields.io/github/stars/erkamyaman/safe-anything?style=social" alt="GitHub stars"></a></p>-<p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 101 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>+<p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 102 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>Made in Türkiye 🇹🇷 by <a href="https://github.com/erkamyaman">erKam Yaman</a>, who also made <a href="https://github.com/erkamyaman/rust-anything">rust-anything</a> · <a href="https://github.com/sponsors/erkamyaman">❤️ Sponsor me</a> · Sponsored by <a href="https://coderabbit.link/er-kam">CodeRabbit</a></p><p align="center">@@ -105,13 +105,13 @@ it hides that finding.## What it finds-101 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.+102 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.The full list is in [docs/rules.md](docs/rules.md).| | || --- | --- || **Code** | SQL injection, command injection, XSS (`innerHTML`, `dangerouslySetInnerHTML`, `v-html`, `echo $_GET`, `raw`), `eval` and `new Function`, path traversal, file inclusion from request input, SSRF, open redirects, unsafe deserialization (pickle, `yaml.load`, `ObjectInputStream`, `BinaryFormatter`, `unserialize`, `Marshal`), TLS checks turned off, MD5/SHA-1, DES/RC4/ECB, JWT `none`, template injection, CORS `*`, debug mode, insecure cookies, `Math.random` tokens, `GRANT ALL` and plain-text passwords in SQL files. JS/TS, Python, Go, Java, Kotlin, PHP, Ruby, C#, SQL |-| **Secrets** | AWS (key ids and secret access keys), GitHub, GitLab, Slack, Stripe, Shopify, npm, PyPI, RubyGems, OpenAI, Anthropic, Groq, Google, Hugging Face, Mailgun, SendGrid, Telegram, DigitalOcean, Databricks, Twilio, Linear, Postman, Pulumi, Sentry, Supabase, Grafana and Doppler keys, Google OAuth client secrets, Slack and Discord webhook URLs, private keys (also inside service-account JSON), passwords in code, credentials in connection strings, committed `.env` files, real values in `.env.example`, a `.gitignore` that misses `.env`, secrets behind public prefixes (`NEXT_PUBLIC_`, `VITE_`, `EXPO_PUBLIC_`) that ship in the client bundle |+| **Secrets** | AWS (key ids and secret access keys), GitHub, GitLab, Slack, Stripe, Shopify, npm, PyPI, RubyGems, OpenAI, Anthropic, Groq, Google, Hugging Face, Mailgun, SendGrid, Telegram, DigitalOcean, Databricks, Twilio, Linear, Postman, Pulumi, Sentry, Supabase, Grafana and Doppler keys, Google OAuth client secrets, Slack and Discord webhook URLs, private keys (also inside service-account JSON) and age keys, passwords in code, credentials in connection strings, committed `.env` files, real values in `.env.example`, a `.gitignore` that misses `.env`, secrets behind public prefixes (`NEXT_PUBLIC_`, `VITE_`, `EXPO_PUBLIC_`) that ship in the client bundle || **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 |@@ -195,7 +195,7 @@ lockfile listed under Dependencies. Nothing is executed. The only network call inames and versions to OSV.dev ([privacy](docs/privacy.md)).It finds known patterns; it does not trace data through your program. A clean scan means none of-these 101 problems were found, not that the code is safe. [Design notes](docs/adr).+these 102 problems were found, not that the code is safe. [Design notes](docs/adr).## Creditsdiff --git a/docs/assets/social.html b/docs/assets/social.htmlindex b64373c..4af9ce3 100644--- a/docs/assets/social.html+++ b/docs/assets/social.html@@ -31,7 +31,7 @@<p class="sub">Code, secrets, mobile, cloud config, dependencies, and the AI agent setup that writes it all. One command.</p><div class="stats"><div class="stat"><b><0.1 s</b><small>for 1,195 files (Juice Shop, M4)</small></div>- <div class="stat"><b>101 rules</b><small>with CWE and OWASP ids</small></div>+ <div class="stat"><b>102 rules</b><small>with CWE and OWASP ids</small></div><div class="stat"><b>100% Rust</b><small>one binary, no runtime</small></div></div></div>diff --git a/docs/rules.md b/docs/rules.mdindex 5ce9cd6..2e4fa95 100644--- a/docs/rules.md+++ b/docs/rules.md@@ -32,7 +32,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`code.sql-grant-all`](https://cheatsheetseries.owasp.org/cheatsheets/Database_Security_Cheat_Sheet.html) | medium | [CWE-250](https://cwe.mitre.org/data/definitions/250.html) | A01:2021 Broken Access Control | A database user gets every privilege on every database. || [`code.sql-plaintext-password`](https://cheatsheetseries.owasp.org/cheatsheets/Database_Security_Cheat_Sheet.html) | medium | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A database password is written in a SQL file. |-## Secrets (38)+## Secrets (39)| Rule | Severity | CWE | OWASP | What it means || --- | --- | --- | --- | --- |@@ -67,6 +67,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`secret.supabase-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A Supabase access token is written in the file. || [`secret.grafana-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A Grafana service account token is written in the file. || [`secret.doppler-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A Doppler personal token is written in the file. |+| [`secret.age-key`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | An age private key is written in the file. || [`secret.private-key`](https://cheatsheetseries.owasp.org/cheatsheets/Key_Management_Cheat_Sheet.html) | critical | [CWE-321](https://cwe.mitre.org/data/definitions/321.html) | A02:2021 Cryptographic Failures | A private key is stored in the repository. || [`secret.hardcoded-password`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | high | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A password or secret is written in the code. || [`secret.url-credentials`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | high | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A connection string carries a username and password. |diff --git a/src/rules/secrets.rs b/src/rules/secrets.rsindex 5e8369a..f688409 100644--- a/src/rules/secrets.rs+++ b/src/rules/secrets.rs@@ -418,6 +418,14 @@ pub static RULES: &[Rule] = &[r"\bdp\.pt\.[A-Za-z0-9]{43}\b","A Doppler personal token is written in the file."),+ secret!(+ "secret.age-key",+ Critical,+ // In a JSON string the key can follow an escape like `\n`, where `\b` fails+ // between `n` and `A`.+ r"(?:\\[nrt]|\b)(AGE-SECRET-KEY-1[QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L]{58})\b",+ "An age private key is written in the file."+ ),secret!("secret.private-key",Critical,@@ -703,4 +711,37 @@ mod tests {assert!(!plausible_aws_secret(&value), "{shape}: {value}");}}++ #[test]+ fn age_key_after_json_escape() {+ let key = [+ "AGE-SECRET-",+ "KEY-1",+ &"QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L".repeat(2)[..58],+ ]+ .concat();+ let age = |src: &str| -> Vec<_> {+ check(&FileInfo::new("keys.json"), src, false)+ .into_iter()+ .filter(|f| f.rule == "secret.age-key")+ .collect()+ };+ for src in [+ format!(r#"{{"key":"line\n{key}"}}"#),+ format!(r#"{{"key":"line\r\n{key}\n"}}"#),+ format!(r#"{{"key":"\t{key}"}}"#),+ format!("key = \"{key}\""),+ ] {+ let found = age(&src);+ assert_eq!(found.len(), 1, "{src} => {found:#?}");+ assert!(!found[0].snippet.contains(&key), "{src} => {found:#?}");+ }+ for src in [+ format!("X{key}"),+ format!("{key}Q"),+ format!(r#""line\n{key}Q""#),+ ] {+ assert!(age(&src).is_empty(), "{src}");+ }+ }}diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex cffbfff..c370f0f 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -9,6 +9,8 @@ const MIXED: &str = "Q7mZ2xK9pL4vR8tN3wB6yH1cF5jD0sG";const UPPER: &str = "Q7MZ2XK9PL4VR8TN3WB6YH1CF5JD0SG";const LETTERS: &str = "QmZxKpLvRtNwByHcFjDsG";const HEX: &str = "a3f91c07d5e284b6";+// The Bech32 alphabet in upper case, as age writes its keys.+const BECH32: &str = "QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L";// Unlike the others, so a leak of this body is not mistaken for another token.const KEY_BODY: &str = "Zr8Wq2Xn5Mb7Vc4Lk1Jh6Gf9Dd3Ss0AaUe";@@ -137,6 +139,9 @@ pub fn fake(name: &str) -> String {"databricks" => ["da", "pi", &body(32, HEX)].concat(),"databricks-suffix" => ["da", "pi", &body(32, HEX), "-2"].concat(),"databricks-upper" => ["da", "pi", &body(32, HEX).to_uppercase()].concat(),+ "age" => ["AGE-SECRET-", "KEY-1", &body(58, BECH32)].concat(),+ // `B` is not in the Bech32 alphabet.+ "age-not-bech32" => ["AGE-SECRET-", "KEY-1", &body(57, BECH32), "B"].concat(),other => panic!("no fake value named {other}"),}}diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTEDindex 04aa961..c92bdc4 100644--- a/tests/fixtures/secrets/EXPECTED+++ b/tests/fixtures/secrets/EXPECTED@@ -66,3 +66,4 @@ config.py:82 secret.gitlab-tokenconfig.py:84 secret.gitlab-tokenconfig.py:86 secret.databricks-tokenconfig.py:87 secret.databricks-token+config.py:92 secret.age-keydiff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.pyindex 08eddbf..17109cc 100644--- a/tests/fixtures/secrets/config.py+++ b/tests/fixtures/secrets/config.py@@ -89,3 +89,5 @@ databricks_short = "dapi0123abcd"databricks_upper = "{{fake:databricks-upper}}"databricks_long = "{{fake:databricks}}a"databricks_prefixed = "my{{fake:databricks}}"+age_key = "{{fake:age}}"+age_key_lookalike = "AGE-SECRET-KEY-1QPZRY9X8 {{fake:age-not-bech32}} {{fake:age}}Q"