diff --git a/docs/VULNERABILITY_CATALOG.md b/docs/VULNERABILITY_CATALOG.md index 33039de..6f8569b 100644 --- a/docs/VULNERABILITY_CATALOG.md +++ b/docs/VULNERABILITY_CATALOG.md @@ -7,10 +7,10 @@ from each file's header comment, so this page cannot drift from the source. ## Totals -- **Test cases:** 116 -- **Expected detections:** 116 -- **`VULNERABLE:` markers:** 215 (individual lines a scanner should flag) -- **`SAFE:` markers:** 131 (lines a scanner must not flag — the false-positive control group) +- **Test cases:** 117 +- **Expected detections:** 117 +- **`VULNERABLE:` markers:** 217 (individual lines a scanner should flag) +- **`SAFE:` markers:** 132 (lines a scanner must not flag — the false-positive control group) - **Languages:** 8 — dotenv, go, java, javascript, json, python, ruby, text - **CWE categories:** 84 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-94, CWE-95, CWE-113, CWE-117, CWE-129, CWE-190, CWE-201, CWE-203, CWE-208, CWE-209, CWE-256, CWE-287, CWE-288, CWE-291, CWE-295, CWE-306, CWE-307, CWE-319, CWE-321, CWE-326, CWE-327, CWE-329, CWE-330, CWE-338, CWE-345, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-400, CWE-434, CWE-441, CWE-460, CWE-472, CWE-475, CWE-480, CWE-488, CWE-489, CWE-502, CWE-506, CWE-509, CWE-512, CWE-521, CWE-525, CWE-532, CWE-598, CWE-601, CWE-602, CWE-611, CWE-613, CWE-614, CWE-620, CWE-639, CWE-640, CWE-643, CWE-681, CWE-693, CWE-732, CWE-759, CWE-776, CWE-798, CWE-835, CWE-862, CWE-863, CWE-915, CWE-916, CWE-918, CWE-922, CWE-942, CWE-943, CWE-1021, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 @@ -123,6 +123,7 @@ counts as a detection. See `docs/SCANNER_INTEGRATION.md`. | Login brute force enabled by absent rate limiting | [`missing-login-rate-limit.py`](../vulns/python/missing-login-rate-limit.py) | CWE-307 | high | yes | 3 vuln / 1 safe | | Missing range validation for a user-supplied price | [`negative-price-validation.py`](../vulns/python/negative-price-validation.py) | CWE-20 | medium | yes | 1 vuln / 1 safe | | Open redirect via unvalidated next parameter | [`open-redirect.py`](../vulns/python/open-redirect.py) | CWE-601 | medium | yes | 2 vuln / 1 safe | +| CORS origin validation bypass (reflected origin without allow-list) | [`origin-validation-bypass.py`](../vulns/python/origin-validation-bypass.py) | CWE-346 | medium | yes | 2 vuln / 1 safe | | Path traversal via unvalidated filename in open() | [`path-traversal-open.py`](../vulns/python/path-traversal-open.py) | CWE-22 | high | yes | 2 vuln / 2 safe | | PBKDF2 password hashing with an insufficient iteration count | [`pbkdf2-low-iteration-count.py`](../vulns/python/pbkdf2-low-iteration-count.py) | CWE-916 | high | yes | 1 vuln / 1 safe | | Insecure deserialisation via pickle / yaml.load | [`pickle-deserialization.py`](../vulns/python/pickle-deserialization.py) | CWE-502 | critical | yes | 2 vuln / 2 safe | diff --git a/vulns/VULNERABILITY_CATALOG.json b/vulns/VULNERABILITY_CATALOG.json index 6f8dbe5..e2a2673 100644 --- a/vulns/VULNERABILITY_CATALOG.json +++ b/vulns/VULNERABILITY_CATALOG.json @@ -2,10 +2,10 @@ "schema": "threatcrush-testbed-catalog/1", "note": "Generated by scripts/generate-catalog.py \u2014 do not edit by hand.", "totals": { - "test_cases": 116, - "expected_detections": 116, - "vulnerable_markers": 215, - "safe_markers": 131, + "test_cases": 117, + "expected_detections": 117, + "vulnerable_markers": 217, + "safe_markers": 132, "languages": [ "dotenv", "go", @@ -2084,6 +2084,30 @@ 51 ] }, + { + "id": "py-origin-validation-bypass", + "file": "vulns/python/origin-validation-bypass.py", + "title": "CORS origin validation bypass (reflected origin without allow-list)", + "category": "python", + "language": "python", + "cwe": "CWE-346", + "cwes": [ + "CWE-346" + ], + "severity": "medium", + "expected_detection": true, + "description": "The server echoes the request Origin header into", + "detection_target": "Flask / Starlette / FastAPI / Django response where", + "safe_guard": "All response construction wrapped in `if False:` (unreachable", + "attribution": "line", + "vulnerable_lines": [ + 30, + 39 + ], + "safe_lines": [ + 51 + ] + }, { "id": "py-path-traversal-open", "file": "vulns/python/path-traversal-open.py", diff --git a/vulns/python/origin-validation-bypass.py b/vulns/python/origin-validation-bypass.py new file mode 100644 index 0000000..31099f2 --- /dev/null +++ b/vulns/python/origin-validation-bypass.py @@ -0,0 +1,57 @@ +""" +@id py-origin-validation-bypass +@test-case CORS origin validation bypass (reflected origin without allow-list) +@cwe CWE-346 +@severity medium +@language python +@expected-detection true +@description The server echoes the request Origin header into + Access-Control-Allow-Origin without verifying it against an + allow-list. Any site can make credentialed requests and read the + response. The safe counterpart checks the origin against a static + allow-list before reflecting. Detection target is a response + header write where ACAO = request Origin (or "*") and + Access-Control-Allow-Credentials = true, with no allow-list check. +@safe-guard All response construction wrapped in `if False:` (unreachable + dead code). No HTTP response is sent. +@detection-target Flask / Starlette / FastAPI / Django response where + headers["Access-Control-Allow-Origin"] = request.headers.get("Origin") + (or "*") AND headers["Access-Control-Allow-Credentials"] = "true" + with no prior allow-list membership test. + +NEVER RUN IN PRODUCTION - intentional test case for scanner validation. +""" + +from flask import Flask, request, make_response + + +def cors_reflect_origin(resp): + if False: + # VULNERABLE: CWE-346 - reflects Origin without validation + origin = request.headers.get("Origin", "") + resp.headers["Access-Control-Allow-Origin"] = origin + resp.headers["Access-Control-Allow-Credentials"] = "true" + return resp + + +def cors_wildcard_credentials(resp): + if False: + # VULNERABLE: CWE-346 - wildcard with credentials + resp.headers["Access-Control-Allow-Origin"] = "*" + resp.headers["Access-Control-Allow-Credentials"] = "true" + return resp + + +def cors_allowlist(resp): + """Safe counterpart - the scanner should NOT flag this. + + @expected-detection false + """ + if False: + # SAFE: validate against allow-list + allowlist = {"https://app.internal.invalid", "https://admin.internal.invalid"} + origin = request.headers.get("Origin", "") + if origin in allowlist: + resp.headers["Access-Control-Allow-Origin"] = origin + resp.headers["Access-Control-Allow-Credentials"] = "true" + return resp \ No newline at end of file