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(code): detect open redirects built from request input (#74)
Ahmad Ghozali652b89a4ef2e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b12e277..1fdb80e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,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 `-`).+- 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.- 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/README.md b/README.mdindex b7c653f..1faf296 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 77 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 78 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-77 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.+78 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 inames 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 77 problems were found, not that the code is safe. [Design notes](docs/adr).+these 78 problems were found, not that the code is safe. [Design notes](docs/adr).## Creditsdiff --git a/docs/rules.md b/docs/rules.mdindex 7edf91d..7954986 100644--- a/docs/rules.md+++ b/docs/rules.md@@ -2,7 +2,7 @@Every rule safe-anything checks, generated from `safe-anything --list-rules --json`. Each links to the OWASP page that explains the problem and the fix.-## Code (24)+## Code (25)| Rule | Severity | CWE | OWASP | What it means || --- | --- | --- | --- | --- |@@ -17,6 +17,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`code.sql-injection`](https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html) | high | [CWE-89](https://cwe.mitre.org/data/definitions/89.html) | A03:2021 Injection | A SQL query is built from variables by string formatting, so input can change the query (SQL injection). || [`code.path-traversal`](https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html) | high | [CWE-22](https://cwe.mitre.org/data/definitions/22.html) | A01:2021 Broken Access Control | A file path comes straight from the request, so ../ can reach any file on the server (path traversal). || [`code.ssrf`](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html) | high | [CWE-918](https://cwe.mitre.org/data/definitions/918.html) | A10:2021 Server-Side Request Forgery | The server fetches a URL taken from the request, so users can reach internal services (SSRF). |+| [`code.open-redirect`](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) | medium | [CWE-601](https://cwe.mitre.org/data/definitions/601.html) | A01:2021 Broken Access Control | The redirect target is taken from the request, so a crafted link can send users to any site from your domain (open redirect). || [`code.tls-verify-off`](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html) | medium | [CWE-295](https://cwe.mitre.org/data/definitions/295.html) | A02:2021 Cryptographic Failures | TLS certificate checks are turned off, so anyone on the network can read or change the traffic. || [`code.weak-hash`](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) | low | [CWE-328](https://cwe.mitre.org/data/definitions/328.html) | A02:2021 Cryptographic Failures | MD5 and SHA-1 are broken for security use (collisions; too fast for passwords). || [`code.weak-cipher`](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html) | medium | [CWE-327](https://cwe.mitre.org/data/definitions/327.html) | A02:2021 Cryptographic Failures | A weak cipher or ECB mode is used; ECB leaks patterns and DES/RC4 are broken. |diff --git a/src/refs.rs b/src/refs.rsindex e3eb161..ab1a726 100644--- a/src/refs.rs+++ b/src/refs.rs@@ -64,6 +64,11 @@ pub fn of(id: &str) -> Refs {"A10:2021 Server-Side Request Forgery","Server_Side_Request_Forgery_Prevention_Cheat_Sheet"),+ "code.open-redirect" => r!(+ "CWE-601",+ "A01:2021 Broken Access Control",+ "Unvalidated_Redirects_and_Forwards_Cheat_Sheet"+ ),"code.tls-verify-off" => r!("CWE-295","A02:2021 Cryptographic Failures",diff --git a/src/rules/code.rs b/src/rules/code.rsindex a03fb82..bd31eb4 100644--- a/src/rules/code.rs+++ b/src/rules/code.rs@@ -328,6 +328,24 @@ pub static RULES: &[Rule] = &["The server fetches a URL taken from the request, so users can reach internal services (SSRF).","Allow only known hosts, block private and link-local addresses, and never pass the raw URL through."),+ rule!(+ "code.open-redirect",+ Medium,+ js,+ r"\b(?:res|response|reply)\.redirect\s*\(\s*req\.(?:query|params|body)",+ None,+ "The redirect target is taken from the request, so a crafted link can send users to any site from your domain (open redirect).",+ "Redirect only to a fixed path or a URL on an allow list; never pass request input straight to redirect."+ ),+ rule!(+ "code.open-redirect",+ Medium,+ py,+ r"\bredirect\s*\(\s*request\.(?:args|form|values|GET|POST|query_params)",+ None,+ "The redirect target is taken from the request, so a crafted link can send users to any site from your domain (open redirect).",+ "Redirect only to a fixed path or a URL on an allow list; never pass request input straight to redirect."+ ),rule!("code.tls-verify-off",Medium,diff --git a/tests/fixtures/code/EXPECTED b/tests/fixtures/code/EXPECTEDindex 92ecfdf..7ead0c0 100644--- a/tests/fixtures/code/EXPECTED+++ b/tests/fixtures/code/EXPECTED@@ -40,6 +40,7 @@ api/views.py:20 code.template-injectionapi/views.py:21 code.unsafe-deserializationapi/views.py:22 code.unsafe-deserializationapi/views.py:25 code.unsafe-deserialization+api/views.py:26 code.open-redirectapi/views.py:4 code.command-injectionapi/views.py:7 code.command-injectionapi/views.py:9 code.unsafe-deserialization@@ -61,6 +62,7 @@ web/app.js:27 code.insecure-cookieweb/app.js:28 code.jwt-noneweb/app.js:29 code.cors-wildcardweb/app.js:30 code.insecure-random+web/app.js:32 code.open-redirectweb/app.js:4 code.xss-inner-htmlweb/app.js:5 code.xss-document-writeweb/app.js:6 code.evaldiff --git a/tests/fixtures/code/api/views.py b/tests/fixtures/code/api/views.pyindex afe9b29..c5cb5d5 100644--- a/tests/fixtures/code/api/views.py+++ b/tests/fixtures/code/api/views.py@@ -23,3 +23,5 @@ docs = yaml.load_all(stream)docs = yaml.load_all(stream, Loader=yaml.SafeLoader)cfg = yaml.safe_load(stream)a = yaml.unsafe_load(payload); b = yaml.load(other, Loader=yaml.SafeLoader)+return redirect(request.args.get("next"))+return redirect("/home")diff --git a/tests/fixtures/code/web/app.js b/tests/fixtures/code/web/app.jsindex badb498..ee7e8f7 100644--- a/tests/fixtures/code/web/app.js+++ b/tests/fixtures/code/web/app.js@@ -29,3 +29,5 @@ jwt.verify(token, key, { algorithms: ['none'] });res.setHeader('Access-Control-Allow-Origin', '*');const token = Math.random().toString(36);const jitter = Math.random() * 100;+res.redirect(req.query.next);+res.redirect('/home');