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 SSRF in Go and PHP (#91)
Onur Ugur52d655eb1812
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d0f19b9..4054eed 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,6 +28,8 @@- 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.+- Code: `code.ssrf` also covers Go (`http.Get`, `http.Head`, `http.Post` with `r.FormValue(...)` or `r.URL.Query().Get(...)`)+ and PHP (`file_get_contents`, `curl_init`, `fopen` with `$_GET`, `$_POST` or `$_REQUEST`). A fixed URL stays unflagged.- Code: `code.open-redirect` now also matches a status code first, so `res.redirect(301, req.query.next)` is reported; 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.diff --git a/src/rules/code.rs b/src/rules/code.rsindex d0d9f80..62a2b1e 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.ssrf",+ High,+ go,+ r"\bhttp\.(?:Get|Head|Post)\(\s*(?:r|req)\.(?:FormValue\(|URL\.Query\(\)\.Get\()",+ None,+ "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.ssrf",+ High,+ php,+ r"\b(?:file_get_contents|curl_init|fopen)\s*\(\s*\$_(?:GET|POST|REQUEST)\b",+ None,+ "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,diff --git a/tests/fixtures/code/EXPECTED b/tests/fixtures/code/EXPECTEDindex 0b78a59..ba2b5b1 100644--- a/tests/fixtures/code/EXPECTED+++ b/tests/fixtures/code/EXPECTED@@ -10,8 +10,10 @@ api/handler.go:1 code.command-injectionapi/handler.go:3 code.sql-injectionapi/handler.go:4 code.tls-verify-offapi/handler.go:5 code.weak-hash+api/handler.go:6 code.ssrfapi/index.php:1 code.sql-injectionapi/index.php:11 code.sql-injection+api/index.php:12 code.ssrfapi/index.php:2 code.command-injectionapi/index.php:3 code.file-inclusionapi/index.php:4 code.unsafe-deserializationdiff --git a/tests/fixtures/code/api/handler.go b/tests/fixtures/code/api/handler.goindex 0211b1d..e977170 100644--- a/tests/fixtures/code/api/handler.go+++ b/tests/fixtures/code/api/handler.go@@ -3,3 +3,6 @@ cmd := exec.Command("git", "log")q := fmt.Sprintf("SELECT * FROM users WHERE id = %s", id)tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}h := md5.New()+resp, err := http.Get(r.FormValue("u"))+resp, err := http.Get("https://api.example.com")+resp, err := http.Get(url)diff --git a/tests/fixtures/code/api/index.php b/tests/fixtures/code/api/index.phpindex 5ad8b66..89ca6bf 100644--- a/tests/fixtures/code/api/index.php+++ b/tests/fixtures/code/api/index.php@@ -9,3 +9,5 @@ $query = "SELECT first_name FROM users WHERE user_id = '$id';";$cmd = shell_exec('ping -c 4 ' . $target);$q = "SELECT * FROM t WHERE id = ?";$insert = "UPDATE users SET password = '$pass_new' WHERE user = 1";+$page = file_get_contents($_GET['url']);+$page = file_get_contents("https://api.example.com/status");