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.

Detect Mailgun API keys (secret.mailgun-key) (#66)

Prashant8acbd7d202d8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c52569..c0a6549 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
- Secrets: new rule `secret.gitlab-token` (critical) for GitLab personal access tokens (`glpat-` followed by 20 characters).
- Secrets: new rule `secret.huggingface-token` (critical) for Hugging Face access tokens (`hf_` followed by 34 letters).
- Secrets: new rule `secret.npm-token` (critical) for npm access tokens (`npm_` followed by 36 letters or digits).
+- Secrets: new rule `secret.mailgun-key` (critical) for Mailgun private API keys (`key-` followed by 32 lowercase hex characters).
- Dependencies: `uv.lock` entries whose `source` is `editable`, `virtual` or `path` (the project itself or a
local package) are no longer counted or looked up on PyPI.
- Secrets: `secret.url-credentials` skips a connection string whose password is an angle-bracket placeholder
diff --git a/README.md b/README.md
index a49b263..e14c847 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 75 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 76 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">
@@ -86,7 +86,7 @@ safe-anything --list-rules
## What it finds
-75 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
+76 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).
| | |
@@ -175,7 +175,7 @@ formats. Nothing is executed. The only network call is the dependency check, whi
names 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 75 problems were found, not that the code is safe. [Design notes](docs/adr).
+these 76 problems were found, not that the code is safe. [Design notes](docs/adr).
## Credits
diff --git a/docs/rules.md b/docs/rules.md
index 50c8919..f378089 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -31,7 +31,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 (17)
+## Secrets (18)
| Rule | Severity | CWE | OWASP | What it means |
| --- | --- | --- | --- | --- |
@@ -45,6 +45,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js
| [`secret.anthropic-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 Anthropic API key is written in the file. |
| [`secret.openai-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 OpenAI API key is written in the file. |
| [`secret.google-api-key`](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 Google API key is written in the file. |
+| [`secret.mailgun-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 | A Mailgun API 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.rs
index 9c2542f..e76b2a3 100644
--- a/src/rules/secrets.rs
+++ b/src/rules/secrets.rs
@@ -147,6 +147,12 @@ pub static RULES: &[Rule] = &[
r"\bAIza[0-9A-Za-z_\-]{35}",
"A Google API key is written in the file."
),
+ secret!(
+ "secret.mailgun-key",
+ Critical,
+ r"\bkey-[0-9a-f]{32}\b",
+ "A Mailgun API key is written in the file."
+ ),
secret!(
"secret.private-key",
Critical,
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index d2834f2..122fada 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -8,6 +8,7 @@ fn body(n: usize, alphabet: &str) -> String {
const MIXED: &str = "Q7mZ2xK9pL4vR8tN3wB6yH1cF5jD0sG";
const UPPER: &str = "Q7MZ2XK9PL4VR8TN3WB6YH1CF5JD0SG";
const LETTERS: &str = "QmZxKpLvRtNwByHcFjDsG";
+const HEX: &str = "a3f91c07d5e284b6";
pub fn fake(name: &str) -> String {
match name {
@@ -30,6 +31,7 @@ pub fn fake(name: &str) -> String {
"anthropic" => ["sk-", "ant-api03-", &body(40, MIXED)].concat(),
"openai" => ["sk-", "proj-", &body(48, MIXED)].concat(),
"google" => ["AI", "za", &body(35, MIXED)].concat(),
+ "mailgun" => ["ke", "y-", &body(32, HEX)].concat(),
"password" => ["hunter2", "hunter2"].concat(),
"db-password" => ["S3cret", "Passw0rd"].concat(),
"random" => body(40, MIXED),
diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTED
index ea43129..3bc4655 100644
--- a/tests/fixtures/secrets/EXPECTED
+++ b/tests/fixtures/secrets/EXPECTED
@@ -18,3 +18,4 @@ app/client.ts:2 secret.public-env-secret
config.py:17 secret.npm-token
config.py:18 secret.gitlab-token
config.py:19 secret.huggingface-token
+config.py:21 secret.mailgun-key
\ No newline at end of file
diff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.py
index 3f0845f..71fcfd4 100644
--- a/tests/fixtures/secrets/config.py
+++ b/tests/fixtures/secrets/config.py
@@ -18,3 +18,5 @@ npm_token = "{{fake:npm}}"
gitlab_token = "{{fake:gitlab}}"
hf_token = "{{fake:huggingface-token}}"
hf_model = "hf-internal-testing/tiny-random-bert"
+mailgun = "{{fake:mailgun}}"
+mailgun_short = "key-short"
\ No newline at end of file