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): match base64 padding and symbols in .env secret values (#65)
Ahmad Ghozaliee5576e6d3aa
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c0a6549..623af88 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,9 @@## Unreleased+- Secrets: `secret.env-file` and `secret.env-example-value` now catch base64 values ending in `=` padding and+ passwords with `!@#$%^&*`. A value that is only `*` characters or starts with `$` (a reference like+ `$POSTGRES_PASSWORD`) is skipped.- Agent: an MCP config whose `npx` (or `pnpm dlx`) argument is empty or starts with a non-ASCIIcharacter no longer crashes the scan.- Dependencies: `pubspec.lock` is read, so Dart and Flutter packages are checked against OSV.devdiff --git a/src/rules/secrets.rs b/src/rules/secrets.rsindex e76b2a3..c64527d 100644--- a/src/rules/secrets.rs+++ b/src/rules/secrets.rs@@ -65,9 +65,9 @@ fn env_example(f: &FileInfo) -> bool {.any(|s| f.name.ends_with(s))}-const ENV_SECRET_LINE: &str = r#"(?m)^\s*(?:export\s+)?[A-Za-z0-9_]*(?i:secret|token|password|passwd|api_?key|private_?key|access_?key|auth|credential)[A-Za-z0-9_]*\s*=\s*["']?([A-Za-z0-9+/_.\-]{16,})["']?\s*$"#;+const ENV_SECRET_LINE: &str = r#"(?m)^\s*(?:export\s+)?[A-Za-z0-9_]*(?i:secret|token|password|passwd|api_?key|private_?key|access_?key|auth|credential)[A-Za-z0-9_]*\s*=\s*["']?([A-Za-z0-9+/_.=!@#$%^&*\-]{16,})["']?\s*$"#;-const ENV_PLACEHOLDER: &str = r"^\s*(?:export\s+)?(?:NEXT_PUBLIC|VITE|REACT_APP|EXPO_PUBLIC|NUXT_PUBLIC|GATSBY|VUE_APP|PUBLIC)_|(?i)=\s*[\x22']?(?:\S*(?:your|example|change|replace|placeholder|dummy|xxxx|\.\.\.|<)|sk_test_|pk_test_|(?-i:[a-z]+[-_][a-z]+[-_][a-z]+))";+const ENV_PLACEHOLDER: &str = r"^\s*(?:export\s+)?(?:NEXT_PUBLIC|VITE|REACT_APP|EXPO_PUBLIC|NUXT_PUBLIC|GATSBY|VUE_APP|PUBLIC)_|(?i)=\s*[\x22']?(?:\S*(?:your|example|change|replace|placeholder|dummy|xxxx|\.\.\.|<)|sk_test_|pk_test_|(?-i:[a-z]+[-_][a-z]+[-_][a-z]+))|=\s*[\x22']?\*+[\x22']?\s*$|=\s*[\x22']?\$";const ROTATE: &str = "Revoke this credential at the provider, then load it from the environment or a secrets manager and keep it out of the repository.";diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 122fada..486dbe2 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -34,6 +34,16 @@ pub fn fake(name: &str) -> String {"mailgun" => ["ke", "y-", &body(32, HEX)].concat(),"password" => ["hunter2", "hunter2"].concat(),"db-password" => ["S3cret", "Passw0rd"].concat(),+ "base64-padded" => [&body(30, MIXED), "=="].concat(),+ "symbol-secret" => [+ &body(8, MIXED),+ "!",+ &body(4, LETTERS),+ "#",+ &body(4, HEX),+ "%",+ ]+ .concat(),"random" => body(40, MIXED),"private-key" => ["-----BEGIN RSA ",diff --git a/tests/fixtures/secrets/.env b/tests/fixtures/secrets/.envindex ce06538..47d4187 100644--- a/tests/fixtures/secrets/.env+++ b/tests/fixtures/secrets/.env@@ -3,3 +3,6 @@ SESSION_SECRET={{fake:random}}NEXT_PUBLIC_API_URL=https://api.acme.ioAPI_TOKEN=your-token-hereNEXT_PUBLIC_SEARCH_API_KEY=a63d9f0c2b7e4d18a5f3+JWT_SECRET={{fake:base64-padded}}+DB_PASSWORD={{fake:symbol-secret}}+ADMIN_PASSWORD=$POSTGRES_PASSWORD_PRODdiff --git a/tests/fixtures/secrets/.env.example b/tests/fixtures/secrets/.env.exampleindex 0121fcd..32db54e 100644--- a/tests/fixtures/secrets/.env.example+++ b/tests/fixtures/secrets/.env.example@@ -7,3 +7,4 @@ PORT=3000STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxxxxxTOKEN_SECRET="this-is-a-secret-value-with-at-least-32-characters"MQTT_PASSWORD="a_secure_password"+PASSWORD=****************diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTEDindex 3bc4655..8abb36a 100644--- a/tests/fixtures/secrets/EXPECTED+++ b/tests/fixtures/secrets/EXPECTED@@ -1,4 +1,6 @@.env:2 secret.env-file+.env:6 secret.env-file+.env:7 secret.env-fileapp/db.js:1 secret.url-credentialsconfig.py:1 secret.aws-access-keyconfig.py:10 secret.google-api-key