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
fix(secrets): scope the hardcoded-password placeholder check to its own value (#186)
Ahmad Ghozali2208209e59ed
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 056b666..1e48e45 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,11 @@## Unreleased+- Secrets: `secret.hardcoded-password` no longer lets a placeholder-like value elsewhere on the+ line hide a real password. The placeholder check now only looks at the value right after the+ matched name, so `connect(user="testuser", password="...")` and+ `{"env": "none", "password": "..."}` are reported, while a placeholder in the password's own+ value stays quiet.- Secrets: `secret.env-file` and `secret.env-example-value` now also match variable names where`PASS` or `PWD` is a whole `_`-separated word (`DB_PASS`, `SMTP_PASS`, `PASS_FILE`, `MYSQL_PWD`),while keeping names like `PASSPORT_ID`, `BYPASS_CACHE` and `COMPASS_URL` quiet.diff --git a/src/rules/secrets.rs b/src/rules/secrets.rsindex 68d15d5..078e701 100644--- a/src/rules/secrets.rs+++ b/src/rules/secrets.rs@@ -472,7 +472,7 @@ pub static RULES: &[Rule] = &[files: any_text,pattern: r#"(?i)\b(password|passwd|pwd|secret|api_?key|access_?token|auth_?token|client_?secret)\b["']?\s*[:=]\s*["']([^"'\s]{8,})["']"#,unless: Some(- r#"(?i)[:=]\s*["'][^"']*(?:\.\.\.|…)|[:=]\s*["'](\$|changeme|password|secret|example|x{3,}|your[-_]|<|\$\{|\{\{|%\(|dummy|test|placeholder|redacted|\*{3,}|none|null)"#,+ r#"(?i)\b(password|passwd|pwd|secret|api_?key|access_?token|auth_?token|client_?secret)\b["']?\s*[:=]\s*["'](?:[^"']*(?:\.\.\.|…)|(\$|changeme|password|secret|example|x{3,}|your[-_]|<|\$\{|\{\{|%\(|dummy|test|placeholder|redacted|\*{3,}|none|null))"#,),message: "A password or secret is written in the code.",fix: ROTATE,@@ -742,6 +742,32 @@ mod tests {}}+ #[test]+ fn hardcoded_password_placeholder_only_counts_in_its_own_value() {+ let v = ["Zq7Wd0000", "Kx9Fake"].concat();+ let src = format!(+ "connect(user=\"testuser\", password=\"{v}\")\nconnect(user=\"admin\", password=\"{v}\")\ncfg = {{\"env\": \"none\", \"password\": \"{v}\"}}\n"+ );+ let found: Vec<_> = check(&FileInfo::new("app.py"), &src, false)+ .into_iter()+ .filter(|f| f.rule == "secret.hardcoded-password")+ .collect();+ assert_eq!(found.len(), 3, "{src:?} => {found:#?}");+ assert_eq!(+ found.iter().map(|f| f.line).collect::<Vec<_>>(),+ vec![1, 2, 3]+ );+ for src in [+ "password=\"changeme12345\"\n".to_string(),+ "password=\"test1234\"\n".to_string(),+ "password=\"your-password-here\"\n".to_string(),+ "password=\"<enter-password>\"\n".to_string(),+ ] {+ let found = check(&FileInfo::new("app.py"), &src, false);+ assert!(found.is_empty(), "{src:?} => {found:#?}");+ }+ }+#[test]fn age_key_after_json_escape() {let bech32 = &"QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L".repeat(2)[..58];