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(secrets): detect Groq API keys (secret.groq-key) (#96)

lyn1744d9507c67d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de77bad..3bfe074 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@
- 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).
- Secrets: new rule `secret.telegram-bot-token` (high) for Telegram bot tokens (8 to 10 digits, a colon, then 35 letters, digits, `_` or `-`).
+- Secrets: new rule `secret.groq-key` (critical) for Groq API keys (`gsk_` followed by 52 letters or digits).
- Code: new rule `code.open-redirect` (medium) for redirects built straight from request input (`res.redirect(req.query.next)`, `redirect(request.args.get("next"))`); a redirect to a fixed path stays unflagged.
- Code: `code.sql-injection` also catches Go queries built by concatenation in `db.Query`, `db.QueryRow`, `db.Exec`
and their `Context` variants (`db.Query("SELECT * FROM t WHERE id=" + id)`). A query with a placeholder stays unflagged.
diff --git a/README.md b/README.md
index c5cf016..6cac718 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 79 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 80 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
-79 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
+80 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 @@ lockfile listed under Dependencies. Nothing is executed. The only network call i
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 79 problems were found, not that the code is safe. [Design notes](docs/adr).
+these 80 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 c75ccf2..6ad4da7 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 (19)
+## Secrets (20)
| Rule | Severity | CWE | OWASP | What it means |
| --- | --- | --- | --- | --- |
@@ -45,13 +45,14 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js
| [`secret.huggingface-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 Hugging Face access token is written in the file. |
| [`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.groq-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 Groq 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.telegram-bot-token`](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 Telegram bot token 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. |
-| [`secret.env-file`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | medium | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A .env file with values is in the repository; these usually hold real secrets. |
+| [`secret.env-file`](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 .env file in the repository holds a secret value. |
| [`secret.env-example-value`](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 | An example env file holds what looks like a real secret value; example files are meant to be committed and shared. |
| [`secret.public-env-secret`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | high | [CWE-200](https://cwe.mitre.org/data/definitions/200.html) | A05:2021 Security Misconfiguration | A secret is given a public env prefix, so the build ships it inside the client bundle where anyone can read it. |
| [`secret.env-not-ignored`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | medium | [CWE-538](https://cwe.mitre.org/data/definitions/538.html) | A05:2021 Security Misconfiguration | The project has env files but .gitignore does not exclude .env, so real secrets are one git add away from the repository. |
diff --git a/src/rules/secrets.rs b/src/rules/secrets.rs
index 0d593bd..f9b205e 100644
--- a/src/rules/secrets.rs
+++ b/src/rules/secrets.rs
@@ -167,6 +167,12 @@ pub static RULES: &[Rule] = &[
r"\bsk-(?:proj|svcacct|admin)-[A-Za-z0-9_\-]{32,}|\bsk-[A-Za-z0-9]{48}\b",
"An OpenAI API key is written in the file."
),
+ secret!(
+ "secret.groq-key",
+ Critical,
+ r"\bgsk_[A-Za-z0-9]{52}\b",
+ "A Groq API key is written in the file."
+ ),
secret!(
"secret.google-api-key",
High,
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index cbfe7f6..c50e96e 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -34,6 +34,7 @@ pub fn fake(name: &str) -> String {
"openai" => ["sk-", "proj-", &body(48, MIXED)].concat(),
"google" => ["AI", "za", &body(35, MIXED)].concat(),
"mailgun" => ["ke", "y-", &body(32, HEX)].concat(),
+ "groq" => ["gs", "k_", &body(52, MIXED)].concat(),
"telegram" => ["1234", "567890", ":", &body(35, MIXED)].concat(),
"telegram-hyphen" => ["1234", "567890", ":", &body(34, MIXED), "-"].concat(),
"password" => ["hunter2", "hunter2"].concat(),
diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTED
index 4edb705..cc22737 100644
--- a/tests/fixtures/secrets/EXPECTED
+++ b/tests/fixtures/secrets/EXPECTED
@@ -23,4 +23,5 @@ config.py:18 secret.gitlab-token
config.py:19 secret.huggingface-token
config.py:21 secret.mailgun-key
config.py:23 secret.telegram-bot-token
-config.py:26 secret.telegram-bot-token
\ No newline at end of file
+config.py:26 secret.telegram-bot-token
+config.py:27 secret.groq-key
\ No newline at end of file
diff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.py
index 1f0bb9b..c161f27 100644
--- a/tests/fixtures/secrets/config.py
+++ b/tests/fixtures/secrets/config.py
@@ -23,4 +23,6 @@ mailgun_short = "key-short"
telegram = "{{fake:telegram}}"
clock = "12:30:45"
upstream = "localhost:8080"
-telegram_hyphen = "{{fake:telegram-hyphen}}"
\ No newline at end of file
+telegram_hyphen = "{{fake:telegram-hyphen}}"
+groq = "{{fake:groq}}"
+groq_short = "gsk_short"
\ No newline at end of file