diff --git a/docs/VULNERABILITY_CATALOG.md b/docs/VULNERABILITY_CATALOG.md index 5763d34..29321ae 100644 --- a/docs/VULNERABILITY_CATALOG.md +++ b/docs/VULNERABILITY_CATALOG.md @@ -7,12 +7,12 @@ from each file's header comment, so this page cannot drift from the source. ## Totals -- **Test cases:** 62 -- **Expected detections:** 62 -- **`VULNERABLE:` markers:** 123 (individual lines a scanner should flag) -- **`SAFE:` markers:** 73 (lines a scanner must not flag — the false-positive control group) +- **Test cases:** 63 +- **Expected detections:** 63 +- **`VULNERABLE:` markers:** 124 (individual lines a scanner should flag) +- **`SAFE:` markers:** 74 (lines a scanner must not flag — the false-positive control group) - **Languages:** 8 — dotenv, go, java, javascript, json, python, ruby, text -- **CWE categories:** 46 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-256, CWE-295, CWE-321, CWE-327, CWE-330, CWE-338, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-489, CWE-502, CWE-506, CWE-532, CWE-601, CWE-611, CWE-614, CWE-639, CWE-643, CWE-681, CWE-759, CWE-798, CWE-862, CWE-915, CWE-918, CWE-942, CWE-943, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 +- **CWE categories:** 47 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-214, CWE-256, CWE-295, CWE-321, CWE-327, CWE-330, CWE-338, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-489, CWE-502, CWE-506, CWE-532, CWE-601, CWE-611, CWE-614, CWE-639, CWE-643, CWE-681, CWE-759, CWE-798, CWE-862, CWE-915, CWE-918, CWE-942, CWE-943, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 ## How coverage is scored @@ -71,6 +71,7 @@ counts as a detection. See `docs/SCANNER_INTEGRATION.md`. | Test case | File | CWE | Severity | Expected | Markers | |---|---|---|---|---|---| | CSV formula injection from untrusted spreadsheet cells | [`csv-formula-injection.py`](../vulns/python/csv-formula-injection.py) | CWE-1236 | medium | yes | 1 vuln / 1 safe | +| Process environment variable injection from untrusted input | [`cwe-214-python.py`](../vulns/python/cwe-214-python.py) | CWE-214 | high | yes | 1 vuln / 1 safe | | Excessive user-record exposure in an API response | [`excessive-data-exposure.py`](../vulns/python/excessive-data-exposure.py) | CWE-201 | high | yes | 1 vuln / 1 safe | | Flask debug mode enabled in application configuration | [`flask-debug-enabled.py`](../vulns/python/flask-debug-enabled.py) | CWE-489 | high | yes | 1 vuln / 1 safe | | Hardcoded secret used to configure session signing | [`hardcoded-session-secret.py`](../vulns/python/hardcoded-session-secret.py) | CWE-798 | high | yes | 1 vuln / 1 safe | diff --git a/vulns/VULNERABILITY_CATALOG.json b/vulns/VULNERABILITY_CATALOG.json index 153fdaf..436e9fe 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": 62, - "expected_detections": 62, - "vulnerable_markers": 123, - "safe_markers": 73, + "test_cases": 63, + "expected_detections": 63, + "vulnerable_markers": 124, + "safe_markers": 74, "languages": [ "dotenv", "go", @@ -38,6 +38,7 @@ "CWE-190", "CWE-201", "CWE-209", + "CWE-214", "CWE-256", "CWE-295", "CWE-321", @@ -791,6 +792,29 @@ 40 ] }, + { + "id": "py-cwe-214-process-environment-injection", + "file": "vulns/python/cwe-214-python.py", + "title": "Process environment variable injection from untrusted input", + "category": "python", + "language": "python", + "cwe": "CWE-214", + "cwes": [ + "CWE-214" + ], + "severity": "high", + "expected_detection": true, + "description": "User-controlled input is used to set an environment variable", + "detection_target": "Taint flow from request input into os.environ assignment", + "safe_guard": "The entire fixture is wrapped in `if False:` and cannot execute. It", + "attribution": "line", + "vulnerable_lines": [ + 27 + ], + "safe_lines": [ + 41 + ] + }, { "id": "py-excessive-data-exposure", "file": "vulns/python/excessive-data-exposure.py", diff --git a/vulns/python/cwe-214-python.py b/vulns/python/cwe-214-python.py new file mode 100644 index 0000000..0d0800b --- /dev/null +++ b/vulns/python/cwe-214-python.py @@ -0,0 +1,42 @@ +""" +@id py-cwe-214-process-environment-injection +@test-case Process environment variable injection from untrusted input +@cwe CWE-214 +@severity high +@language python +@expected-detection true +@description User-controlled input is used to set an environment variable + without validation, allowing an attacker to influence the + behavior of child processes or the current process. +@safe-guard The entire fixture is wrapped in `if False:` and cannot execute. It + writes only to an in-memory dictionary and never to the real + environment. +@detection-target Taint flow from request input into os.environ assignment + without sanitization. + +NEVER RUN IN PRODUCTION - intentional test case for scanner validation. +""" + + +if False: + import os + + def set_env_vulnerable(request): + env_name = request.form["env_name"] # SOURCE: attacker-controlled + env_value = request.form["env_value"] + os.environ[env_name] = env_value # VULNERABLE: CWE-214 + return "Environment variable set" + + def validate_env_name(name): + # Only allow alphanumeric and underscore, must start with letter + if not name or not name[0].isalpha(): + return False + return all(c.isalnum() or c == "_" for c in name) + + def set_env_safe(request): + env_name = request.form["env_name"] + env_value = request.form["env_value"] + if not validate_env_name(env_name): + return "Invalid environment variable name" + os.environ[env_name] = env_value # SAFE: validated name + return "Environment variable set" # @expected-detection false \ No newline at end of file