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 Hugging Face access tokens (#62)

Manuel Gasparinia3ebd0961706
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4c195e..3c52569 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- 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.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).
- 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.
diff --git a/README.md b/README.md
index a6cc0a0..a49b263 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 74 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 75 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
-74 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
+75 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 74 problems were found, not that the code is safe. [Design notes](docs/adr).
+these 75 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 5123cf0..50c8919 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 (16)
+## Secrets (17)
| Rule | Severity | CWE | OWASP | What it means |
| --- | --- | --- | --- | --- |
@@ -41,6 +41,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js
| [`secret.slack-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 Slack token is written in the file. |
| [`secret.stripe-live-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 live Stripe secret key is written in the file. |
| [`secret.npm-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 | An npm access token is written in the file. |
+| [`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.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. |
diff --git a/src/rules/secrets.rs b/src/rules/secrets.rs
index 8670351..9c2542f 100644
--- a/src/rules/secrets.rs
+++ b/src/rules/secrets.rs
@@ -123,6 +123,12 @@ pub static RULES: &[Rule] = &[
r"\bnpm_[A-Za-z0-9]{36}\b",
"An npm access token is written in the file."
),
+ secret!(
+ "secret.huggingface-token",
+ Critical,
+ r"\bhf_[A-Za-z]{34}\b",
+ "A Hugging Face access token is written in the file."
+ ),
secret!(
"secret.anthropic-key",
Critical,
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index e03f73f..d2834f2 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -7,6 +7,7 @@ fn body(n: usize, alphabet: &str) -> String {
const MIXED: &str = "Q7mZ2xK9pL4vR8tN3wB6yH1cF5jD0sG";
const UPPER: &str = "Q7MZ2XK9PL4VR8TN3WB6YH1CF5JD0SG";
+const LETTERS: &str = "QmZxKpLvRtNwByHcFjDsG";
pub fn fake(name: &str) -> String {
match name {
@@ -24,6 +25,7 @@ pub fn fake(name: &str) -> String {
.concat(),
"stripe-live" => ["sk", "_live_", &body(24, MIXED)].concat(),
"npm" => ["np", "m_", &body(36, MIXED)].concat(),
+ "huggingface-token" => ["h", "f_", &body(34, LETTERS)].concat(),
"stripe-test" => ["sk", "_test_", &body(24, MIXED)].concat(),
"anthropic" => ["sk-", "ant-api03-", &body(40, MIXED)].concat(),
"openai" => ["sk-", "proj-", &body(48, MIXED)].concat(),
diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTED
index 9ec6e17..ea43129 100644
--- a/tests/fixtures/secrets/EXPECTED
+++ b/tests/fixtures/secrets/EXPECTED
@@ -17,3 +17,4 @@ app/client.ts:1 secret.public-env-secret
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
diff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.py
index ef1bd57..3f0845f 100644
--- a/tests/fixtures/secrets/config.py
+++ b/tests/fixtures/secrets/config.py
@@ -16,3 +16,5 @@ secret = "your-secret-here"
token = ""
npm_token = "{{fake:npm}}"
gitlab_token = "{{fake:gitlab}}"
+hf_token = "{{fake:huggingface-token}}"
+hf_model = "hf-internal-testing/tiny-random-bert"