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 npm access tokens (#15)
Mingc0617f5cd029
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 599f445..76d7982 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,7 @@## Unreleased+- 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 alocal package) are no longer counted or looked up on PyPI.- Secrets: `secret.url-credentials` skips a connection string whose password is an angle-bracket placeholderdiff --git a/docs/rules.md b/docs/rules.mdindex 8e7fe23..9085bd9 100644--- a/docs/rules.md+++ b/docs/rules.md@@ -39,6 +39,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`secret.github-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 GitHub token is written in the file. || [`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.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.rsindex 8464ecb..6301fb8 100644--- a/src/rules/secrets.rs+++ b/src/rules/secrets.rs@@ -111,6 +111,12 @@ pub static RULES: &[Rule] = &[r"\b[sr]k_live_[A-Za-z0-9]{24,}","A live Stripe secret key is written in the file."),+ secret!(+ "secret.npm-token",+ Critical,+ r"\bnpm_[A-Za-z0-9]{36}\b",+ "An npm access token is written in the file."+ ),secret!("secret.anthropic-key",Critical,diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 5cb7192..483db7f 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -22,6 +22,7 @@ pub fn fake(name: &str) -> String {].concat(),"stripe-live" => ["sk", "_live_", &body(24, MIXED)].concat(),+ "npm" => ["np", "m_", &body(36, MIXED)].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/EXPECTEDindex a5a8735..ea61956 100644--- a/tests/fixtures/secrets/EXPECTED+++ b/tests/fixtures/secrets/EXPECTED@@ -15,3 +15,4 @@ keys/deploy.pem:1 secret.private-key.gitignore:1 secret.env-not-ignoredapp/client.ts:1 secret.public-env-secretapp/client.ts:2 secret.public-env-secret+config.py:17 secret.npm-tokendiff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.pyindex a7abab9..30e70ca 100644--- a/tests/fixtures/secrets/config.py+++ b/tests/fixtures/secrets/config.py@@ -14,3 +14,4 @@ password = "changeme"api_key = "${API_KEY}"secret = "your-secret-here"token = ""+npm_token = "{{fake:npm}}"