{"id":"psp-276-71af6cf761fcf47e","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1784_26 = \"defensive\"\n\ndef load_insecure_file_permissions_1784_26(request_1784_26, scope_1784_26):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1784_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1784_26).write_text(scope_1784_26, encoding=\"utf-8\")\n os.chmod(request_1784_26, 0o600)\n return Path(request_1784_26)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1784_26 = \"defensive\"\n\ndef load_insecure_file_permissions_1784_26(request_1784_26, scope_1784_26):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1784_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1784_26).write_text(scope_1784_26, encoding=\"utf-8\")\n os.chmod(request_1784_26, 0o600)\n return Path(request_1784_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_71af6cf7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_1784_26)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-5b78871d20b88914","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_9064_7 = \"defensive\"\n\ndef resolve_flask_open_redirect_9064_7(payload_9064_7):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_9064_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(payload_9064_7)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_9064_7 = \"defensive\"\n\ndef resolve_flask_open_redirect_9064_7(payload_9064_7):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_9064_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9064_7)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_9064_7)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_5b78871d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_9064_7)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-228d2ade3a23c12f","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_1737_17 = \"defensive\"\n\ndef apply_regex_dos_1737_17(subject_1737_17, target_1737_17):\n if HANDLER_KIND_APPLY_REGEX_DOS_1737_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1737_17) > 256 or len(target_1737_17) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1737_17), target_1737_17) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_1737_17 = \"defensive\"\n\ndef apply_regex_dos_1737_17(subject_1737_17, target_1737_17):\n if HANDLER_KIND_APPLY_REGEX_DOS_1737_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1737_17) > 256 or len(target_1737_17) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1737_17), target_1737_17) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_228d2ade_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_regex_dos_1737_17)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-534f7497e451f0ad","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7592_6 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7592_6(subject_7592_6, context_7592_6):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7592_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7592_6.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_7592_6\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7592_6 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7592_6(subject_7592_6, context_7592_6):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7592_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_7592_6)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_7592_6.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_7592_6\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_534f7497_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_7592_6)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-e92e12bcb214ba24","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_3786_2 = \"defensive\"\n\ndef apply_lxml_external_entity_3786_2(payload_3786_2):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_3786_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_3786_2, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_3786_2 = \"defensive\"\n\ndef apply_lxml_external_entity_3786_2(payload_3786_2):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_3786_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_3786_2, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_e92e12bc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_external_entity_3786_2)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-321a0bb27a9454e1","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4833_28 = \"defensive\"\n\ndef apply_flask_session_fixation_4833_28(request_4833_28, context_4833_28):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4833_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_4833_28[\"user_id\"] = context_4833_28.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4833_28 = \"defensive\"\n\ndef apply_flask_session_fixation_4833_28(request_4833_28, context_4833_28):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4833_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_4833_28.clear()\n request_4833_28[\"user_id\"] = context_4833_28.id\n request_4833_28[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_321a0bb2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_4833_28)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-fb69826bc812b6a5","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_1889_28 = \"defensive\"\n\ndef resolve_regex_dos_1889_28(payload_1889_28, scope_1889_28):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_1889_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_1889_28, scope_1889_28) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_1889_28 = \"defensive\"\n\ndef resolve_regex_dos_1889_28(payload_1889_28, scope_1889_28):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_1889_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_1889_28) > 256 or len(scope_1889_28) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_1889_28), scope_1889_28) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_fb69826b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_regex_dos_1889_28)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-8f9561f4ae0332c3","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_5345_1 = \"defensive\"\n\ndef load_dynamic_code_injection_5345_1(request_5345_1):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_5345_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_5345_1, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_5345_1 = \"defensive\"\n\ndef load_dynamic_code_injection_5345_1(request_5345_1):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_5345_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_5345_1) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_5345_1)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_8f9561f4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_dynamic_code_injection_5345_1)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-8748c120cd622dd7","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7265_24 = \"defensive\"\n\ndef process_http_response_splitting_7265_24(payload_7265_24, context_7265_24):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7265_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7265_24.headers[\"X-Next\"] = context_7265_24\n return payload_7265_24\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7265_24 = \"defensive\"\n\ndef process_http_response_splitting_7265_24(payload_7265_24, context_7265_24):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7265_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7265_24 or \"\\n\" in context_7265_24:\n raise ValueError(\"invalid header value\")\n payload_7265_24.headers[\"X-Next\"] = context_7265_24\n return payload_7265_24\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_8748c120_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_7265_24)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-8a4ca4bad1ae1f74","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_9171_18 = \"defensive\"\n\ndef apply_resource_consumption_9171_18(value_9171_18, context_9171_18):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_9171_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9171_18.read(int(context_9171_18))\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_9171_18 = \"defensive\"\n\ndef apply_resource_consumption_9171_18(value_9171_18, context_9171_18):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_9171_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_9171_18), 1), 1_048_576)\n data = value_9171_18.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_8a4ca4ba_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_9171_18)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-9a4318dab154fec4","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_9119_3 = \"defensive\"\n\ndef load_dynamic_code_injection_9119_3(subject_9119_3):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_9119_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_9119_3, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_9119_3 = \"defensive\"\n\ndef load_dynamic_code_injection_9119_3(subject_9119_3):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_9119_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_9119_3) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_9119_3)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_9a4318da_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_dynamic_code_injection_9119_3)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-b4f3b58fc92589d3","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_3394_10 = \"defensive\"\n\ndef resolve_weak_cryptography_3394_10(subject_3394_10, policy_3394_10):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_3394_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_3394_10.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_3394_10 = \"defensive\"\n\ndef resolve_weak_cryptography_3394_10(subject_3394_10, policy_3394_10):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_3394_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_3394_10.encode(\"utf-8\"), policy_3394_10, 200000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_b4f3b58f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_3394_10)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-489a1d6f51a97e87","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1771_15 = \"defensive\"\n\ndef handle_csv_formula_injection_1771_15(subject_1771_15):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1771_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in subject_1771_15)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1771_15 = \"defensive\"\n\ndef handle_csv_formula_injection_1771_15(subject_1771_15):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1771_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_1771_15)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_489a1d6f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_1771_15)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-61fd4ac4336cd882","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2013_25 = \"defensive\"\n\ndef load_cleartext_http_transport_2013_25(payload_2013_25):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2013_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_2013_25, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2013_25 = \"defensive\"\n\ndef load_cleartext_http_transport_2013_25(payload_2013_25):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2013_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_2013_25, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_61fd4ac4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_2013_25)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-c4f2a8230a8ef324","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2363_11 = \"defensive\"\n\ndef resolve_lxml_external_entity_2363_11(payload_2363_11):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2363_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_2363_11, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2363_11 = \"defensive\"\n\ndef resolve_lxml_external_entity_2363_11(payload_2363_11):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2363_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_2363_11, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_c4f2a823_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_2363_11)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a211b073fecec4f1","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1890_14 = \"defensive\"\n\ndef load_httpx_client_ssrf_1890_14(payload_1890_14, target_1890_14, options_1890_14):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1890_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_1890_14)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_1890_14):\n raise ValueError(\"destination is not allowed\")\n return payload_1890_14.get(target_1890_14, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1890_14 = \"defensive\"\n\ndef load_httpx_client_ssrf_1890_14(payload_1890_14, target_1890_14, options_1890_14):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1890_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_1890_14)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_1890_14):\n raise ValueError(\"destination is not allowed\")\n return payload_1890_14.get(target_1890_14, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_a211b073_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_1890_14)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-12f8f25e72bd78ee","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5570_16 = \"defensive\"\n\ndef load_fastapi_upload_validation_5570_16(payload_5570_16):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5570_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_5570_16.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5570_16 = \"defensive\"\n\ndef load_fastapi_upload_validation_5570_16(payload_5570_16):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5570_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_5570_16.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_5570_16.size is None or payload_5570_16.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_5570_16.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_12f8f25e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_upload_validation_5570_16)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-0505b014dc2b696a","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_5980_16 = \"defensive\"\n\ndef apply_insecure_random_token_5980_16(subject_5980_16):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_5980_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_5980_16)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_5980_16 = \"defensive\"\n\ndef apply_insecure_random_token_5980_16(subject_5980_16):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_5980_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_5980_16)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_0505b014_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_5980_16)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-a359e2ccb3df38c4","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_6598_4 = \"defensive\"\n\ndef resolve_log_injection_6598_4(value_6598_4, scope_6598_4):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_6598_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6598_4.warning(\"audit=%s\", scope_6598_4)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_6598_4 = \"defensive\"\n\ndef resolve_log_injection_6598_4(value_6598_4, scope_6598_4):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_6598_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_6598_4).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_6598_4.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_a359e2cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_6598_4)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-76288f3f0f9c091d","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_6272_29 = \"defensive\"\n\ndef process_ssrf_6272_29(payload_6272_29, context_6272_29):\n if HANDLER_KIND_PROCESS_SSRF_6272_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_6272_29)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_6272_29):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_6272_29, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_6272_29 = \"defensive\"\n\ndef process_ssrf_6272_29(payload_6272_29, context_6272_29):\n if HANDLER_KIND_PROCESS_SSRF_6272_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_6272_29)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_6272_29):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_6272_29, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_76288f3f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ssrf_6272_29)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-32549dda917606d7","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2103_18 = \"defensive\"\n\ndef apply_ldap_filter_injection_2103_18(request_2103_18, policy_2103_18):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2103_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={policy_2103_18})\"\n return request_2103_18.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2103_18 = \"defensive\"\n\ndef apply_ldap_filter_injection_2103_18(request_2103_18, policy_2103_18):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2103_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_2103_18)\n query = f\"(uid={escaped})\"\n return request_2103_18.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_32549dda_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ldap_filter_injection_2103_18)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4c57ef144c03ec8f","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_6220_20 = \"defensive\"\n\ndef load_tarfile_path_traversal_6220_20(value_6220_20, scope_6220_20):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_6220_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6220_20.extractall(scope_6220_20, filter=\"data\")\n return scope_6220_20\n","fixed_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_6220_20 = \"defensive\"\n\ndef load_tarfile_path_traversal_6220_20(value_6220_20, scope_6220_20):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_6220_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6220_20.extractall(scope_6220_20, filter=\"data\")\n return scope_6220_20\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_4c57ef14_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_tarfile_path_traversal_6220_20)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-c989a4d2b1e23477","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_5089_22 = \"defensive\"\n\ndef handle_flask_open_redirect_5089_22(value_5089_22):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_5089_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_5089_22)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_5089_22 = \"defensive\"\n\ndef handle_flask_open_redirect_5089_22(value_5089_22):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_5089_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_5089_22)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_5089_22)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_c989a4d2_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_5089_22)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-74fcd546cf9fc040","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3610_21 = \"defensive\"\n\ndef apply_mass_assignment_3610_21(subject_3610_21, context_3610_21):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3610_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in context_3610_21.items():\n setattr(subject_3610_21, key, value)\n return subject_3610_21\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3610_21 = \"defensive\"\n\ndef apply_mass_assignment_3610_21(subject_3610_21, context_3610_21):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3610_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_3610_21.items() if key in allowed_fields}\n subject_3610_21.update(safe)\n return subject_3610_21\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_74fcd546_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_3610_21)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-9f552d80108a1c69","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_3265_0 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_3265_0(request_3265_0):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_3265_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_3265_0, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_3265_0 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_3265_0(request_3265_0):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_3265_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_3265_0)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_9f552d80_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_3265_0)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-ad321856e05d4615","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4471_28 = \"defensive\"\n\ndef apply_django_safe_string_xss_4471_28(payload_4471_28):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4471_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_4471_28}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4471_28 = \"defensive\"\n\ndef apply_django_safe_string_xss_4471_28(payload_4471_28):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4471_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_4471_28)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_ad321856_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_4471_28)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-8f053d53362094e8","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7747_13 = \"defensive\"\n\ndef process_plaintext_password_storage_7747_13(request_7747_13, context_7747_13, owner_7747_13):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7747_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_7747_13).write_text(context_7747_13, encoding=\"utf-8\")\n return Path(request_7747_13)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7747_13 = \"defensive\"\n\ndef process_plaintext_password_storage_7747_13(request_7747_13, context_7747_13, owner_7747_13):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7747_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_7747_13) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", context_7747_13.encode(\"utf-8\"), owner_7747_13, 240_000).hex()\n Path(request_7747_13).write_text(verifier, encoding=\"ascii\")\n return Path(request_7747_13)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_8f053d53_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_7747_13)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-8b1814f123389746","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_3978_5 = \"defensive\"\n\ndef process_flask_csrf_validation_3978_5(payload_3978_5, context_3978_5):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_3978_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_3978_5.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_3978_5.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_3978_5.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_3978_5 = \"defensive\"\n\ndef process_flask_csrf_validation_3978_5(payload_3978_5, context_3978_5):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_3978_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_3978_5.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_3978_5.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_3978_5.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_8b1814f1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_3978_5)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-d3f1cfedf89c015b","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_3151_25 = \"defensive\"\n\ndef resolve_django_safe_string_xss_3151_25(value_3151_25):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_3151_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{value_3151_25}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_3151_25 = \"defensive\"\n\ndef resolve_django_safe_string_xss_3151_25(value_3151_25):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_3151_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_3151_25)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_d3f1cfed_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_3151_25)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-5ce6a0e20284ccf4","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4849_26 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_4849_26(value_4849_26, scope_4849_26, options_4849_26):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4849_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_4849_26, scope_4849_26, algorithms=[\"HS256\"], audience=options_4849_26)\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4849_26 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_4849_26(value_4849_26, scope_4849_26, options_4849_26):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4849_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_4849_26, scope_4849_26, algorithms=[\"HS256\"], audience=options_4849_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_5ce6a0e2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_4849_26)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-ce686d532e8686d6","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6873_25 = \"defensive\"\n\ndef handle_sensitive_data_exposure_6873_25(value_6873_25, scope_6873_25, options_6873_25):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6873_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6873_25.info(\"login user=%s password=%s\", scope_6873_25, options_6873_25)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6873_25 = \"defensive\"\n\ndef handle_sensitive_data_exposure_6873_25(value_6873_25, scope_6873_25, options_6873_25):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6873_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6873_25.info(\"login user=%s\", scope_6873_25)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_ce686d53_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_6873_25)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-a73a79fed5fa68d5","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_7139_27 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_7139_27(value_7139_27, target_7139_27, options_7139_27):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_7139_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_7139_27, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_7139_27 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_7139_27(value_7139_27, target_7139_27, options_7139_27):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_7139_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_7139_27, target_7139_27, algorithms=[\"HS256\"], audience=options_7139_27)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_a73a79fe_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_7139_27)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-6f5ba0404cb3ed57","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_2974_3 = \"defensive\"\n\ndef process_regex_dos_2974_3(subject_2974_3, scope_2974_3):\n if HANDLER_KIND_PROCESS_REGEX_DOS_2974_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_2974_3, scope_2974_3) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_2974_3 = \"defensive\"\n\ndef process_regex_dos_2974_3(subject_2974_3, scope_2974_3):\n if HANDLER_KIND_PROCESS_REGEX_DOS_2974_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_2974_3) > 256 or len(scope_2974_3) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_2974_3), scope_2974_3) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_6f5ba040_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_2974_3)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-c4e3002ca173aefe","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4942_22 = \"defensive\"\n\ndef load_insecure_file_permissions_4942_22(value_4942_22, policy_4942_22):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4942_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_4942_22).write_text(policy_4942_22, encoding=\"utf-8\")\n os.chmod(value_4942_22, 0o777)\n return Path(value_4942_22)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4942_22 = \"defensive\"\n\ndef load_insecure_file_permissions_4942_22(value_4942_22, policy_4942_22):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4942_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_4942_22).write_text(policy_4942_22, encoding=\"utf-8\")\n os.chmod(value_4942_22, 0o600)\n return Path(value_4942_22)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_c4e3002c_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_4942_22)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-2d1ca93b0bf7a3c5","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2482_17 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_2482_17(subject_2482_17, target_2482_17):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2482_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2482_17.extractall(target_2482_17, filter=\"data\")\n return target_2482_17\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2482_17 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_2482_17(subject_2482_17, target_2482_17):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2482_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2482_17.extractall(target_2482_17, filter=\"data\")\n return target_2482_17\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_2d1ca93b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_2482_17)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-056f0879115255c0","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1297_25 = \"defensive\"\n\ndef handle_regex_dos_1297_25(subject_1297_25, policy_1297_25):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1297_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_1297_25, policy_1297_25) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1297_25 = \"defensive\"\n\ndef handle_regex_dos_1297_25(subject_1297_25, policy_1297_25):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1297_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1297_25) > 256 or len(policy_1297_25) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1297_25), policy_1297_25) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_056f0879_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_1297_25)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-6b7cf9c005f53d79","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9784_18 = \"defensive\"\n\ndef load_django_error_details_9784_18(payload_9784_18, scope_9784_18):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9784_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_9784_18()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9784_18 = \"defensive\"\n\ndef load_django_error_details_9784_18(payload_9784_18, scope_9784_18):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9784_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_9784_18()\n except Exception:\n payload_9784_18.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_6b7cf9c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_9784_18)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-65b47c6d7268f065","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_6709_24 = \"defensive\"\n\ndef load_insecure_file_permissions_6709_24(value_6709_24, target_6709_24):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_6709_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_6709_24).write_text(target_6709_24, encoding=\"utf-8\")\n os.chmod(value_6709_24, 0o777)\n return Path(value_6709_24)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_6709_24 = \"defensive\"\n\ndef load_insecure_file_permissions_6709_24(value_6709_24, target_6709_24):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_6709_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_6709_24).write_text(target_6709_24, encoding=\"utf-8\")\n os.chmod(value_6709_24, 0o600)\n return Path(value_6709_24)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_65b47c6d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_6709_24)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-6e419e32436806b3","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_1021_18 = \"defensive\"\n\ndef handle_sql_injection_1021_18(subject_1021_18, target_1021_18):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_1021_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {target_1021_18}\"\n return subject_1021_18.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_1021_18 = \"defensive\"\n\ndef handle_sql_injection_1021_18(subject_1021_18, target_1021_18):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_1021_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_1021_18.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (target_1021_18,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_6e419e32_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_1021_18)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-c6d7d4db8a8159f2","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7648_7 = \"defensive\"\n\ndef handle_insecure_temp_file_7648_7(request_7648_7, scope_7648_7):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7648_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{request_7648_7}.txt\")\n path.write_text(scope_7648_7, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7648_7 = \"defensive\"\n\ndef handle_insecure_temp_file_7648_7(request_7648_7, scope_7648_7):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7648_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_7648_7)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_c6d7d4db_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_temp_file_7648_7)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-e29e712d43d626ca","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_2537_26 = \"defensive\"\n\ndef resolve_log_injection_2537_26(payload_2537_26, scope_2537_26):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_2537_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_2537_26).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_2537_26.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_2537_26 = \"defensive\"\n\ndef resolve_log_injection_2537_26(payload_2537_26, scope_2537_26):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_2537_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_2537_26).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_2537_26.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_e29e712d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_2537_26)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-351bd72e3f5e80ac","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_5209_8 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_5209_8(request_5209_8):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_5209_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_5209_8)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_5209_8 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_5209_8(request_5209_8):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_5209_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_5209_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_351bd72e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_5209_8)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-20b66601d4335401","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6645_15 = \"defensive\"\n\ndef process_requests_tls_verification_6645_15(payload_6645_15):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6645_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6645_15, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6645_15 = \"defensive\"\n\ndef process_requests_tls_verification_6645_15(payload_6645_15):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6645_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6645_15, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_20b66601_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_requests_tls_verification_6645_15)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-caa5577770088e45","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_1738_22 = \"defensive\"\n\ndef handle_tarfile_path_traversal_1738_22(subject_1738_22, scope_1738_22):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_1738_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1738_22.extractall(scope_1738_22)\n return scope_1738_22\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_1738_22 = \"defensive\"\n\ndef handle_tarfile_path_traversal_1738_22(subject_1738_22, scope_1738_22):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_1738_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1738_22.extractall(scope_1738_22, filter=\"data\")\n return scope_1738_22\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_caa55777_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_1738_22)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-0396f7a9dfc192dd","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7392_23 = \"defensive\"\n\ndef process_starlette_permissive_cors_7392_23(subject_7392_23, context_7392_23):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7392_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_7392_23)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_7392_23.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_7392_23\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7392_23 = \"defensive\"\n\ndef process_starlette_permissive_cors_7392_23(subject_7392_23, context_7392_23):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7392_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_7392_23)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_7392_23.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_7392_23\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_0396f7a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_7392_23)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-762ee318ebd8dede","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_5415_6 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_5415_6(subject_5415_6, context_5415_6):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_5415_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5415_6.extractall(context_5415_6)\n return context_5415_6\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_5415_6 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_5415_6(subject_5415_6, context_5415_6):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_5415_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5415_6.extractall(context_5415_6, filter=\"data\")\n return context_5415_6\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_762ee318_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_5415_6)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-56b24457e0100fba","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_8596_15 = \"defensive\"\n\ndef process_plaintext_password_storage_8596_15(subject_8596_15, context_8596_15, owner_8596_15):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_8596_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_8596_15).write_text(context_8596_15, encoding=\"utf-8\")\n return Path(subject_8596_15)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_8596_15 = \"defensive\"\n\ndef process_plaintext_password_storage_8596_15(subject_8596_15, context_8596_15, owner_8596_15):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_8596_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_8596_15) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", context_8596_15.encode(\"utf-8\"), owner_8596_15, 240_000).hex()\n Path(subject_8596_15).write_text(verifier, encoding=\"ascii\")\n return Path(subject_8596_15)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_56b24457_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_8596_15)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-c56d7bc8ec4daa35","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_3792_0 = \"defensive\"\n\ndef apply_django_safe_string_xss_3792_0(subject_3792_0):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_3792_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{subject_3792_0}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_3792_0 = \"defensive\"\n\ndef apply_django_safe_string_xss_3792_0(subject_3792_0):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_3792_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_3792_0)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_c56d7bc8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_3792_0)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-e7477840bdc71b84","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8299_6 = \"defensive\"\n\ndef apply_weak_cryptography_8299_6(subject_8299_6, scope_8299_6):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8299_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_8299_6.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8299_6 = \"defensive\"\n\ndef apply_weak_cryptography_8299_6(subject_8299_6, scope_8299_6):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8299_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_8299_6.encode(\"utf-8\"), scope_8299_6, 210000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_e7477840_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_weak_cryptography_8299_6)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-949d2cfb8a7bac56","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_3998_4 = \"defensive\"\n\ndef handle_regex_dos_3998_4(request_3998_4, context_3998_4):\n if HANDLER_KIND_HANDLE_REGEX_DOS_3998_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(request_3998_4, context_3998_4) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_3998_4 = \"defensive\"\n\ndef handle_regex_dos_3998_4(request_3998_4, context_3998_4):\n if HANDLER_KIND_HANDLE_REGEX_DOS_3998_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_3998_4) > 256 or len(context_3998_4) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(request_3998_4), context_3998_4) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_949d2cfb_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_3998_4)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-fbb2bdd6dffeb4c2","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_2440_8 = \"defensive\"\n\ndef handle_django_error_details_2440_8(subject_2440_8, policy_2440_8):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_2440_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2440_8()\n except Exception:\n subject_2440_8.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_2440_8 = \"defensive\"\n\ndef handle_django_error_details_2440_8(subject_2440_8, policy_2440_8):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_2440_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2440_8()\n except Exception:\n subject_2440_8.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_fbb2bdd6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_error_details_2440_8)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-bbee0f6ab34a2814","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5086_14 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5086_14(value_5086_14):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5086_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_5086_14.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_5086_14.size is None or value_5086_14.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_5086_14.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5086_14 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5086_14(value_5086_14):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5086_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_5086_14.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_5086_14.size is None or value_5086_14.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_5086_14.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_bbee0f6a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_5086_14)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-bc883a363b3aee63","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1943_13 = \"defensive\"\n\ndef process_csv_formula_injection_1943_13(request_1943_13):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1943_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in request_1943_13)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1943_13 = \"defensive\"\n\ndef process_csv_formula_injection_1943_13(request_1943_13):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1943_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_1943_13)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_bc883a36_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_1943_13)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-cf7ad4de3a934fbf","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3713_9 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_3713_9(request_3713_9, context_3713_9):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3713_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_3713_9}\")\n return request_3713_9.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3713_9 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_3713_9(request_3713_9, context_3713_9):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3713_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_3713_9.execute(statement, {\"account_id\": context_3713_9}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_cf7ad4de_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_3713_9)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-ee8ac9b6e1c06398","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_3906_3 = \"defensive\"\n\ndef handle_lxml_xpath_injection_3906_3(subject_3906_3, policy_3906_3):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_3906_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{policy_3906_3}']\"\n return subject_3906_3.xpath(xpath)\n","fixed_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_3906_3 = \"defensive\"\n\ndef handle_lxml_xpath_injection_3906_3(subject_3906_3, policy_3906_3):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_3906_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3906_3.xpath(\"//user[@name=$account]\", account=policy_3906_3)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_ee8ac9b6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_xpath_injection_3906_3)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-b0fbea73d310d478","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9000_8 = \"defensive\"\n\ndef resolve_log_injection_9000_8(subject_9000_8, target_9000_8):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9000_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_9000_8).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_9000_8.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9000_8 = \"defensive\"\n\ndef resolve_log_injection_9000_8(subject_9000_8, target_9000_8):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9000_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_9000_8).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_9000_8.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_b0fbea73_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_9000_8)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-b8130ecc3652aed4","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_4630_16 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_4630_16(subject_4630_16, scope_4630_16):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_4630_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4630_16.extractall(scope_4630_16)\n return scope_4630_16\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_4630_16 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_4630_16(subject_4630_16, scope_4630_16):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_4630_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4630_16.extractall(scope_4630_16, filter=\"data\")\n return scope_4630_16\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_b8130ecc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_4630_16)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-beefe8e85ced9c5c","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1906_19 = \"defensive\"\n\ndef resolve_plaintext_password_storage_1906_19(request_1906_19, context_1906_19, options_1906_19):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1906_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1906_19).write_text(context_1906_19, encoding=\"utf-8\")\n return Path(request_1906_19)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1906_19 = \"defensive\"\n\ndef resolve_plaintext_password_storage_1906_19(request_1906_19, context_1906_19, options_1906_19):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1906_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_1906_19) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", context_1906_19.encode(\"utf-8\"), options_1906_19, 240_000).hex()\n Path(request_1906_19).write_text(verifier, encoding=\"ascii\")\n return Path(request_1906_19)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_beefe8e8_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_plaintext_password_storage_1906_19)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-0cadc729f7016243","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5761_29 = \"defensive\"\n\ndef apply_starlette_permissive_cors_5761_29(payload_5761_29, policy_5761_29):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5761_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5761_29)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_5761_29.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_5761_29\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5761_29 = \"defensive\"\n\ndef apply_starlette_permissive_cors_5761_29(payload_5761_29, policy_5761_29):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5761_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5761_29)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_5761_29.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_5761_29\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_0cadc729_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_5761_29)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-b96301824e8430d9","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_7845_11 = \"defensive\"\n\ndef handle_insecure_file_permissions_7845_11(subject_7845_11, context_7845_11):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_7845_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_7845_11).write_text(context_7845_11, encoding=\"utf-8\")\n os.chmod(subject_7845_11, 0o600)\n return Path(subject_7845_11)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_7845_11 = \"defensive\"\n\ndef handle_insecure_file_permissions_7845_11(subject_7845_11, context_7845_11):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_7845_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_7845_11).write_text(context_7845_11, encoding=\"utf-8\")\n os.chmod(subject_7845_11, 0o600)\n return Path(subject_7845_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_b9630182_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_7845_11)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-6688e47909d9a31e","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8277_29 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_8277_29(value_8277_29, policy_8277_29, options_8277_29):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8277_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_8277_29, policy_8277_29, algorithms=[\"HS256\"], audience=options_8277_29)\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8277_29 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_8277_29(value_8277_29, policy_8277_29, options_8277_29):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8277_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_8277_29, policy_8277_29, algorithms=[\"HS256\"], audience=options_8277_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_6688e479_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_8277_29)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-990c459405449a9b","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_8882_11 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_8882_11(request_8882_11):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_8882_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_8882_11)\n","fixed_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_8882_11 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_8882_11(request_8882_11):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_8882_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_8882_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_990c4594_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyyaml_unsafe_load_8882_11)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-fbc2c5e3b5f62e16","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_1039_13 = \"defensive\"\n\ndef load_fastapi_missing_authentication_1039_13(subject_1039_13, context_1039_13):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_1039_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_1039_13.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_1039_13 = \"defensive\"\n\ndef load_fastapi_missing_authentication_1039_13(subject_1039_13, context_1039_13):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_1039_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1039_13 is None or not subject_1039_13.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_1039_13.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_fbc2c5e3_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_1039_13)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-dcb3b679d4206a6c","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_6423_20 = \"defensive\"\n\ndef process_insecure_file_permissions_6423_20(value_6423_20, target_6423_20):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_6423_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_6423_20).write_text(target_6423_20, encoding=\"utf-8\")\n os.chmod(value_6423_20, 0o600)\n return Path(value_6423_20)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_6423_20 = \"defensive\"\n\ndef process_insecure_file_permissions_6423_20(value_6423_20, target_6423_20):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_6423_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_6423_20).write_text(target_6423_20, encoding=\"utf-8\")\n os.chmod(value_6423_20, 0o600)\n return Path(value_6423_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_dcb3b679_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_6423_20)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-fb4346b654d31983","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3864_2 = \"defensive\"\n\ndef load_weak_cryptography_3864_2(payload_3864_2, context_3864_2):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3864_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_3864_2.encode(\"utf-8\"), context_3864_2, 220000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3864_2 = \"defensive\"\n\ndef load_weak_cryptography_3864_2(payload_3864_2, context_3864_2):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3864_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_3864_2.encode(\"utf-8\"), context_3864_2, 220000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_fb4346b6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_3864_2)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-e48e63cbdfe9d8bb","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4563_7 = \"defensive\"\n\ndef resolve_resource_consumption_4563_7(request_4563_7, target_4563_7):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4563_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4563_7.read(int(target_4563_7))\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4563_7 = \"defensive\"\n\ndef resolve_resource_consumption_4563_7(request_4563_7, target_4563_7):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4563_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_4563_7), 1), 1_048_576)\n data = request_4563_7.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_e48e63cb_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_4563_7)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-46a7ffddec7dbfc9","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1053_11 = \"defensive\"\n\ndef resolve_log_injection_1053_11(request_1053_11, policy_1053_11):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1053_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_1053_11).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_1053_11.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1053_11 = \"defensive\"\n\ndef resolve_log_injection_1053_11(request_1053_11, policy_1053_11):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1053_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_1053_11).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_1053_11.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_46a7ffdd_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_1053_11)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-9b1965e4a6be9e0b","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5710_21 = \"defensive\"\n\ndef resolve_requests_tls_verification_5710_21(value_5710_21):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5710_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_5710_21, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5710_21 = \"defensive\"\n\ndef resolve_requests_tls_verification_5710_21(value_5710_21):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5710_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_5710_21, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_9b1965e4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_requests_tls_verification_5710_21)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-bb16e7f52faeb595","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5326_28 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_5326_28(payload_5326_28, context_5326_28, limit_5326_28):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5326_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5326_28, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5326_28 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_5326_28(payload_5326_28, context_5326_28, limit_5326_28):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5326_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5326_28, context_5326_28, algorithms=[\"HS256\"], audience=limit_5326_28)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_bb16e7f5_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_5326_28)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-6623258ffe61d327","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8357_21 = \"defensive\"\n\ndef handle_unsafe_deserialization_8357_21(value_8357_21):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8357_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_8357_21)\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8357_21 = \"defensive\"\n\ndef handle_unsafe_deserialization_8357_21(value_8357_21):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8357_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_8357_21.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_6623258f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_8357_21)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-e40543c2c80e6eca","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_4776_23 = \"defensive\"\n\ndef load_hardcoded_credentials_4776_23(subject_4776_23):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_4776_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4776_23)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_4776_23 = \"defensive\"\n\ndef load_hardcoded_credentials_4776_23(subject_4776_23):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_4776_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4776_23)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_e40543c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_4776_23)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-e065281ca4e023f8","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_4510_18 = \"defensive\"\n\ndef handle_hardcoded_credentials_4510_18(value_4510_18):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_4510_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000018\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_4510_18)}\n","fixed_code":"import os\n\nHANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_4510_18 = \"defensive\"\n\ndef handle_hardcoded_credentials_4510_18(value_4510_18):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_4510_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_4510_18)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_e065281c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_hardcoded_credentials_4510_18)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-5e13ff6b19038e7f","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_9560_27 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_9560_27(payload_9560_27, policy_9560_27):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_9560_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9560_27.extractall(policy_9560_27)\n return policy_9560_27\n","fixed_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_9560_27 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_9560_27(payload_9560_27, policy_9560_27):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_9560_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_9560_27.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_9560_27.extractall(policy_9560_27)\n return policy_9560_27\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_5e13ff6b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_zip_decompression_bomb_9560_27)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-e6ff92f0806e79ce","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_1380_25 = \"defensive\"\n\ndef process_flask_session_fixation_1380_25(request_1380_25, target_1380_25):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_1380_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1380_25[\"user_id\"] = target_1380_25.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_1380_25 = \"defensive\"\n\ndef process_flask_session_fixation_1380_25(request_1380_25, target_1380_25):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_1380_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1380_25.clear()\n request_1380_25[\"user_id\"] = target_1380_25.id\n request_1380_25[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_e6ff92f0_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_1380_25)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-a553eb945e1442a6","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_6599_16 = \"defensive\"\n\ndef process_http_response_splitting_6599_16(subject_6599_16, context_6599_16):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_6599_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_6599_16.headers[\"X-Next\"] = context_6599_16\n return subject_6599_16\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_6599_16 = \"defensive\"\n\ndef process_http_response_splitting_6599_16(subject_6599_16, context_6599_16):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_6599_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_6599_16 or \"\\n\" in context_6599_16:\n raise ValueError(\"invalid header value\")\n subject_6599_16.headers[\"X-Next\"] = context_6599_16\n return subject_6599_16\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_a553eb94_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_6599_16)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-46172fcec9060084","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4811_4 = \"defensive\"\n\ndef handle_plaintext_password_storage_4811_4(request_4811_4, target_4811_4, allowed_4811_4):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4811_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_4811_4).write_text(target_4811_4, encoding=\"utf-8\")\n return Path(request_4811_4)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4811_4 = \"defensive\"\n\ndef handle_plaintext_password_storage_4811_4(request_4811_4, target_4811_4, allowed_4811_4):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4811_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_4811_4) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_4811_4.encode(\"utf-8\"), allowed_4811_4, 240_000).hex()\n Path(request_4811_4).write_text(verifier, encoding=\"ascii\")\n return Path(request_4811_4)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_46172fce_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_4811_4)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-4a9545a336d60ddb","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6558_19 = \"defensive\"\n\ndef handle_mass_assignment_6558_19(request_6558_19, context_6558_19):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6558_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in context_6558_19.items():\n setattr(request_6558_19, key, value)\n return request_6558_19\n","fixed_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6558_19 = \"defensive\"\n\ndef handle_mass_assignment_6558_19(request_6558_19, context_6558_19):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6558_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_6558_19.items() if key in allowed_fields}\n request_6558_19.update(safe)\n return request_6558_19\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_4a9545a3_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_mass_assignment_6558_19)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-1f6a4a26f7bc702c","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_6038_4 = \"defensive\"\n\ndef apply_insecure_file_permissions_6038_4(subject_6038_4, policy_6038_4):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_6038_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_6038_4).write_text(policy_6038_4, encoding=\"utf-8\")\n os.chmod(subject_6038_4, 0o777)\n return Path(subject_6038_4)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_6038_4 = \"defensive\"\n\ndef apply_insecure_file_permissions_6038_4(subject_6038_4, policy_6038_4):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_6038_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_6038_4).write_text(policy_6038_4, encoding=\"utf-8\")\n os.chmod(subject_6038_4, 0o600)\n return Path(subject_6038_4)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_1f6a4a26_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_6038_4)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-348c5db3aa569750","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3926_25 = \"defensive\"\n\ndef resolve_csv_formula_injection_3926_25(payload_3926_25):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3926_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_3926_25)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3926_25 = \"defensive\"\n\ndef resolve_csv_formula_injection_3926_25(payload_3926_25):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3926_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_3926_25)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_348c5db3_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_3926_25)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-4272bcb8bc477069","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_4705_23 = \"defensive\"\n\ndef resolve_regex_dos_4705_23(value_4705_23, context_4705_23):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_4705_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_4705_23) > 256 or len(context_4705_23) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_4705_23), context_4705_23) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_4705_23 = \"defensive\"\n\ndef resolve_regex_dos_4705_23(value_4705_23, context_4705_23):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_4705_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_4705_23) > 256 or len(context_4705_23) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_4705_23), context_4705_23) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_4272bcb8_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_regex_dos_4705_23)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-ad349d8d27de18e5","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_5341_18 = \"defensive\"\n\ndef process_cleartext_http_transport_5341_18(value_5341_18):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_5341_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_5341_18, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_5341_18 = \"defensive\"\n\ndef process_cleartext_http_transport_5341_18(value_5341_18):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_5341_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_5341_18, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_ad349d8d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_cleartext_http_transport_5341_18)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-052b714d726153c5","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4867_9 = \"defensive\"\n\ndef handle_requests_tls_verification_4867_9(payload_4867_9):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4867_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_4867_9, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4867_9 = \"defensive\"\n\ndef handle_requests_tls_verification_4867_9(payload_4867_9):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4867_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_4867_9, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_052b714d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_4867_9)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-6a21b38270ceae5b","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_7637_1 = \"defensive\"\n\ndef handle_sensitive_data_exposure_7637_1(payload_7637_1, policy_7637_1, limit_7637_1):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_7637_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7637_1.info(\"login user=%s password=%s\", policy_7637_1, limit_7637_1)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_7637_1 = \"defensive\"\n\ndef handle_sensitive_data_exposure_7637_1(payload_7637_1, policy_7637_1, limit_7637_1):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_7637_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7637_1.info(\"login user=%s\", policy_7637_1)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_6a21b382_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_7637_1)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-354abff618bd3756","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5778_26 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5778_26(value_5778_26):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5778_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5778_26.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5778_26 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5778_26(value_5778_26):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5778_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5778_26.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_354abff6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_5778_26)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-962c5af4a70ae04b","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_6339_25 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_6339_25(request_6339_25):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_6339_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_6339_25, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_6339_25 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_6339_25(request_6339_25):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_6339_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_6339_25)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_962c5af4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_6339_25)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-c322a117069e4d49","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_6653_4 = \"defensive\"\n\ndef handle_command_injection_6653_4(value_6653_4, policy_6653_4):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_6653_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {value_6653_4} {policy_6653_4}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_6653_4 = \"defensive\"\n\ndef handle_command_injection_6653_4(value_6653_4, policy_6653_4):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_6653_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_6653_4, policy_6653_4], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_c322a117_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_6653_4)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-1902be47efa13e2c","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1960_21 = \"defensive\"\n\ndef process_hardcoded_credentials_1960_21(payload_1960_21):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1960_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000021\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_1960_21)}\n","fixed_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1960_21 = \"defensive\"\n\ndef process_hardcoded_credentials_1960_21(payload_1960_21):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1960_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_1960_21)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_1902be47_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_hardcoded_credentials_1960_21)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-4db63beda967cdf4","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_8209_0 = \"defensive\"\n\ndef load_hardcoded_credentials_8209_0(payload_8209_0):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_8209_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000000\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_8209_0)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_8209_0 = \"defensive\"\n\ndef load_hardcoded_credentials_8209_0(payload_8209_0):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_8209_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_8209_0)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_4db63bed_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_8209_0)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-cd4879d15cf9b4ab","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_8482_12 = \"defensive\"\n\ndef process_unsafe_deserialization_8482_12(request_8482_12):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_8482_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(request_8482_12)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_8482_12 = \"defensive\"\n\ndef process_unsafe_deserialization_8482_12(request_8482_12):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_8482_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_8482_12.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_cd4879d1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_8482_12)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-f87fa9ef921b5376","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8550_5 = \"defensive\"\n\ndef process_insecure_temp_file_8550_5(subject_8550_5, scope_8550_5):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8550_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_8550_5)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8550_5 = \"defensive\"\n\ndef process_insecure_temp_file_8550_5(subject_8550_5, scope_8550_5):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8550_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_8550_5)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_f87fa9ef_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_8550_5)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-9513ebbc6854c240","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_2201_23 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_2201_23(value_2201_23):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_2201_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(value_2201_23)\n","fixed_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_2201_23 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_2201_23(value_2201_23):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_2201_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(value_2201_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_9513ebbc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyyaml_unsafe_load_2201_23)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-346e586fe8a1fdb6","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1533_12 = \"defensive\"\n\ndef process_csv_formula_injection_1533_12(payload_1533_12):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1533_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_1533_12)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1533_12 = \"defensive\"\n\ndef process_csv_formula_injection_1533_12(payload_1533_12):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1533_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_1533_12)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_346e586f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_1533_12)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-995d8bb2f706684d","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_2901_22 = \"defensive\"\n\ndef load_flask_csrf_validation_2901_22(request_2901_22, scope_2901_22):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_2901_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2901_22.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_2901_22 = \"defensive\"\n\ndef load_flask_csrf_validation_2901_22(request_2901_22, scope_2901_22):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_2901_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_2901_22.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_2901_22.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_2901_22.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_995d8bb2_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_csrf_validation_2901_22)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-60876c48500223cf","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4506_21 = \"defensive\"\n\ndef resolve_flask_session_fixation_4506_21(subject_4506_21, target_4506_21):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4506_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4506_21[\"user_id\"] = target_4506_21.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4506_21 = \"defensive\"\n\ndef resolve_flask_session_fixation_4506_21(subject_4506_21, target_4506_21):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4506_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4506_21.clear()\n subject_4506_21[\"user_id\"] = target_4506_21.id\n subject_4506_21[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_60876c48_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_4506_21)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-1d990fb3243457b1","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_5373_2 = \"defensive\"\n\ndef load_command_injection_5373_2(subject_5373_2, target_5373_2):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_5373_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_5373_2, target_5373_2], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_5373_2 = \"defensive\"\n\ndef load_command_injection_5373_2(subject_5373_2, target_5373_2):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_5373_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_5373_2, target_5373_2], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_1d990fb3_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_command_injection_5373_2)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-81fe317a57795fa2","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_4947_8 = \"defensive\"\n\ndef resolve_flask_jinja_xss_4947_8(value_4947_8):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_4947_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_4947_8)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_4947_8 = \"defensive\"\n\ndef resolve_flask_jinja_xss_4947_8(value_4947_8):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_4947_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_4947_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_81fe317a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_4947_8)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-88280cbfa0fa9712","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4673_4 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_4673_4(request_4673_4):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4673_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_4673_4, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4673_4 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_4673_4(request_4673_4):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4673_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_4673_4)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_88280cbf_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyyaml_unsafe_load_4673_4)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-be30109264d1b9a8","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_1608_17 = \"defensive\"\n\ndef handle_command_injection_1608_17(payload_1608_17, target_1608_17):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_1608_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_1608_17, target_1608_17], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_1608_17 = \"defensive\"\n\ndef handle_command_injection_1608_17(payload_1608_17, target_1608_17):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_1608_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_1608_17, target_1608_17], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_be301092_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_1608_17)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-133dc37f1099aed5","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2349_24 = \"defensive\"\n\ndef load_zip_decompression_bomb_2349_24(value_2349_24, target_2349_24):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2349_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2349_24.extractall(target_2349_24)\n return target_2349_24\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2349_24 = \"defensive\"\n\ndef load_zip_decompression_bomb_2349_24(value_2349_24, target_2349_24):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2349_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_2349_24.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_2349_24.extractall(target_2349_24)\n return target_2349_24\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_133dc37f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_2349_24)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-1134618c56e875fc","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_2949_28 = \"defensive\"\n\ndef process_insecure_random_token_2949_28(request_2949_28):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_2949_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_2949_28)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_2949_28 = \"defensive\"\n\ndef process_insecure_random_token_2949_28(request_2949_28):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_2949_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_2949_28)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_1134618c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_random_token_2949_28)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-9818be6aaaf8c592","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1105_4 = \"defensive\"\n\ndef load_ldap_filter_injection_1105_4(value_1105_4, scope_1105_4):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1105_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={scope_1105_4})\"\n return value_1105_4.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1105_4 = \"defensive\"\n\ndef load_ldap_filter_injection_1105_4(value_1105_4, scope_1105_4):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1105_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_1105_4)\n query = f\"(uid={escaped})\"\n return value_1105_4.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_9818be6a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ldap_filter_injection_1105_4)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-75b3ba51c9d91d87","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5900_19 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_5900_19(value_5900_19, policy_5900_19):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5900_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_5900_19}\")\n return value_5900_19.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5900_19 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_5900_19(value_5900_19, policy_5900_19):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5900_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_5900_19.execute(statement, {\"account_id\": policy_5900_19}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_75b3ba51_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sqlalchemy_text_injection_5900_19)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-9a83474065008fe6","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_5421_4 = \"defensive\"\n\ndef handle_csv_formula_injection_5421_4(payload_5421_4):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_5421_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_5421_4)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_5421_4 = \"defensive\"\n\ndef handle_csv_formula_injection_5421_4(payload_5421_4):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_5421_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_5421_4)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_9a834740_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_5421_4)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-92d62a20c6394f6f","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_9579_28 = \"defensive\"\n\ndef resolve_command_injection_9579_28(value_9579_28, scope_9579_28):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_9579_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {value_9579_28} {scope_9579_28}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_9579_28 = \"defensive\"\n\ndef resolve_command_injection_9579_28(value_9579_28, scope_9579_28):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_9579_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_9579_28, scope_9579_28], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_92d62a20_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_9579_28)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-449acb19eb1a8aad","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5634_23 = \"defensive\"\n\ndef handle_ldap_filter_injection_5634_23(value_5634_23, scope_5634_23):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5634_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_5634_23)\n query = f\"(uid={escaped})\"\n return value_5634_23.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5634_23 = \"defensive\"\n\ndef handle_ldap_filter_injection_5634_23(value_5634_23, scope_5634_23):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5634_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_5634_23)\n query = f\"(uid={escaped})\"\n return value_5634_23.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_449acb19_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_5634_23)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-fb7f8e671228ab13","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_9238_2 = \"defensive\"\n\ndef resolve_mass_assignment_9238_2(subject_9238_2, target_9238_2):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_9238_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_9238_2.items() if key in allowed_fields}\n subject_9238_2.update(safe)\n return subject_9238_2\n","fixed_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_9238_2 = \"defensive\"\n\ndef resolve_mass_assignment_9238_2(subject_9238_2, target_9238_2):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_9238_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_9238_2.items() if key in allowed_fields}\n subject_9238_2.update(safe)\n return subject_9238_2\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_fb7f8e67_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_mass_assignment_9238_2)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-5c68e48a345f091b","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_4864_6 = \"defensive\"\n\ndef process_missing_authorization_4864_6(value_4864_6, context_4864_6):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_4864_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_4864_6.delete()\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_4864_6 = \"defensive\"\n\ndef process_missing_authorization_4864_6(value_4864_6, context_4864_6):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_4864_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_4864_6.id != context_4864_6.owner_id:\n raise PermissionError(\"record ownership required\")\n context_4864_6.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_5c68e48a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_missing_authorization_4864_6)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a091cbb0f6537a31","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_9347_27 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_9347_27(payload_9347_27, policy_9347_27):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_9347_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_9347_27}\")\n return payload_9347_27.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_9347_27 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_9347_27(payload_9347_27, policy_9347_27):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_9347_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_9347_27.execute(statement, {\"account_id\": policy_9347_27}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_a091cbb0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_9347_27)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-46e73095b3e0a0f1","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_3950_3 = \"defensive\"\n\ndef process_insecure_random_token_3950_3(value_3950_3):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_3950_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(value_3950_3)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_3950_3 = \"defensive\"\n\ndef process_insecure_random_token_3950_3(value_3950_3):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_3950_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_3950_3)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_46e73095_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_random_token_3950_3)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-063bd0c8c60b6b54","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_7398_15 = \"defensive\"\n\ndef apply_regex_dos_7398_15(value_7398_15, policy_7398_15):\n if HANDLER_KIND_APPLY_REGEX_DOS_7398_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(value_7398_15, policy_7398_15) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_7398_15 = \"defensive\"\n\ndef apply_regex_dos_7398_15(value_7398_15, policy_7398_15):\n if HANDLER_KIND_APPLY_REGEX_DOS_7398_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_7398_15) > 256 or len(policy_7398_15) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_7398_15), policy_7398_15) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_063bd0c8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_regex_dos_7398_15)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-187486d8fa8d8b74","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9185_13 = \"defensive\"\n\ndef load_tarfile_path_traversal_9185_13(request_9185_13, context_9185_13):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9185_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9185_13.extractall(context_9185_13)\n return context_9185_13\n","fixed_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9185_13 = \"defensive\"\n\ndef load_tarfile_path_traversal_9185_13(request_9185_13, context_9185_13):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9185_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9185_13.extractall(context_9185_13, filter=\"data\")\n return context_9185_13\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_187486d8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_tarfile_path_traversal_9185_13)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-30f6cf2f177e464b","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_4541_23 = \"defensive\"\n\ndef load_flask_csrf_validation_4541_23(value_4541_23, scope_4541_23):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_4541_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_4541_23.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_4541_23.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_4541_23.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_4541_23 = \"defensive\"\n\ndef load_flask_csrf_validation_4541_23(value_4541_23, scope_4541_23):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_4541_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_4541_23.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_4541_23.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_4541_23.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_30f6cf2f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_csrf_validation_4541_23)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-c51d096d4c0f48fc","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_4304_29 = \"defensive\"\n\ndef load_zip_decompression_bomb_4304_29(request_4304_29, target_4304_29):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_4304_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_4304_29.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_4304_29.extractall(target_4304_29)\n return target_4304_29\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_4304_29 = \"defensive\"\n\ndef load_zip_decompression_bomb_4304_29(request_4304_29, target_4304_29):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_4304_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_4304_29.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_4304_29.extractall(target_4304_29)\n return target_4304_29\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_c51d096d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_4304_29)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-0ec21b9b234a6278","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_8453_5 = \"defensive\"\n\ndef handle_ssrf_8453_5(value_8453_5, target_8453_5):\n if HANDLER_KIND_HANDLE_SSRF_8453_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_8453_5)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_8453_5):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_8453_5, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_8453_5 = \"defensive\"\n\ndef handle_ssrf_8453_5(value_8453_5, target_8453_5):\n if HANDLER_KIND_HANDLE_SSRF_8453_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_8453_5)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_8453_5):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_8453_5, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_0ec21b9b_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_8453_5)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-7c87341efdce59d2","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_6860_4 = \"defensive\"\n\ndef load_fastapi_missing_authentication_6860_4(payload_6860_4, target_6860_4):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_6860_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return target_6860_4.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_6860_4 = \"defensive\"\n\ndef load_fastapi_missing_authentication_6860_4(payload_6860_4, target_6860_4):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_6860_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_6860_4 is None or not payload_6860_4.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_6860_4.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_7c87341e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_6860_4)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-9085741fe3b26816","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_3756_2 = \"defensive\"\n\ndef load_path_traversal_3756_2(request_3756_2, policy_3756_2):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_3756_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_3756_2).resolve()\n candidate = (root / policy_3756_2).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_3756_2 = \"defensive\"\n\ndef load_path_traversal_3756_2(request_3756_2, policy_3756_2):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_3756_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_3756_2).resolve()\n candidate = (root / policy_3756_2).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_9085741f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_path_traversal_3756_2)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-0d8996a620e3e4f9","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8557_10 = \"defensive\"\n\ndef apply_missing_authorization_8557_10(request_8557_10, target_8557_10):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8557_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n target_8557_10.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8557_10 = \"defensive\"\n\ndef apply_missing_authorization_8557_10(request_8557_10, target_8557_10):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8557_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_8557_10.id != target_8557_10.owner_id:\n raise PermissionError(\"record ownership required\")\n target_8557_10.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_0d8996a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_8557_10)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-a3d1ecdcfe0ca59d","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2422_7 = \"defensive\"\n\ndef load_plaintext_password_storage_2422_7(payload_2422_7, scope_2422_7, allowed_2422_7):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2422_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_2422_7).write_text(scope_2422_7, encoding=\"utf-8\")\n return Path(payload_2422_7)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2422_7 = \"defensive\"\n\ndef load_plaintext_password_storage_2422_7(payload_2422_7, scope_2422_7, allowed_2422_7):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2422_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_2422_7) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_2422_7.encode(\"utf-8\"), allowed_2422_7, 240_000).hex()\n Path(payload_2422_7).write_text(verifier, encoding=\"ascii\")\n return Path(payload_2422_7)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_a3d1ecdc_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_2422_7)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-8f37bdd6e642ba63","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2842_7 = \"defensive\"\n\ndef process_flask_session_fixation_2842_7(request_2842_7, context_2842_7):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2842_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2842_7[\"user_id\"] = context_2842_7.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2842_7 = \"defensive\"\n\ndef process_flask_session_fixation_2842_7(request_2842_7, context_2842_7):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2842_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2842_7.clear()\n request_2842_7[\"user_id\"] = context_2842_7.id\n request_2842_7[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_8f37bdd6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_2842_7)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-21cfd71c09f55b7c","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_9059_2 = \"defensive\"\n\ndef apply_flask_jinja_xss_9059_2(request_9059_2):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_9059_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_9059_2)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_9059_2 = \"defensive\"\n\ndef apply_flask_jinja_xss_9059_2(request_9059_2):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_9059_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_9059_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_21cfd71c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_9059_2)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-fc0b0f3bb7f7edfc","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_3112_5 = \"defensive\"\n\ndef process_cleartext_http_transport_3112_5(subject_3112_5):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_3112_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_3112_5, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_3112_5 = \"defensive\"\n\ndef process_cleartext_http_transport_3112_5(subject_3112_5):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_3112_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_3112_5, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_fc0b0f3b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_cleartext_http_transport_3112_5)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-0ae9abd1c98f2521","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_8086_24 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_8086_24(subject_8086_24, target_8086_24, limit_8086_24):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_8086_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_8086_24, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_8086_24 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_8086_24(subject_8086_24, target_8086_24, limit_8086_24):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_8086_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_8086_24, target_8086_24, algorithms=[\"HS256\"], audience=limit_8086_24)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_0ae9abd1_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_8086_24)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-a2a90fcdb50217d7","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_8008_22 = \"defensive\"\n\ndef load_fastapi_missing_authentication_8008_22(payload_8008_22, context_8008_22):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_8008_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_8008_22.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_8008_22 = \"defensive\"\n\ndef load_fastapi_missing_authentication_8008_22(payload_8008_22, context_8008_22):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_8008_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_8008_22 is None or not payload_8008_22.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_8008_22.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_a2a90fcd_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_8008_22)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-477d15a91e03526a","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_2703_20 = \"defensive\"\n\ndef load_weak_cryptography_2703_20(payload_2703_20, scope_2703_20):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_2703_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_2703_20.encode(\"utf-8\"), scope_2703_20, 200000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_2703_20 = \"defensive\"\n\ndef load_weak_cryptography_2703_20(payload_2703_20, scope_2703_20):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_2703_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_2703_20.encode(\"utf-8\"), scope_2703_20, 200000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_477d15a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_2703_20)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-7ecf4f7665b31647","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4939_14 = \"defensive\"\n\ndef handle_insecure_random_token_4939_14(request_4939_14):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4939_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_4939_14)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4939_14 = \"defensive\"\n\ndef handle_insecure_random_token_4939_14(request_4939_14):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4939_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_4939_14)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_7ecf4f76_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_random_token_4939_14)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-02e270f015d026d0","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_6595_7 = \"defensive\"\n\ndef apply_dynamic_code_injection_6595_7(subject_6595_7):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_6595_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_6595_7, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_6595_7 = \"defensive\"\n\ndef apply_dynamic_code_injection_6595_7(subject_6595_7):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_6595_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_6595_7) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_6595_7)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_02e270f0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_6595_7)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-d24f5e6984da4eff","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_4026_22 = \"defensive\"\n\ndef resolve_command_injection_4026_22(payload_4026_22, scope_4026_22):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_4026_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_4026_22} {scope_4026_22}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_4026_22 = \"defensive\"\n\ndef resolve_command_injection_4026_22(payload_4026_22, scope_4026_22):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_4026_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_4026_22, scope_4026_22], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_d24f5e69_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_4026_22)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-c06e5fd30ee037eb","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8611_6 = \"defensive\"\n\ndef apply_insecure_random_token_8611_6(request_8611_6):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8611_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_8611_6)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8611_6 = \"defensive\"\n\ndef apply_insecure_random_token_8611_6(request_8611_6):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8611_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_8611_6)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_c06e5fd3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_8611_6)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-665456e7babc5801","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_4133_6 = \"defensive\"\n\ndef apply_ldap_filter_injection_4133_6(payload_4133_6, scope_4133_6):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_4133_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={scope_4133_6})\"\n return payload_4133_6.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_4133_6 = \"defensive\"\n\ndef apply_ldap_filter_injection_4133_6(payload_4133_6, scope_4133_6):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_4133_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_4133_6)\n query = f\"(uid={escaped})\"\n return payload_4133_6.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_665456e7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ldap_filter_injection_4133_6)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-365571fcfa9ba1ed","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8641_10 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_8641_10(payload_8641_10, target_8641_10, owner_8641_10):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8641_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_8641_10, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8641_10 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_8641_10(payload_8641_10, target_8641_10, owner_8641_10):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_8641_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_8641_10, target_8641_10, algorithms=[\"HS256\"], audience=owner_8641_10)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_365571fc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_8641_10)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-7316ca4304729333","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4292_28 = \"defensive\"\n\ndef process_unsafe_deserialization_4292_28(value_4292_28):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4292_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_4292_28)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4292_28 = \"defensive\"\n\ndef process_unsafe_deserialization_4292_28(value_4292_28):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4292_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_4292_28.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_7316ca43_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_4292_28)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-b46424fe1cef92fd","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3462_29 = \"defensive\"\n\ndef process_lxml_xpath_injection_3462_29(subject_3462_29, target_3462_29):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3462_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3462_29.xpath(\"//user[@name=$account]\", account=target_3462_29)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3462_29 = \"defensive\"\n\ndef process_lxml_xpath_injection_3462_29(subject_3462_29, target_3462_29):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3462_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3462_29.xpath(\"//user[@name=$account]\", account=target_3462_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_b46424fe_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_3462_29)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-05dd35d911cfe655","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2212_21 = \"defensive\"\n\ndef apply_ldap_filter_injection_2212_21(payload_2212_21, target_2212_21):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2212_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={target_2212_21})\"\n return payload_2212_21.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2212_21 = \"defensive\"\n\ndef apply_ldap_filter_injection_2212_21(payload_2212_21, target_2212_21):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_2212_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_2212_21)\n query = f\"(uid={escaped})\"\n return payload_2212_21.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_05dd35d9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ldap_filter_injection_2212_21)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-7c5f66a1e4a9986c","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_5555_19 = \"defensive\"\n\ndef handle_log_injection_5555_19(value_5555_19, target_5555_19):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_5555_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5555_19.warning(\"audit=%s\", target_5555_19)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_5555_19 = \"defensive\"\n\ndef handle_log_injection_5555_19(value_5555_19, target_5555_19):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_5555_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_5555_19).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_5555_19.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_7c5f66a1_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_log_injection_5555_19)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-52a367250ec210ea","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6797_29 = \"defensive\"\n\ndef apply_mass_assignment_6797_29(request_6797_29, target_6797_29):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6797_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_6797_29.items() if key in allowed_fields}\n request_6797_29.update(safe)\n return request_6797_29\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6797_29 = \"defensive\"\n\ndef apply_mass_assignment_6797_29(request_6797_29, target_6797_29):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6797_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_6797_29.items() if key in allowed_fields}\n request_6797_29.update(safe)\n return request_6797_29\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_52a36725_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_6797_29)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-7f46a1e75e1f79d0","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7127_8 = \"defensive\"\n\ndef resolve_insecure_temp_file_7127_8(value_7127_8, context_7127_8):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7127_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_7127_8)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7127_8 = \"defensive\"\n\ndef resolve_insecure_temp_file_7127_8(value_7127_8, context_7127_8):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7127_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_7127_8)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_7f46a1e7_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_7127_8)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-d4ef57a49cd39bc6","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_5496_27 = \"defensive\"\n\ndef process_http_response_splitting_5496_27(payload_5496_27, policy_5496_27):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_5496_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5496_27.headers[\"X-Next\"] = policy_5496_27\n return payload_5496_27\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_5496_27 = \"defensive\"\n\ndef process_http_response_splitting_5496_27(payload_5496_27, policy_5496_27):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_5496_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_5496_27 or \"\\n\" in policy_5496_27:\n raise ValueError(\"invalid header value\")\n payload_5496_27.headers[\"X-Next\"] = policy_5496_27\n return payload_5496_27\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_d4ef57a4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_5496_27)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-6774dfaa9e734c00","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_9062_5 = \"defensive\"\n\ndef process_plaintext_password_storage_9062_5(payload_9062_5, scope_9062_5, owner_9062_5):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_9062_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_9062_5) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_9062_5.encode(\"utf-8\"), owner_9062_5, 240_000).hex()\n Path(payload_9062_5).write_text(verifier, encoding=\"ascii\")\n return Path(payload_9062_5)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_9062_5 = \"defensive\"\n\ndef process_plaintext_password_storage_9062_5(payload_9062_5, scope_9062_5, owner_9062_5):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_9062_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_9062_5) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_9062_5.encode(\"utf-8\"), owner_9062_5, 240_000).hex()\n Path(payload_9062_5).write_text(verifier, encoding=\"ascii\")\n return Path(payload_9062_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_6774dfaa_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_9062_5)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-5fca36b9fe148f3c","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_8404_16 = \"defensive\"\n\ndef apply_zip_decompression_bomb_8404_16(value_8404_16, scope_8404_16):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_8404_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8404_16.extractall(scope_8404_16)\n return scope_8404_16\n","fixed_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_8404_16 = \"defensive\"\n\ndef apply_zip_decompression_bomb_8404_16(value_8404_16, scope_8404_16):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_8404_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_8404_16.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_8404_16.extractall(scope_8404_16)\n return scope_8404_16\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_5fca36b9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_zip_decompression_bomb_8404_16)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-46fc78bcd58f9e50","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_2814_26 = \"defensive\"\n\ndef apply_lxml_xpath_injection_2814_26(payload_2814_26, policy_2814_26):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_2814_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_2814_26.xpath(\"//user[@name=$account]\", account=policy_2814_26)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_2814_26 = \"defensive\"\n\ndef apply_lxml_xpath_injection_2814_26(payload_2814_26, policy_2814_26):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_2814_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_2814_26.xpath(\"//user[@name=$account]\", account=policy_2814_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_46fc78bc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_2814_26)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-7e5051e13db09959","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6697_13 = \"defensive\"\n\ndef load_resource_consumption_6697_13(subject_6697_13, scope_6697_13):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6697_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_6697_13.read(int(scope_6697_13))\n","fixed_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6697_13 = \"defensive\"\n\ndef load_resource_consumption_6697_13(subject_6697_13, scope_6697_13):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6697_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_6697_13), 1), 1_048_576)\n data = subject_6697_13.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_7e5051e1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_resource_consumption_6697_13)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-4f5dd4bb25155463","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7711_3 = \"defensive\"\n\ndef handle_flask_open_redirect_7711_3(request_7711_3):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7711_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(request_7711_3)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7711_3 = \"defensive\"\n\ndef handle_flask_open_redirect_7711_3(request_7711_3):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7711_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_7711_3)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_7711_3)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_4f5dd4bb_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_7711_3)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-c8d7dbf3f6798187","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8253_24 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_8253_24(subject_8253_24, target_8253_24):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8253_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {target_8253_24}\")\n return subject_8253_24.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8253_24 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_8253_24(subject_8253_24, target_8253_24):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8253_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_8253_24.execute(statement, {\"account_id\": target_8253_24}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_c8d7dbf3_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_8253_24)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-321d88d59950fe39","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_5445_29 = \"defensive\"\n\ndef load_requests_tls_verification_5445_29(request_5445_29):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_5445_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_5445_29, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_5445_29 = \"defensive\"\n\ndef load_requests_tls_verification_5445_29(request_5445_29):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_5445_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_5445_29, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_321d88d5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_requests_tls_verification_5445_29)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-6410718d58aefe93","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_5483_25 = \"defensive\"\n\ndef apply_sql_injection_5483_25(value_5483_25, scope_5483_25):\n if HANDLER_KIND_APPLY_SQL_INJECTION_5483_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {scope_5483_25}\"\n return value_5483_25.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_5483_25 = \"defensive\"\n\ndef apply_sql_injection_5483_25(value_5483_25, scope_5483_25):\n if HANDLER_KIND_APPLY_SQL_INJECTION_5483_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5483_25.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (scope_5483_25,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_6410718d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_5483_25)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a712c10d6b5c3e7b","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8848_12 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_8848_12(request_8848_12, context_8848_12):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8848_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_8848_12}\")\n return request_8848_12.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8848_12 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_8848_12(request_8848_12, context_8848_12):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8848_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_8848_12.execute(statement, {\"account_id\": context_8848_12}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_a712c10d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sqlalchemy_text_injection_8848_12)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-ce47bbecbc4e9252","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1858_2 = \"defensive\"\n\ndef apply_missing_authorization_1858_2(request_1858_2, scope_1858_2):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1858_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_1858_2.id != scope_1858_2.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1858_2.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1858_2 = \"defensive\"\n\ndef apply_missing_authorization_1858_2(request_1858_2, scope_1858_2):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1858_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_1858_2.id != scope_1858_2.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1858_2.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_ce47bbec_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_1858_2)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-e361407aa57ae680","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_2251_29 = \"defensive\"\n\ndef process_flask_csrf_validation_2251_29(value_2251_29, target_2251_29):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_2251_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_2251_29.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_2251_29.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_2251_29.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_2251_29 = \"defensive\"\n\ndef process_flask_csrf_validation_2251_29(value_2251_29, target_2251_29):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_2251_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_2251_29.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_2251_29.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_2251_29.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_e361407a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_2251_29)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-17e142eec83eec7c","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_2377_26 = \"defensive\"\n\ndef load_requests_tls_verification_2377_26(value_2377_26):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_2377_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_2377_26, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_2377_26 = \"defensive\"\n\ndef load_requests_tls_verification_2377_26(value_2377_26):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_2377_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_2377_26, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_17e142ee_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_requests_tls_verification_2377_26)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-485ca1db93393ab1","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2463_16 = \"defensive\"\n\ndef load_lxml_external_entity_2463_16(subject_2463_16):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2463_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(subject_2463_16)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2463_16 = \"defensive\"\n\ndef load_lxml_external_entity_2463_16(subject_2463_16):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2463_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_2463_16, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_485ca1db_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_external_entity_2463_16)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-4e22704812a9d6be","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3093_14 = \"defensive\"\n\ndef process_flask_open_redirect_3093_14(subject_3093_14):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3093_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_3093_14)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_3093_14)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3093_14 = \"defensive\"\n\ndef process_flask_open_redirect_3093_14(subject_3093_14):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3093_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_3093_14)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_3093_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_4e227048_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_open_redirect_3093_14)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-5a0c7592644666e1","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8898_4 = \"defensive\"\n\ndef resolve_lxml_external_entity_8898_4(value_8898_4):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8898_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_8898_4)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8898_4 = \"defensive\"\n\ndef resolve_lxml_external_entity_8898_4(value_8898_4):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8898_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_8898_4, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_5a0c7592_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_8898_4)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-1656b2a471d85776","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1058_25 = \"defensive\"\n\ndef load_django_error_details_1058_25(subject_1058_25, target_1058_25):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1058_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_1058_25()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1058_25 = \"defensive\"\n\ndef load_django_error_details_1058_25(subject_1058_25, target_1058_25):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1058_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_1058_25()\n except Exception:\n subject_1058_25.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_1656b2a4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_1058_25)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-6c9af858f4616d83","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_7305_18 = \"defensive\"\n\ndef handle_lxml_external_entity_7305_18(value_7305_18):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_7305_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_7305_18)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_7305_18 = \"defensive\"\n\ndef handle_lxml_external_entity_7305_18(value_7305_18):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_7305_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_7305_18, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_6c9af858_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_7305_18)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-295771c6c730fd51","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_5773_4 = \"defensive\"\n\ndef load_resource_consumption_5773_4(value_5773_4, scope_5773_4):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_5773_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5773_4.read(int(scope_5773_4))\n","fixed_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_5773_4 = \"defensive\"\n\ndef load_resource_consumption_5773_4(value_5773_4, scope_5773_4):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_5773_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_5773_4), 1), 1_048_576)\n data = value_5773_4.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_295771c6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_resource_consumption_5773_4)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-1b48babc6d6a5979","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_2320_2 = \"defensive\"\n\ndef handle_zip_decompression_bomb_2320_2(request_2320_2, target_2320_2):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_2320_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_2320_2.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_2320_2.extractall(target_2320_2)\n return target_2320_2\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_2320_2 = \"defensive\"\n\ndef handle_zip_decompression_bomb_2320_2(request_2320_2, target_2320_2):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_2320_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_2320_2.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_2320_2.extractall(target_2320_2)\n return target_2320_2\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_1b48babc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_2320_2)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-2834769f34b92652","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4699_19 = \"defensive\"\n\ndef load_insecure_file_permissions_4699_19(request_4699_19, target_4699_19):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4699_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_4699_19).write_text(target_4699_19, encoding=\"utf-8\")\n os.chmod(request_4699_19, 0o777)\n return Path(request_4699_19)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4699_19 = \"defensive\"\n\ndef load_insecure_file_permissions_4699_19(request_4699_19, target_4699_19):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_4699_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_4699_19).write_text(target_4699_19, encoding=\"utf-8\")\n os.chmod(request_4699_19, 0o600)\n return Path(request_4699_19)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_2834769f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_4699_19)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-f040266d92f3102e","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6634_20 = \"defensive\"\n\ndef process_zip_decompression_bomb_6634_20(value_6634_20, scope_6634_20):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6634_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_6634_20.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_6634_20.extractall(scope_6634_20)\n return scope_6634_20\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6634_20 = \"defensive\"\n\ndef process_zip_decompression_bomb_6634_20(value_6634_20, scope_6634_20):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6634_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_6634_20.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_6634_20.extractall(scope_6634_20)\n return scope_6634_20\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_f040266d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_6634_20)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-3e31c1a586520dc6","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3487_6 = \"defensive\"\n\ndef load_fastapi_missing_authentication_3487_6(request_3487_6, policy_3487_6):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3487_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return policy_3487_6.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3487_6 = \"defensive\"\n\ndef load_fastapi_missing_authentication_3487_6(request_3487_6, policy_3487_6):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3487_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_3487_6 is None or not request_3487_6.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_3487_6.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_3e31c1a5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_3487_6)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-2b2a5fdf48c156c9","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_4486_4 = \"defensive\"\n\ndef resolve_http_response_splitting_4486_4(payload_4486_4, policy_4486_4):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_4486_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4486_4.headers[\"X-Next\"] = policy_4486_4\n return payload_4486_4\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_4486_4 = \"defensive\"\n\ndef resolve_http_response_splitting_4486_4(payload_4486_4, policy_4486_4):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_4486_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_4486_4 or \"\\n\" in policy_4486_4:\n raise ValueError(\"invalid header value\")\n payload_4486_4.headers[\"X-Next\"] = policy_4486_4\n return payload_4486_4\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_2b2a5fdf_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_4486_4)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-cb8b60b4489d7bce","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5109_18 = \"defensive\"\n\ndef resolve_http_response_splitting_5109_18(subject_5109_18, target_5109_18):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5109_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5109_18.headers[\"X-Next\"] = target_5109_18\n return subject_5109_18\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5109_18 = \"defensive\"\n\ndef resolve_http_response_splitting_5109_18(subject_5109_18, target_5109_18):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5109_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_5109_18 or \"\\n\" in target_5109_18:\n raise ValueError(\"invalid header value\")\n subject_5109_18.headers[\"X-Next\"] = target_5109_18\n return subject_5109_18\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_cb8b60b4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_5109_18)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-e54f3c3d95aa12f2","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8787_13 = \"defensive\"\n\ndef apply_missing_authorization_8787_13(request_8787_13, target_8787_13):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8787_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n target_8787_13.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8787_13 = \"defensive\"\n\ndef apply_missing_authorization_8787_13(request_8787_13, target_8787_13):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8787_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_8787_13.id != target_8787_13.owner_id:\n raise PermissionError(\"record ownership required\")\n target_8787_13.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_e54f3c3d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_8787_13)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-22796659e911966e","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_SSRF_8279_25 = \"defensive\"\n\ndef process_ssrf_8279_25(subject_8279_25, target_8279_25):\n if HANDLER_KIND_PROCESS_SSRF_8279_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_8279_25, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_8279_25 = \"defensive\"\n\ndef process_ssrf_8279_25(subject_8279_25, target_8279_25):\n if HANDLER_KIND_PROCESS_SSRF_8279_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_8279_25)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_8279_25):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_8279_25, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_22796659_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ssrf_8279_25)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-3184f10e0dcd3fc7","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6000_0 = \"defensive\"\n\ndef handle_mass_assignment_6000_0(request_6000_0, target_6000_0):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6000_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in target_6000_0.items():\n setattr(request_6000_0, key, value)\n return request_6000_0\n","fixed_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6000_0 = \"defensive\"\n\ndef handle_mass_assignment_6000_0(request_6000_0, target_6000_0):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_6000_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_6000_0.items() if key in allowed_fields}\n request_6000_0.update(safe)\n return request_6000_0\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_3184f10e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_mass_assignment_6000_0)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-6c773919f90b0c40","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5899_14 = \"defensive\"\n\ndef resolve_weak_cryptography_5899_14(value_5899_14, scope_5899_14):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5899_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_5899_14.encode(\"utf-8\"), scope_5899_14, 240000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5899_14 = \"defensive\"\n\ndef resolve_weak_cryptography_5899_14(value_5899_14, scope_5899_14):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5899_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_5899_14.encode(\"utf-8\"), scope_5899_14, 240000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_6c773919_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_5899_14)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-04bca3afb855cf28","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_9159_23 = \"defensive\"\n\ndef process_fastapi_upload_validation_9159_23(payload_9159_23):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_9159_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_9159_23.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_9159_23.size is None or payload_9159_23.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_9159_23.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_9159_23 = \"defensive\"\n\ndef process_fastapi_upload_validation_9159_23(payload_9159_23):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_9159_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_9159_23.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_9159_23.size is None or payload_9159_23.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_9159_23.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_04bca3af_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_9159_23)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-41eb35c4e8d36e33","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_1761_9 = \"defensive\"\n\ndef process_zip_decompression_bomb_1761_9(request_1761_9, context_1761_9):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_1761_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1761_9.extractall(context_1761_9)\n return context_1761_9\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_1761_9 = \"defensive\"\n\ndef process_zip_decompression_bomb_1761_9(request_1761_9, context_1761_9):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_1761_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_1761_9.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_1761_9.extractall(context_1761_9)\n return context_1761_9\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_41eb35c4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_1761_9)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-54d958ba47a535bd","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_6168_21 = \"defensive\"\n\ndef load_dynamic_code_injection_6168_21(request_6168_21):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_6168_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_6168_21, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_6168_21 = \"defensive\"\n\ndef load_dynamic_code_injection_6168_21(request_6168_21):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_6168_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_6168_21) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_6168_21)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_54d958ba_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_dynamic_code_injection_6168_21)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-aeb7bcfe81e92e60","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_2592_2 = \"defensive\"\n\ndef resolve_hardcoded_credentials_2592_2(request_2592_2):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_2592_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2592_2)}\n","fixed_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_2592_2 = \"defensive\"\n\ndef resolve_hardcoded_credentials_2592_2(request_2592_2):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_2592_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2592_2)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_aeb7bcfe_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_hardcoded_credentials_2592_2)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4c135602f186fa46","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4218_11 = \"defensive\"\n\ndef handle_tarfile_path_traversal_4218_11(request_4218_11, target_4218_11):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4218_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_4218_11.extractall(target_4218_11, filter=\"data\")\n return target_4218_11\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4218_11 = \"defensive\"\n\ndef handle_tarfile_path_traversal_4218_11(request_4218_11, target_4218_11):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4218_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_4218_11.extractall(target_4218_11, filter=\"data\")\n return target_4218_11\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_4c135602_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_4218_11)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-fac3579f89bffb0a","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7530_27 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_7530_27(value_7530_27, target_7530_27):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7530_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{target_7530_27}']\"\n return value_7530_27.xpath(xpath)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7530_27 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_7530_27(value_7530_27, target_7530_27):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7530_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7530_27.xpath(\"//user[@name=$account]\", account=target_7530_27)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_fac3579f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_7530_27)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-dc7fea55f90b357c","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_5024_13 = \"defensive\"\n\ndef handle_sql_injection_5024_13(request_5024_13, target_5024_13):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_5024_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {target_5024_13}\"\n return request_5024_13.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_5024_13 = \"defensive\"\n\ndef handle_sql_injection_5024_13(request_5024_13, target_5024_13):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_5024_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_5024_13.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (target_5024_13,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_dc7fea55_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_5024_13)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-755c2a89b0311ed6","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9293_11 = \"defensive\"\n\ndef process_httpx_client_ssrf_9293_11(subject_9293_11, target_9293_11, limit_9293_11):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9293_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_9293_11)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_9293_11):\n raise ValueError(\"destination is not allowed\")\n return subject_9293_11.get(target_9293_11, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9293_11 = \"defensive\"\n\ndef process_httpx_client_ssrf_9293_11(subject_9293_11, target_9293_11, limit_9293_11):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9293_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_9293_11)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_9293_11):\n raise ValueError(\"destination is not allowed\")\n return subject_9293_11.get(target_9293_11, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_755c2a89_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_9293_11)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-4c2312c093497697","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8298_28 = \"defensive\"\n\ndef resolve_lxml_external_entity_8298_28(request_8298_28):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8298_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(request_8298_28)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8298_28 = \"defensive\"\n\ndef resolve_lxml_external_entity_8298_28(request_8298_28):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_8298_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_8298_28, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_4c2312c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_8298_28)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-e2e1bb239fddb55c","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_6521_7 = \"defensive\"\n\ndef handle_httpx_client_ssrf_6521_7(payload_6521_7, target_6521_7, options_6521_7):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_6521_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_6521_7.get(target_6521_7, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_6521_7 = \"defensive\"\n\ndef handle_httpx_client_ssrf_6521_7(payload_6521_7, target_6521_7, options_6521_7):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_6521_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_6521_7)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_6521_7):\n raise ValueError(\"destination is not allowed\")\n return payload_6521_7.get(target_6521_7, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_e2e1bb23_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_httpx_client_ssrf_6521_7)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-9a68860648374816","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1124_14 = \"defensive\"\n\ndef handle_regex_dos_1124_14(value_1124_14, context_1124_14):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1124_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_1124_14) > 256 or len(context_1124_14) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_1124_14), context_1124_14) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1124_14 = \"defensive\"\n\ndef handle_regex_dos_1124_14(value_1124_14, context_1124_14):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1124_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_1124_14) > 256 or len(context_1124_14) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_1124_14), context_1124_14) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_9a688606_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_1124_14)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-98a14571516cfdfe","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4562_25 = \"defensive\"\n\ndef load_lxml_external_entity_4562_25(payload_4562_25):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4562_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_4562_25)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4562_25 = \"defensive\"\n\ndef load_lxml_external_entity_4562_25(payload_4562_25):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4562_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_4562_25, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_98a14571_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_external_entity_4562_25)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-733585a2caa0276e","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_5784_8 = \"defensive\"\n\ndef process_httpx_client_ssrf_5784_8(payload_5784_8, scope_5784_8, limit_5784_8):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_5784_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_5784_8)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_5784_8):\n raise ValueError(\"destination is not allowed\")\n return payload_5784_8.get(scope_5784_8, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_5784_8 = \"defensive\"\n\ndef process_httpx_client_ssrf_5784_8(payload_5784_8, scope_5784_8, limit_5784_8):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_5784_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_5784_8)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_5784_8):\n raise ValueError(\"destination is not allowed\")\n return payload_5784_8.get(scope_5784_8, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_733585a2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_5784_8)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-91de8f9171eaa271","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1687_6 = \"defensive\"\n\ndef process_django_error_details_1687_6(value_1687_6, context_1687_6):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1687_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_1687_6()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1687_6 = \"defensive\"\n\ndef process_django_error_details_1687_6(value_1687_6, context_1687_6):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1687_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_1687_6()\n except Exception:\n value_1687_6.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_91de8f91_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_error_details_1687_6)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-51971113d6644235","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3891_13 = \"defensive\"\n\ndef handle_flask_open_redirect_3891_13(value_3891_13):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3891_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_3891_13)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3891_13 = \"defensive\"\n\ndef handle_flask_open_redirect_3891_13(value_3891_13):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3891_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_3891_13)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_3891_13)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_51971113_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_3891_13)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-4c482e91a946b99e","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_5066_10 = \"defensive\"\n\ndef handle_cleartext_http_transport_5066_10(payload_5066_10):\n if HANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_5066_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_5066_10, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_5066_10 = \"defensive\"\n\ndef handle_cleartext_http_transport_5066_10(payload_5066_10):\n if HANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_5066_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_5066_10, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_4c482e91_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_cleartext_http_transport_5066_10)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-ab933277c55206bb","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_1369_23 = \"defensive\"\n\ndef process_flask_jinja_xss_1369_23(request_1369_23):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_1369_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_1369_23)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_1369_23 = \"defensive\"\n\ndef process_flask_jinja_xss_1369_23(request_1369_23):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_1369_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_1369_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_ab933277_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_1369_23)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-b1ef20cc23409c68","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_6419_14 = \"defensive\"\n\ndef load_ldap_filter_injection_6419_14(request_6419_14, scope_6419_14):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_6419_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_6419_14)\n query = f\"(uid={escaped})\"\n return request_6419_14.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_6419_14 = \"defensive\"\n\ndef load_ldap_filter_injection_6419_14(request_6419_14, scope_6419_14):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_6419_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_6419_14)\n query = f\"(uid={escaped})\"\n return request_6419_14.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_b1ef20cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ldap_filter_injection_6419_14)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-acc390480b9eedef","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6103_8 = \"defensive\"\n\ndef process_zip_decompression_bomb_6103_8(subject_6103_8, target_6103_8):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6103_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_6103_8.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_6103_8.extractall(target_6103_8)\n return target_6103_8\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6103_8 = \"defensive\"\n\ndef process_zip_decompression_bomb_6103_8(subject_6103_8, target_6103_8):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_6103_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_6103_8.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_6103_8.extractall(target_6103_8)\n return target_6103_8\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_acc39048_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_6103_8)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-3a682cace5747cf7","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_5655_12 = \"defensive\"\n\ndef apply_dynamic_code_injection_5655_12(request_5655_12):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_5655_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_5655_12, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_5655_12 = \"defensive\"\n\ndef apply_dynamic_code_injection_5655_12(request_5655_12):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_5655_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_5655_12) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_5655_12)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_3a682cac_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_5655_12)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-82bf857ca27bdbc4","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_3111_13 = \"defensive\"\n\ndef resolve_unsafe_deserialization_3111_13(value_3111_13):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_3111_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_3111_13)\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_3111_13 = \"defensive\"\n\ndef resolve_unsafe_deserialization_3111_13(value_3111_13):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_3111_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_3111_13.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_82bf857c_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_3111_13)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-7f214c9f13f4dba8","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7720_18 = \"defensive\"\n\ndef resolve_insecure_temp_file_7720_18(payload_7720_18, scope_7720_18):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7720_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_7720_18}.txt\")\n path.write_text(scope_7720_18, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7720_18 = \"defensive\"\n\ndef resolve_insecure_temp_file_7720_18(payload_7720_18, scope_7720_18):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7720_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_7720_18)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_7f214c9f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_7720_18)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-5d2dadd07465ec86","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_2717_27 = \"defensive\"\n\ndef apply_regex_dos_2717_27(value_2717_27, context_2717_27):\n if HANDLER_KIND_APPLY_REGEX_DOS_2717_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(value_2717_27, context_2717_27) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_2717_27 = \"defensive\"\n\ndef apply_regex_dos_2717_27(value_2717_27, context_2717_27):\n if HANDLER_KIND_APPLY_REGEX_DOS_2717_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_2717_27) > 256 or len(context_2717_27) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_2717_27), context_2717_27) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_5d2dadd0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_regex_dos_2717_27)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-b2416f9923297fe6","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_7059_21 = \"defensive\"\n\ndef handle_django_error_details_7059_21(request_7059_21, context_7059_21):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_7059_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_7059_21()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_7059_21 = \"defensive\"\n\ndef handle_django_error_details_7059_21(request_7059_21, context_7059_21):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_7059_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_7059_21()\n except Exception:\n request_7059_21.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_b2416f99_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_error_details_7059_21)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-2e57dfb8080a3ccb","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7260_22 = \"defensive\"\n\ndef handle_django_safe_string_xss_7260_22(subject_7260_22):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7260_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{subject_7260_22}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7260_22 = \"defensive\"\n\ndef handle_django_safe_string_xss_7260_22(subject_7260_22):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7260_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_7260_22)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_2e57dfb8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_7260_22)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-ba1cc4388f3594f8","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7388_20 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7388_20(request_7388_20, context_7388_20):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7388_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7388_20.xpath(\"//user[@name=$account]\", account=context_7388_20)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7388_20 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7388_20(request_7388_20, context_7388_20):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7388_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7388_20.xpath(\"//user[@name=$account]\", account=context_7388_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_ba1cc438_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_7388_20)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-d42eb13f0ca24a2c","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9007_17 = \"defensive\"\n\ndef resolve_log_injection_9007_17(subject_9007_17, policy_9007_17):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9007_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_9007_17).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_9007_17.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9007_17 = \"defensive\"\n\ndef resolve_log_injection_9007_17(subject_9007_17, policy_9007_17):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9007_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_9007_17).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_9007_17.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_d42eb13f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_9007_17)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-f41d8afc38590a8a","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_6068_20 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_6068_20(value_6068_20, context_6068_20, allowed_6068_20):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_6068_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_6068_20, context_6068_20, algorithms=[\"HS256\"], audience=allowed_6068_20)\n","fixed_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_6068_20 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_6068_20(value_6068_20, context_6068_20, allowed_6068_20):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_6068_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_6068_20, context_6068_20, algorithms=[\"HS256\"], audience=allowed_6068_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_f41d8afc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyjwt_signature_bypass_6068_20)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-05eb242a0b563551","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_1885_27 = \"defensive\"\n\ndef apply_django_error_details_1885_27(request_1885_27, scope_1885_27):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_1885_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_1885_27()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_1885_27 = \"defensive\"\n\ndef apply_django_error_details_1885_27(request_1885_27, scope_1885_27):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_1885_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_1885_27()\n except Exception:\n request_1885_27.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_05eb242a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_1885_27)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-810854ff6a8e0e78","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_4329_5 = \"defensive\"\n\ndef resolve_lxml_external_entity_4329_5(subject_4329_5):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_4329_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_4329_5, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_4329_5 = \"defensive\"\n\ndef resolve_lxml_external_entity_4329_5(subject_4329_5):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_4329_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_4329_5, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_810854ff_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_4329_5)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-804129abefb9a54b","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2425_7 = \"defensive\"\n\ndef resolve_flask_csrf_validation_2425_7(subject_2425_7, scope_2425_7):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2425_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_2425_7.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2425_7 = \"defensive\"\n\ndef resolve_flask_csrf_validation_2425_7(subject_2425_7, scope_2425_7):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2425_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_2425_7.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_2425_7.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_2425_7.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_804129ab_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_csrf_validation_2425_7)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-24eebc6498247943","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8282_24 = \"defensive\"\n\ndef process_sensitive_data_exposure_8282_24(payload_8282_24, context_8282_24, limit_8282_24):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8282_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8282_24.info(\"login user=%s password=%s\", context_8282_24, limit_8282_24)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8282_24 = \"defensive\"\n\ndef process_sensitive_data_exposure_8282_24(payload_8282_24, context_8282_24, limit_8282_24):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8282_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8282_24.info(\"login user=%s\", context_8282_24)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_24eebc64_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_8282_24)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-2e1723c4820d8b4f","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_5092_16 = \"defensive\"\n\ndef handle_missing_authorization_5092_16(value_5092_16, context_5092_16):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_5092_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_5092_16.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_5092_16 = \"defensive\"\n\ndef handle_missing_authorization_5092_16(value_5092_16, context_5092_16):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_5092_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_5092_16.id != context_5092_16.owner_id:\n raise PermissionError(\"record ownership required\")\n context_5092_16.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_2e1723c4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_5092_16)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-615c7a26ff1766a5","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_2403_26 = \"defensive\"\n\ndef resolve_command_injection_2403_26(subject_2403_26, context_2403_26):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_2403_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_2403_26, context_2403_26], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_2403_26 = \"defensive\"\n\ndef resolve_command_injection_2403_26(subject_2403_26, context_2403_26):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_2403_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_2403_26, context_2403_26], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_615c7a26_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_2403_26)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-133784d9b2aae2a0","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4212_4 = \"defensive\"\n\ndef handle_flask_jinja_xss_4212_4(subject_4212_4):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4212_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(subject_4212_4)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4212_4 = \"defensive\"\n\ndef handle_flask_jinja_xss_4212_4(subject_4212_4):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4212_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(subject_4212_4)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_133784d9_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_jinja_xss_4212_4)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-10c16a317569abbf","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2086_22 = \"defensive\"\n\ndef handle_hardcoded_credentials_2086_22(request_2086_22):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2086_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000022\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2086_22)}\n","fixed_code":"import os\n\nHANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2086_22 = \"defensive\"\n\ndef handle_hardcoded_credentials_2086_22(request_2086_22):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2086_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2086_22)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_10c16a31_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_hardcoded_credentials_2086_22)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-99534ba33f56013b","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_6673_9 = \"defensive\"\n\ndef process_command_injection_6673_9(payload_6673_9, context_6673_9):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_6673_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_6673_9} {context_6673_9}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_6673_9 = \"defensive\"\n\ndef process_command_injection_6673_9(payload_6673_9, context_6673_9):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_6673_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_6673_9, context_6673_9], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_99534ba3_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_6673_9)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-f67242c2c46ca1eb","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8180_9 = \"defensive\"\n\ndef process_insecure_temp_file_8180_9(subject_8180_9, scope_8180_9):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8180_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{subject_8180_9}.txt\")\n path.write_text(scope_8180_9, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8180_9 = \"defensive\"\n\ndef process_insecure_temp_file_8180_9(subject_8180_9, scope_8180_9):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_8180_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_8180_9)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_f67242c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_8180_9)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-378b7cafa3851e3d","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2189_29 = \"defensive\"\n\ndef handle_hardcoded_credentials_2189_29(subject_2189_29):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2189_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_2189_29)}\n","fixed_code":"import os\n\nHANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2189_29 = \"defensive\"\n\ndef handle_hardcoded_credentials_2189_29(subject_2189_29):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_2189_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_2189_29)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_378b7caf_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_hardcoded_credentials_2189_29)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-cbbf6c2f2e536957","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9374_24 = \"defensive\"\n\ndef handle_flask_session_fixation_9374_24(payload_9374_24, scope_9374_24):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9374_24[\"user_id\"] = scope_9374_24.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9374_24 = \"defensive\"\n\ndef handle_flask_session_fixation_9374_24(payload_9374_24, scope_9374_24):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9374_24.clear()\n payload_9374_24[\"user_id\"] = scope_9374_24.id\n payload_9374_24[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_cbbf6c2f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_9374_24)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-6fb42673753becac","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_9432_25 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_9432_25(value_9432_25, target_9432_25):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_9432_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9432_25.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return value_9432_25\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_9432_25 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_9432_25(value_9432_25, target_9432_25):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_9432_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_9432_25)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_9432_25.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_9432_25\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_6fb42673_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_9432_25)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-756c1b9458b4b160","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_4030_17 = \"defensive\"\n\ndef resolve_mass_assignment_4030_17(value_4030_17, policy_4030_17):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_4030_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_4030_17.items() if key in allowed_fields}\n value_4030_17.update(safe)\n return value_4030_17\n","fixed_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_4030_17 = \"defensive\"\n\ndef resolve_mass_assignment_4030_17(value_4030_17, policy_4030_17):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_4030_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_4030_17.items() if key in allowed_fields}\n value_4030_17.update(safe)\n return value_4030_17\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_756c1b94_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_mass_assignment_4030_17)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-574648b80a431cc1","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_7647_18 = \"defensive\"\n\ndef load_weak_cryptography_7647_18(subject_7647_18, scope_7647_18):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_7647_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_7647_18.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_7647_18 = \"defensive\"\n\ndef load_weak_cryptography_7647_18(subject_7647_18, scope_7647_18):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_7647_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_7647_18.encode(\"utf-8\"), scope_7647_18, 230000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_574648b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_7647_18)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-90e8bc9c61eed07c","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5256_24 = \"defensive\"\n\ndef handle_resource_consumption_5256_24(subject_5256_24, target_5256_24):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5256_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_5256_24.read(int(target_5256_24))\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5256_24 = \"defensive\"\n\ndef handle_resource_consumption_5256_24(subject_5256_24, target_5256_24):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5256_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_5256_24), 1), 1_048_576)\n data = subject_5256_24.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_90e8bc9c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_5256_24)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-f172ed07d8dee4cb","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_4563_18 = \"defensive\"\n\ndef load_path_traversal_4563_18(request_4563_18, scope_4563_18):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_4563_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(request_4563_18) / scope_4563_18).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_4563_18 = \"defensive\"\n\ndef load_path_traversal_4563_18(request_4563_18, scope_4563_18):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_4563_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_4563_18).resolve()\n candidate = (root / scope_4563_18).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_f172ed07_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_path_traversal_4563_18)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-b4db0a8f82dc778f","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_6125_28 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_6125_28(subject_6125_28, scope_6125_28):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_6125_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return scope_6125_28.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_6125_28 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_6125_28(subject_6125_28, scope_6125_28):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_6125_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_6125_28 is None or not subject_6125_28.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_6125_28.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_b4db0a8f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_missing_authentication_6125_28)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-5de9b288fd784e15","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_3873_1 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_3873_1(request_3873_1, policy_3873_1, owner_3873_1):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_3873_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_3873_1, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_3873_1 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_3873_1(request_3873_1, policy_3873_1, owner_3873_1):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_3873_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_3873_1, policy_3873_1, algorithms=[\"HS256\"], audience=owner_3873_1)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_5de9b288_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_3873_1)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-5910cbc65fd15a35","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_2367_3 = \"defensive\"\n\ndef resolve_ldap_filter_injection_2367_3(subject_2367_3, scope_2367_3):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_2367_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={scope_2367_3})\"\n return subject_2367_3.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_2367_3 = \"defensive\"\n\ndef resolve_ldap_filter_injection_2367_3(subject_2367_3, scope_2367_3):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_2367_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_2367_3)\n query = f\"(uid={escaped})\"\n return subject_2367_3.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_5910cbc6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_2367_3)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-efdbbdfcec27f246","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_5118_9 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_5118_9(value_5118_9, context_5118_9):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_5118_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{context_5118_9}']\"\n return value_5118_9.xpath(xpath)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_5118_9 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_5118_9(value_5118_9, context_5118_9):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_5118_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5118_9.xpath(\"//user[@name=$account]\", account=context_5118_9)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_efdbbdfc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_5118_9)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-56b5c4a3d9f58a7e","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_1411_21 = \"defensive\"\n\ndef handle_sensitive_data_exposure_1411_21(subject_1411_21, scope_1411_21, options_1411_21):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_1411_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1411_21.info(\"login user=%s password=%s\", scope_1411_21, options_1411_21)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_1411_21 = \"defensive\"\n\ndef handle_sensitive_data_exposure_1411_21(subject_1411_21, scope_1411_21, options_1411_21):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_1411_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1411_21.info(\"login user=%s\", scope_1411_21)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_56b5c4a3_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_1411_21)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-639fe86ffaf2c90e","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2677_8 = \"defensive\"\n\ndef load_plaintext_password_storage_2677_8(request_2677_8, target_2677_8, options_2677_8):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2677_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_2677_8) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_2677_8.encode(\"utf-8\"), options_2677_8, 240_000).hex()\n Path(request_2677_8).write_text(verifier, encoding=\"ascii\")\n return Path(request_2677_8)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2677_8 = \"defensive\"\n\ndef load_plaintext_password_storage_2677_8(request_2677_8, target_2677_8, options_2677_8):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2677_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_2677_8) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_2677_8.encode(\"utf-8\"), options_2677_8, 240_000).hex()\n Path(request_2677_8).write_text(verifier, encoding=\"ascii\")\n return Path(request_2677_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_639fe86f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_2677_8)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-15327084939fdc4f","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_6746_4 = \"defensive\"\n\ndef process_unsafe_deserialization_6746_4(payload_6746_4):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_6746_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(payload_6746_4)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_6746_4 = \"defensive\"\n\ndef process_unsafe_deserialization_6746_4(payload_6746_4):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_6746_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_6746_4.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_15327084_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_6746_4)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-50fcb8b194851674","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1393_0 = \"defensive\"\n\ndef apply_insecure_temp_file_1393_0(value_1393_0, target_1393_0):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1393_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{value_1393_0}.txt\")\n path.write_text(target_1393_0, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1393_0 = \"defensive\"\n\ndef apply_insecure_temp_file_1393_0(value_1393_0, target_1393_0):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1393_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(target_1393_0)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_50fcb8b1_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_1393_0)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-0c00231770c4de98","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_2685_24 = \"defensive\"\n\ndef process_ldap_filter_injection_2685_24(subject_2685_24, target_2685_24):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_2685_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={target_2685_24})\"\n return subject_2685_24.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_2685_24 = \"defensive\"\n\ndef process_ldap_filter_injection_2685_24(subject_2685_24, target_2685_24):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_2685_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_2685_24)\n query = f\"(uid={escaped})\"\n return subject_2685_24.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_0c002317_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ldap_filter_injection_2685_24)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-c43213de044b8667","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7342_14 = \"defensive\"\n\ndef process_flask_csrf_validation_7342_14(payload_7342_14, policy_7342_14):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7342_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_7342_14.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_7342_14.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_7342_14.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7342_14 = \"defensive\"\n\ndef process_flask_csrf_validation_7342_14(payload_7342_14, policy_7342_14):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7342_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_7342_14.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_7342_14.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_7342_14.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_c43213de_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_7342_14)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-0dacd55eef4312e3","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2190_25 = \"defensive\"\n\ndef process_log_injection_2190_25(value_2190_25, scope_2190_25):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2190_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2190_25.warning(\"audit=%s\", scope_2190_25)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2190_25 = \"defensive\"\n\ndef process_log_injection_2190_25(value_2190_25, scope_2190_25):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2190_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_2190_25).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_2190_25.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_0dacd55e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_2190_25)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-fd75f74449face89","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_5855_18 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_5855_18(subject_5855_18):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_5855_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(subject_5855_18, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_5855_18 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_5855_18(subject_5855_18):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_5855_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_5855_18)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_fd75f744_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyyaml_unsafe_load_5855_18)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-ad1560ef40cc4479","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7322_4 = \"defensive\"\n\ndef apply_hardcoded_credentials_7322_4(value_7322_4):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7322_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000004\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_7322_4)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7322_4 = \"defensive\"\n\ndef apply_hardcoded_credentials_7322_4(value_7322_4):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7322_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_7322_4)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_ad1560ef_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_7322_4)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-4e1cef6ec6829606","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_6454_12 = \"defensive\"\n\ndef apply_starlette_permissive_cors_6454_12(subject_6454_12, scope_6454_12):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_6454_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_6454_12.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_6454_12\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_6454_12 = \"defensive\"\n\ndef apply_starlette_permissive_cors_6454_12(subject_6454_12, scope_6454_12):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_6454_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_6454_12)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_6454_12.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_6454_12\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_4e1cef6e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_6454_12)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-88047b7c017a9da8","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5391_24 = \"defensive\"\n\ndef resolve_weak_cryptography_5391_24(subject_5391_24, scope_5391_24):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5391_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_5391_24.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5391_24 = \"defensive\"\n\ndef resolve_weak_cryptography_5391_24(subject_5391_24, scope_5391_24):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_5391_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_5391_24.encode(\"utf-8\"), scope_5391_24, 240000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_88047b7c_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_5391_24)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-229819da719445ca","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_9956_29 = \"defensive\"\n\ndef load_insecure_file_permissions_9956_29(subject_9956_29, policy_9956_29):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_9956_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_9956_29).write_text(policy_9956_29, encoding=\"utf-8\")\n os.chmod(subject_9956_29, 0o600)\n return Path(subject_9956_29)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_9956_29 = \"defensive\"\n\ndef load_insecure_file_permissions_9956_29(subject_9956_29, policy_9956_29):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_9956_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_9956_29).write_text(policy_9956_29, encoding=\"utf-8\")\n os.chmod(subject_9956_29, 0o600)\n return Path(subject_9956_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_229819da_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_9956_29)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-9db6669d22915241","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_2542_24 = \"defensive\"\n\ndef load_regex_dos_2542_24(payload_2542_24, scope_2542_24):\n if HANDLER_KIND_LOAD_REGEX_DOS_2542_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_2542_24, scope_2542_24) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_2542_24 = \"defensive\"\n\ndef load_regex_dos_2542_24(payload_2542_24, scope_2542_24):\n if HANDLER_KIND_LOAD_REGEX_DOS_2542_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_2542_24) > 256 or len(scope_2542_24) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_2542_24), scope_2542_24) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_9db6669d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_regex_dos_2542_24)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-f48e395ffbc13c4f","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3474_1 = \"defensive\"\n\ndef process_weak_cryptography_3474_1(payload_3474_1, scope_3474_1):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3474_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_3474_1.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3474_1 = \"defensive\"\n\ndef process_weak_cryptography_3474_1(payload_3474_1, scope_3474_1):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3474_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_3474_1.encode(\"utf-8\"), scope_3474_1, 210000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_f48e395f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_3474_1)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-87762ae423695497","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_7650_26 = \"defensive\"\n\ndef apply_flask_jinja_xss_7650_26(value_7650_26):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_7650_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_7650_26)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_7650_26 = \"defensive\"\n\ndef apply_flask_jinja_xss_7650_26(value_7650_26):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_7650_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_7650_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_87762ae4_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_7650_26)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-ebc099f4c1055f59","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_7084_2 = \"defensive\"\n\ndef resolve_requests_tls_verification_7084_2(payload_7084_2):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_7084_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_7084_2, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_7084_2 = \"defensive\"\n\ndef resolve_requests_tls_verification_7084_2(payload_7084_2):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_7084_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_7084_2, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_ebc099f4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_requests_tls_verification_7084_2)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-d997f97c7380db3d","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1067_27 = \"defensive\"\n\ndef load_weak_cryptography_1067_27(subject_1067_27, scope_1067_27):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1067_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_1067_27.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1067_27 = \"defensive\"\n\ndef load_weak_cryptography_1067_27(subject_1067_27, scope_1067_27):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1067_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_1067_27.encode(\"utf-8\"), scope_1067_27, 220000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_d997f97c_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_1067_27)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-a5706104dd9d1d50","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3353_25 = \"defensive\"\n\ndef resolve_insecure_temp_file_3353_25(request_3353_25, context_3353_25):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3353_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{request_3353_25}.txt\")\n path.write_text(context_3353_25, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3353_25 = \"defensive\"\n\ndef resolve_insecure_temp_file_3353_25(request_3353_25, context_3353_25):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3353_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3353_25)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_a5706104_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_3353_25)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-19a49b7b88f11833","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3459_12 = \"defensive\"\n\ndef load_weak_cryptography_3459_12(request_3459_12, policy_3459_12):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3459_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(request_3459_12.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3459_12 = \"defensive\"\n\ndef load_weak_cryptography_3459_12(request_3459_12, policy_3459_12):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3459_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", request_3459_12.encode(\"utf-8\"), policy_3459_12, 220000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_19a49b7b_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_3459_12)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-085b2dde370b0515","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_9435_1 = \"defensive\"\n\ndef resolve_unsafe_deserialization_9435_1(request_9435_1):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_9435_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(request_9435_1)\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_9435_1 = \"defensive\"\n\ndef resolve_unsafe_deserialization_9435_1(request_9435_1):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_9435_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_9435_1.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_085b2dde_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_9435_1)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-6fd6b20973d25edc","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4522_29 = \"defensive\"\n\ndef handle_django_safe_string_xss_4522_29(subject_4522_29):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4522_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_4522_29)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4522_29 = \"defensive\"\n\ndef handle_django_safe_string_xss_4522_29(subject_4522_29):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4522_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_4522_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_6fd6b209_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_4522_29)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-57b2c4946c7cc739","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_7565_4 = \"defensive\"\n\ndef apply_sensitive_data_exposure_7565_4(subject_7565_4, policy_7565_4, allowed_7565_4):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_7565_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7565_4.info(\"login user=%s password=%s\", policy_7565_4, allowed_7565_4)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_7565_4 = \"defensive\"\n\ndef apply_sensitive_data_exposure_7565_4(subject_7565_4, policy_7565_4, allowed_7565_4):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_7565_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7565_4.info(\"login user=%s\", policy_7565_4)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_57b2c494_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sensitive_data_exposure_7565_4)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-47b38fe112b693c5","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4524_23 = \"defensive\"\n\ndef resolve_flask_session_fixation_4524_23(subject_4524_23, context_4524_23):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4524_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4524_23.clear()\n subject_4524_23[\"user_id\"] = context_4524_23.id\n subject_4524_23[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4524_23 = \"defensive\"\n\ndef resolve_flask_session_fixation_4524_23(subject_4524_23, context_4524_23):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_4524_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4524_23.clear()\n subject_4524_23[\"user_id\"] = context_4524_23.id\n subject_4524_23[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_47b38fe1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_4524_23)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-d92e5025eb2d2112","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5263_7 = \"defensive\"\n\ndef process_log_injection_5263_7(value_5263_7, scope_5263_7):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5263_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5263_7.warning(\"audit=%s\", scope_5263_7)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5263_7 = \"defensive\"\n\ndef process_log_injection_5263_7(value_5263_7, scope_5263_7):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5263_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_5263_7).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_5263_7.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_d92e5025_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_5263_7)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-63d507e74d2c9aec","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1904_26 = \"defensive\"\n\ndef load_ldap_filter_injection_1904_26(subject_1904_26, scope_1904_26):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1904_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_1904_26)\n query = f\"(uid={escaped})\"\n return subject_1904_26.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1904_26 = \"defensive\"\n\ndef load_ldap_filter_injection_1904_26(subject_1904_26, scope_1904_26):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_1904_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_1904_26)\n query = f\"(uid={escaped})\"\n return subject_1904_26.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_63d507e7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ldap_filter_injection_1904_26)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-2fe89455a595e1da","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_1601_11 = \"defensive\"\n\ndef apply_http_response_splitting_1601_11(request_1601_11, policy_1601_11):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_1601_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_1601_11 or \"\\n\" in policy_1601_11:\n raise ValueError(\"invalid header value\")\n request_1601_11.headers[\"X-Next\"] = policy_1601_11\n return request_1601_11\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_1601_11 = \"defensive\"\n\ndef apply_http_response_splitting_1601_11(request_1601_11, policy_1601_11):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_1601_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_1601_11 or \"\\n\" in policy_1601_11:\n raise ValueError(\"invalid header value\")\n request_1601_11.headers[\"X-Next\"] = policy_1601_11\n return request_1601_11\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_2fe89455_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_1601_11)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-6e7ada3cd55b62f3","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3629_28 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3629_28(value_3629_28, scope_3629_28):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3629_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_3629_28}']\"\n return value_3629_28.xpath(xpath)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3629_28 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3629_28(value_3629_28, scope_3629_28):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3629_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_3629_28.xpath(\"//user[@name=$account]\", account=scope_3629_28)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_6e7ada3c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_3629_28)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-c75b49fad239edf0","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8382_27 = \"defensive\"\n\ndef handle_path_traversal_8382_27(payload_8382_27, target_8382_27):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8382_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_8382_27) / target_8382_27).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8382_27 = \"defensive\"\n\ndef handle_path_traversal_8382_27(payload_8382_27, target_8382_27):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8382_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_8382_27).resolve()\n candidate = (root / target_8382_27).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_c75b49fa_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_8382_27)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-acf0537dc172a642","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_5733_13 = \"defensive\"\n\ndef load_django_error_details_5733_13(payload_5733_13, scope_5733_13):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_5733_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_5733_13()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_5733_13 = \"defensive\"\n\ndef load_django_error_details_5733_13(payload_5733_13, scope_5733_13):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_5733_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_5733_13()\n except Exception:\n payload_5733_13.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_acf0537d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_5733_13)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-fbdb1a0afbd57aa4","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6809_16 = \"defensive\"\n\ndef apply_django_error_details_6809_16(value_6809_16, scope_6809_16):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6809_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_6809_16()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6809_16 = \"defensive\"\n\ndef apply_django_error_details_6809_16(value_6809_16, scope_6809_16):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6809_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_6809_16()\n except Exception:\n value_6809_16.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_fbdb1a0a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_6809_16)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-183aa639a2e161e5","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_8955_29 = \"defensive\"\n\ndef handle_ldap_filter_injection_8955_29(payload_8955_29, context_8955_29):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_8955_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_8955_29)\n query = f\"(uid={escaped})\"\n return payload_8955_29.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_8955_29 = \"defensive\"\n\ndef handle_ldap_filter_injection_8955_29(payload_8955_29, context_8955_29):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_8955_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_8955_29)\n query = f\"(uid={escaped})\"\n return payload_8955_29.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_183aa639_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_8955_29)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-697e8b3ac33d4a78","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_6311_29 = \"defensive\"\n\ndef process_weak_cryptography_6311_29(value_6311_29, context_6311_29):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_6311_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_6311_29.encode(\"utf-8\"), context_6311_29, 240000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_6311_29 = \"defensive\"\n\ndef process_weak_cryptography_6311_29(value_6311_29, context_6311_29):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_6311_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_6311_29.encode(\"utf-8\"), context_6311_29, 240000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_697e8b3a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_6311_29)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-48b4fe4e882c2349","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_6678_29 = \"defensive\"\n\ndef process_resource_consumption_6678_29(payload_6678_29, policy_6678_29):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_6678_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_6678_29), 1), 1_048_576)\n data = payload_6678_29.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_6678_29 = \"defensive\"\n\ndef process_resource_consumption_6678_29(payload_6678_29, policy_6678_29):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_6678_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_6678_29), 1), 1_048_576)\n data = payload_6678_29.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_48b4fe4e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_resource_consumption_6678_29)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-898a1325fcd8c814","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1234_2 = \"defensive\"\n\ndef load_insecure_file_permissions_1234_2(request_1234_2, target_1234_2):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1234_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1234_2).write_text(target_1234_2, encoding=\"utf-8\")\n os.chmod(request_1234_2, 0o600)\n return Path(request_1234_2)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1234_2 = \"defensive\"\n\ndef load_insecure_file_permissions_1234_2(request_1234_2, target_1234_2):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1234_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1234_2).write_text(target_1234_2, encoding=\"utf-8\")\n os.chmod(request_1234_2, 0o600)\n return Path(request_1234_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_898a1325_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_1234_2)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-ebd7d02a1277ba0b","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_5567_25 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_5567_25(subject_5567_25):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_5567_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_5567_25.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_5567_25 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_5567_25(subject_5567_25):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_5567_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_5567_25.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_5567_25.size is None or subject_5567_25.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_5567_25.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_ebd7d02a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_5567_25)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-85fe568201350f6a","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_6867_2 = \"defensive\"\n\ndef handle_flask_session_fixation_6867_2(subject_6867_2, scope_6867_2):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_6867_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_6867_2.clear()\n subject_6867_2[\"user_id\"] = scope_6867_2.id\n subject_6867_2[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_6867_2 = \"defensive\"\n\ndef handle_flask_session_fixation_6867_2(subject_6867_2, scope_6867_2):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_6867_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_6867_2.clear()\n subject_6867_2[\"user_id\"] = scope_6867_2.id\n subject_6867_2[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_85fe5682_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_6867_2)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-83d81959de3a4d67","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4186_21 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_4186_21(request_4186_21, scope_4186_21):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4186_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {scope_4186_21}\")\n return request_4186_21.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4186_21 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_4186_21(request_4186_21, scope_4186_21):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4186_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_4186_21.execute(statement, {\"account_id\": scope_4186_21}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_83d81959_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_4186_21)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-ac86fa37b5ae775a","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3502_22 = \"defensive\"\n\ndef resolve_csv_formula_injection_3502_22(value_3502_22):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3502_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_3502_22)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3502_22 = \"defensive\"\n\ndef resolve_csv_formula_injection_3502_22(value_3502_22):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3502_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_3502_22)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_ac86fa37_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_3502_22)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-502162e886a87379","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_5629_0 = \"defensive\"\n\ndef handle_command_injection_5629_0(subject_5629_0, policy_5629_0):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_5629_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_5629_0} {policy_5629_0}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_5629_0 = \"defensive\"\n\ndef handle_command_injection_5629_0(subject_5629_0, policy_5629_0):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_5629_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_5629_0, policy_5629_0], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_502162e8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_5629_0)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-9a4a4b52a7f2e04a","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9112_17 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_9112_17(request_9112_17):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9112_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9112_17)\n","fixed_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9112_17 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_9112_17(request_9112_17):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9112_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9112_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_9a4a4b52_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyyaml_unsafe_load_9112_17)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-e9fb3c2165d2e5f4","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_6993_0 = \"defensive\"\n\ndef process_flask_jinja_xss_6993_0(subject_6993_0):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_6993_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(subject_6993_0)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_6993_0 = \"defensive\"\n\ndef process_flask_jinja_xss_6993_0(subject_6993_0):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_6993_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(subject_6993_0)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_e9fb3c21_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_6993_0)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-4196c7c273025fcd","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_1358_7 = \"defensive\"\n\ndef handle_django_safe_string_xss_1358_7(payload_1358_7):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_1358_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_1358_7}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_1358_7 = \"defensive\"\n\ndef handle_django_safe_string_xss_1358_7(payload_1358_7):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_1358_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_1358_7)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_4196c7c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_1358_7)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-cd127177d355246b","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_3633_13 = \"defensive\"\n\ndef process_regex_dos_3633_13(payload_3633_13, context_3633_13):\n if HANDLER_KIND_PROCESS_REGEX_DOS_3633_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_3633_13, context_3633_13) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_3633_13 = \"defensive\"\n\ndef process_regex_dos_3633_13(payload_3633_13, context_3633_13):\n if HANDLER_KIND_PROCESS_REGEX_DOS_3633_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_3633_13) > 256 or len(context_3633_13) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_3633_13), context_3633_13) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_cd127177_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_3633_13)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-e90e1f39ce446b83","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5696_29 = \"defensive\"\n\ndef handle_dynamic_code_injection_5696_29(subject_5696_29):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5696_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5696_29) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_5696_29)\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5696_29 = \"defensive\"\n\ndef handle_dynamic_code_injection_5696_29(subject_5696_29):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5696_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5696_29) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_5696_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_e90e1f39_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_5696_29)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-f6b40e428e608887","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_2630_26 = \"defensive\"\n\ndef load_insecure_temp_file_2630_26(request_2630_26, policy_2630_26):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_2630_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_2630_26)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_2630_26 = \"defensive\"\n\ndef load_insecure_temp_file_2630_26(request_2630_26, policy_2630_26):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_2630_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_2630_26)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_f6b40e42_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_temp_file_2630_26)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-d7ee8e40a70be7d5","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_6228_26 = \"defensive\"\n\ndef load_sensitive_data_exposure_6228_26(request_6228_26, context_6228_26, limit_6228_26):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_6228_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6228_26.info(\"login user=%s\", context_6228_26)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_6228_26 = \"defensive\"\n\ndef load_sensitive_data_exposure_6228_26(request_6228_26, context_6228_26, limit_6228_26):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_6228_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6228_26.info(\"login user=%s\", context_6228_26)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_d7ee8e40_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_6228_26)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-714fe58a6a3fd51b","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6827_3 = \"defensive\"\n\ndef apply_resource_consumption_6827_3(payload_6827_3, target_6827_3):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6827_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_6827_3.read(int(target_6827_3))\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6827_3 = \"defensive\"\n\ndef apply_resource_consumption_6827_3(payload_6827_3, target_6827_3):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6827_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_6827_3), 1), 1_048_576)\n data = payload_6827_3.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_714fe58a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_6827_3)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-8d1a35eb80317c52","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_9121_28 = \"defensive\"\n\ndef load_insecure_temp_file_9121_28(payload_9121_28, policy_9121_28):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_9121_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_9121_28}.txt\")\n path.write_text(policy_9121_28, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_9121_28 = \"defensive\"\n\ndef load_insecure_temp_file_9121_28(payload_9121_28, policy_9121_28):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_9121_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_9121_28)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_8d1a35eb_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_temp_file_9121_28)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-1a526c372b044865","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_9220_23 = \"defensive\"\n\ndef apply_sensitive_data_exposure_9220_23(value_9220_23, policy_9220_23, owner_9220_23):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_9220_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9220_23.info(\"login user=%s\", policy_9220_23)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_9220_23 = \"defensive\"\n\ndef apply_sensitive_data_exposure_9220_23(value_9220_23, policy_9220_23, owner_9220_23):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_9220_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9220_23.info(\"login user=%s\", policy_9220_23)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_1a526c37_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sensitive_data_exposure_9220_23)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-f0f6dc16f30f85ee","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4798_12 = \"defensive\"\n\ndef load_mass_assignment_4798_12(request_4798_12, scope_4798_12):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4798_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in scope_4798_12.items():\n setattr(request_4798_12, key, value)\n return request_4798_12\n","fixed_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4798_12 = \"defensive\"\n\ndef load_mass_assignment_4798_12(request_4798_12, scope_4798_12):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4798_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_4798_12.items() if key in allowed_fields}\n request_4798_12.update(safe)\n return request_4798_12\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_f0f6dc16_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_mass_assignment_4798_12)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-4932667b2f969c88","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7157_4 = \"defensive\"\n\ndef load_cleartext_http_transport_7157_4(value_7157_4):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7157_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_7157_4, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7157_4 = \"defensive\"\n\ndef load_cleartext_http_transport_7157_4(value_7157_4):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7157_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7157_4, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_4932667b_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_7157_4)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-0971d20a82531f81","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9864_8 = \"defensive\"\n\ndef resolve_sql_injection_9864_8(value_9864_8, target_9864_8):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9864_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9864_8.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9864_8,)).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9864_8 = \"defensive\"\n\ndef resolve_sql_injection_9864_8(value_9864_8, target_9864_8):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9864_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9864_8.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9864_8,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_0971d20a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_9864_8)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-e6fbc13e91c8667e","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_7393_29 = \"defensive\"\n\ndef load_flask_jinja_xss_7393_29(subject_7393_29):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_7393_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(subject_7393_29)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_7393_29 = \"defensive\"\n\ndef load_flask_jinja_xss_7393_29(subject_7393_29):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_7393_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(subject_7393_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_e6fbc13e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_jinja_xss_7393_29)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-e545a89089af5eae","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1212_0 = \"defensive\"\n\ndef resolve_plaintext_password_storage_1212_0(value_1212_0, target_1212_0, options_1212_0):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1212_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_1212_0).write_text(target_1212_0, encoding=\"utf-8\")\n return Path(value_1212_0)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1212_0 = \"defensive\"\n\ndef resolve_plaintext_password_storage_1212_0(value_1212_0, target_1212_0, options_1212_0):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_1212_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_1212_0) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_1212_0.encode(\"utf-8\"), options_1212_0, 240_000).hex()\n Path(value_1212_0).write_text(verifier, encoding=\"ascii\")\n return Path(value_1212_0)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_e545a890_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_plaintext_password_storage_1212_0)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-4cf80a2045e93b65","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_3948_23 = \"defensive\"\n\ndef process_missing_authorization_3948_23(value_3948_23, target_3948_23):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_3948_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3948_23.id != target_3948_23.owner_id:\n raise PermissionError(\"record ownership required\")\n target_3948_23.delete()\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_3948_23 = \"defensive\"\n\ndef process_missing_authorization_3948_23(value_3948_23, target_3948_23):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_3948_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3948_23.id != target_3948_23.owner_id:\n raise PermissionError(\"record ownership required\")\n target_3948_23.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_4cf80a20_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_missing_authorization_3948_23)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-01674576abe7c367","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_5624_1 = \"defensive\"\n\ndef load_insecure_random_token_5624_1(payload_5624_1):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_5624_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(payload_5624_1)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_5624_1 = \"defensive\"\n\ndef load_insecure_random_token_5624_1(payload_5624_1):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_5624_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_5624_1)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_01674576_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_random_token_5624_1)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-f98a23e509c04116","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6344_9 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_6344_9(payload_6344_9, target_6344_9):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6344_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return target_6344_9.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6344_9 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_6344_9(payload_6344_9, target_6344_9):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6344_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_6344_9 is None or not payload_6344_9.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_6344_9.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_f98a23e5_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_missing_authentication_6344_9)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-10d8c99b0a643a1f","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_5599_10 = \"defensive\"\n\ndef resolve_command_injection_5599_10(subject_5599_10, context_5599_10):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_5599_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_5599_10} {context_5599_10}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_5599_10 = \"defensive\"\n\ndef resolve_command_injection_5599_10(subject_5599_10, context_5599_10):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_5599_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_5599_10, context_5599_10], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_10d8c99b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_5599_10)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-219056668aba72e2","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3560_23 = \"defensive\"\n\ndef resolve_insecure_temp_file_3560_23(payload_3560_23, scope_3560_23):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3560_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_3560_23)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3560_23 = \"defensive\"\n\ndef resolve_insecure_temp_file_3560_23(payload_3560_23, scope_3560_23):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3560_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_3560_23)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_21905666_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_3560_23)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-dc90fd17a0757529","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5215_10 = \"defensive\"\n\ndef apply_starlette_permissive_cors_5215_10(subject_5215_10, policy_5215_10):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5215_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5215_10.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_5215_10\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5215_10 = \"defensive\"\n\ndef apply_starlette_permissive_cors_5215_10(subject_5215_10, policy_5215_10):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_5215_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5215_10)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_5215_10.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_5215_10\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_dc90fd17_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_5215_10)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-ebad8c090333424e","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_8911_16 = \"defensive\"\n\ndef load_plaintext_password_storage_8911_16(value_8911_16, target_8911_16, options_8911_16):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_8911_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_8911_16).write_text(target_8911_16, encoding=\"utf-8\")\n return Path(value_8911_16)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_8911_16 = \"defensive\"\n\ndef load_plaintext_password_storage_8911_16(value_8911_16, target_8911_16, options_8911_16):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_8911_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_8911_16) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_8911_16.encode(\"utf-8\"), options_8911_16, 240_000).hex()\n Path(value_8911_16).write_text(verifier, encoding=\"ascii\")\n return Path(value_8911_16)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_ebad8c09_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_8911_16)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-f00f682a3e036401","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_3317_11 = \"defensive\"\n\ndef process_regex_dos_3317_11(payload_3317_11, scope_3317_11):\n if HANDLER_KIND_PROCESS_REGEX_DOS_3317_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_3317_11) > 256 or len(scope_3317_11) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_3317_11), scope_3317_11) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_3317_11 = \"defensive\"\n\ndef process_regex_dos_3317_11(payload_3317_11, scope_3317_11):\n if HANDLER_KIND_PROCESS_REGEX_DOS_3317_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_3317_11) > 256 or len(scope_3317_11) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_3317_11), scope_3317_11) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_f00f682a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_3317_11)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-92d528061a5abab5","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1536_28 = \"defensive\"\n\ndef process_starlette_permissive_cors_1536_28(value_1536_28, scope_1536_28):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1536_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_1536_28.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return value_1536_28\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1536_28 = \"defensive\"\n\ndef process_starlette_permissive_cors_1536_28(value_1536_28, scope_1536_28):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1536_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_1536_28)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_1536_28.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_1536_28\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_92d52806_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_1536_28)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-935141cf5ec45e34","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_8976_20 = \"defensive\"\n\ndef handle_ssrf_8976_20(value_8976_20, scope_8976_20):\n if HANDLER_KIND_HANDLE_SSRF_8976_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_8976_20)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_8976_20):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_8976_20, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_8976_20 = \"defensive\"\n\ndef handle_ssrf_8976_20(value_8976_20, scope_8976_20):\n if HANDLER_KIND_HANDLE_SSRF_8976_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_8976_20)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_8976_20):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_8976_20, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_935141cf_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_8976_20)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-c0aea8d074984470","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_2493_29 = \"defensive\"\n\ndef load_flask_open_redirect_2493_29(request_2493_29):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_2493_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_2493_29)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_2493_29)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_2493_29 = \"defensive\"\n\ndef load_flask_open_redirect_2493_29(request_2493_29):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_2493_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_2493_29)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_2493_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_c0aea8d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_open_redirect_2493_29)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-cf59b0d480eba75b","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_9430_7 = \"defensive\"\n\ndef process_flask_jinja_xss_9430_7(request_9430_7):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_9430_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_9430_7)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_9430_7 = \"defensive\"\n\ndef process_flask_jinja_xss_9430_7(request_9430_7):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_9430_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_9430_7)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_cf59b0d4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_9430_7)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-0e8ecbdd4a84e11e","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2710_7 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_2710_7(payload_2710_7):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2710_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(payload_2710_7, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2710_7 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_2710_7(payload_2710_7):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2710_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_2710_7)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_0e8ecbdd_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_2710_7)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-58f86c63cd30c783","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_1063_11 = \"defensive\"\n\ndef apply_insecure_random_token_1063_11(value_1063_11):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_1063_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_1063_11)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_1063_11 = \"defensive\"\n\ndef apply_insecure_random_token_1063_11(value_1063_11):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_1063_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_1063_11)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_58f86c63_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_1063_11)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-cf00319f7928ce7c","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4495_27 = \"defensive\"\n\ndef resolve_resource_consumption_4495_27(payload_4495_27, context_4495_27):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4495_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_4495_27.read(int(context_4495_27))\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4495_27 = \"defensive\"\n\ndef resolve_resource_consumption_4495_27(payload_4495_27, context_4495_27):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4495_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_4495_27), 1), 1_048_576)\n data = payload_4495_27.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_cf00319f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_4495_27)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-5969b9b6ab1a2c5e","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9639_26 = \"defensive\"\n\ndef process_httpx_client_ssrf_9639_26(request_9639_26, target_9639_26, owner_9639_26):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9639_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_9639_26)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_9639_26):\n raise ValueError(\"destination is not allowed\")\n return request_9639_26.get(target_9639_26, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9639_26 = \"defensive\"\n\ndef process_httpx_client_ssrf_9639_26(request_9639_26, target_9639_26, owner_9639_26):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_9639_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_9639_26)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_9639_26):\n raise ValueError(\"destination is not allowed\")\n return request_9639_26.get(target_9639_26, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_5969b9b6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_9639_26)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-1a4ea4a683e344f7","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9514_3 = \"defensive\"\n\ndef apply_requests_tls_verification_9514_3(subject_9514_3):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9514_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_9514_3, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9514_3 = \"defensive\"\n\ndef apply_requests_tls_verification_9514_3(subject_9514_3):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9514_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_9514_3, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_1a4ea4a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_9514_3)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-8bc54fc1e7988b06","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7758_23 = \"defensive\"\n\ndef resolve_django_error_details_7758_23(subject_7758_23, scope_7758_23):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7758_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_7758_23()\n except Exception:\n subject_7758_23.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7758_23 = \"defensive\"\n\ndef resolve_django_error_details_7758_23(subject_7758_23, scope_7758_23):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7758_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_7758_23()\n except Exception:\n subject_7758_23.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_8bc54fc1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_7758_23)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-37f285b36843f5a5","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5154_19 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5154_19(subject_5154_19):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5154_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(subject_5154_19)\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5154_19 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5154_19(subject_5154_19):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5154_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_5154_19.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_37f285b3_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_5154_19)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-b8866cd97fe573a2","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_SSRF_7063_7 = \"defensive\"\n\ndef load_ssrf_7063_7(subject_7063_7, scope_7063_7):\n if HANDLER_KIND_LOAD_SSRF_7063_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_7063_7, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_7063_7 = \"defensive\"\n\ndef load_ssrf_7063_7(subject_7063_7, scope_7063_7):\n if HANDLER_KIND_LOAD_SSRF_7063_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_7063_7)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_7063_7):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_7063_7, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_b8866cd9_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_7063_7)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-210a76f2e8f41a6e","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_1840_28 = \"defensive\"\n\ndef apply_dynamic_code_injection_1840_28(subject_1840_28):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_1840_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_1840_28, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_1840_28 = \"defensive\"\n\ndef apply_dynamic_code_injection_1840_28(subject_1840_28):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_1840_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1840_28) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_1840_28)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_210a76f2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_1840_28)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-e4abe68121473a96","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8372_19 = \"defensive\"\n\ndef apply_hardcoded_credentials_8372_19(value_8372_19):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8372_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000019\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_8372_19)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8372_19 = \"defensive\"\n\ndef apply_hardcoded_credentials_8372_19(value_8372_19):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8372_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_8372_19)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_e4abe681_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_8372_19)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9f31f67778b813ae","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4766_4 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_4766_4(subject_4766_4, context_4766_4):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4766_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_4766_4}\")\n return subject_4766_4.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4766_4 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_4766_4(subject_4766_4, context_4766_4):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_4766_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_4766_4.execute(statement, {\"account_id\": context_4766_4}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_9f31f677_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_4766_4)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-c77d0184bf01cfd9","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_9273_17 = \"defensive\"\n\ndef resolve_flask_session_fixation_9273_17(subject_9273_17, scope_9273_17):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_9273_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_9273_17.clear()\n subject_9273_17[\"user_id\"] = scope_9273_17.id\n subject_9273_17[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_9273_17 = \"defensive\"\n\ndef resolve_flask_session_fixation_9273_17(subject_9273_17, scope_9273_17):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_9273_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_9273_17.clear()\n subject_9273_17[\"user_id\"] = scope_9273_17.id\n subject_9273_17[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_c77d0184_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_9273_17)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-3c06e5144ad01819","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_7270_2 = \"defensive\"\n\ndef load_insecure_temp_file_7270_2(subject_7270_2, scope_7270_2):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_7270_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_7270_2)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_7270_2 = \"defensive\"\n\ndef load_insecure_temp_file_7270_2(subject_7270_2, scope_7270_2):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_7270_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_7270_2)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_3c06e514_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_temp_file_7270_2)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-4377d6b2b6b00d1d","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_5649_12 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_5649_12(payload_5649_12, policy_5649_12, limit_5649_12):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_5649_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5649_12, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_5649_12 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_5649_12(payload_5649_12, policy_5649_12, limit_5649_12):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_5649_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5649_12, policy_5649_12, algorithms=[\"HS256\"], audience=limit_5649_12)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_4377d6b2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_5649_12)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-6a887b06dc2d7ac0","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6260_17 = \"defensive\"\n\ndef apply_http_response_splitting_6260_17(request_6260_17, target_6260_17):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6260_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_6260_17 or \"\\n\" in target_6260_17:\n raise ValueError(\"invalid header value\")\n request_6260_17.headers[\"X-Next\"] = target_6260_17\n return request_6260_17\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6260_17 = \"defensive\"\n\ndef apply_http_response_splitting_6260_17(request_6260_17, target_6260_17):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6260_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_6260_17 or \"\\n\" in target_6260_17:\n raise ValueError(\"invalid header value\")\n request_6260_17.headers[\"X-Next\"] = target_6260_17\n return request_6260_17\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_6a887b06_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_6260_17)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-7f291fa103df454c","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_9757_20 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_9757_20(subject_9757_20):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_9757_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_9757_20)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_9757_20 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_9757_20(subject_9757_20):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_9757_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_9757_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_7f291fa1_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_9757_20)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-c408042e95a7c45e","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_3827_20 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_3827_20(value_3827_20, context_3827_20):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_3827_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3827_20 is None or not value_3827_20.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_3827_20.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_3827_20 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_3827_20(value_3827_20, context_3827_20):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_3827_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3827_20 is None or not value_3827_20.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_3827_20.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_c408042e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_3827_20)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-03b42f5084538b90","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_2208_13 = \"defensive\"\n\ndef resolve_flask_session_fixation_2208_13(subject_2208_13, scope_2208_13):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_2208_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2208_13[\"user_id\"] = scope_2208_13.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_2208_13 = \"defensive\"\n\ndef resolve_flask_session_fixation_2208_13(subject_2208_13, scope_2208_13):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_2208_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2208_13.clear()\n subject_2208_13[\"user_id\"] = scope_2208_13.id\n subject_2208_13[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_03b42f50_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_2208_13)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-47726ccb4cc0376d","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_4054_0 = \"defensive\"\n\ndef process_path_traversal_4054_0(value_4054_0, context_4054_0):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_4054_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_4054_0) / context_4054_0).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_4054_0 = \"defensive\"\n\ndef process_path_traversal_4054_0(value_4054_0, context_4054_0):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_4054_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_4054_0).resolve()\n candidate = (root / context_4054_0).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_47726ccb_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_4054_0)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-72fabda692ea2874","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_5798_2 = \"defensive\"\n\ndef process_regex_dos_5798_2(subject_5798_2, context_5798_2):\n if HANDLER_KIND_PROCESS_REGEX_DOS_5798_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5798_2) > 256 or len(context_5798_2) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_5798_2), context_5798_2) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_5798_2 = \"defensive\"\n\ndef process_regex_dos_5798_2(subject_5798_2, context_5798_2):\n if HANDLER_KIND_PROCESS_REGEX_DOS_5798_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5798_2) > 256 or len(context_5798_2) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_5798_2), context_5798_2) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_72fabda6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_5798_2)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-89936f474904cb09","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3869_18 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3869_18(payload_3869_18, scope_3869_18):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3869_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_3869_18.extractall(scope_3869_18)\n return scope_3869_18\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3869_18 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3869_18(payload_3869_18, scope_3869_18):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3869_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_3869_18.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_3869_18.extractall(scope_3869_18)\n return scope_3869_18\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_89936f47_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_3869_18)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-7e25d301d181009c","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7458_13 = \"defensive\"\n\ndef apply_insecure_random_token_7458_13(request_7458_13):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7458_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_7458_13)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7458_13 = \"defensive\"\n\ndef apply_insecure_random_token_7458_13(request_7458_13):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7458_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_7458_13)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_7e25d301_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_7458_13)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-184e775dc373a0b8","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_8012_18 = \"defensive\"\n\ndef apply_flask_csrf_validation_8012_18(request_8012_18, scope_8012_18):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_8012_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_8012_18.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_8012_18 = \"defensive\"\n\ndef apply_flask_csrf_validation_8012_18(request_8012_18, scope_8012_18):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_8012_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_8012_18.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_8012_18.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_8012_18.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_184e775d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_csrf_validation_8012_18)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-7cc5571f164a9bf8","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5789_0 = \"defensive\"\n\ndef process_django_error_details_5789_0(payload_5789_0, context_5789_0):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5789_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_5789_0()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5789_0 = \"defensive\"\n\ndef process_django_error_details_5789_0(payload_5789_0, context_5789_0):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5789_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_5789_0()\n except Exception:\n payload_5789_0.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_7cc5571f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_error_details_5789_0)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-b3ac070a00203ece","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_9568_6 = \"defensive\"\n\ndef load_flask_jinja_xss_9568_6(request_9568_6):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_9568_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_9568_6)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_9568_6 = \"defensive\"\n\ndef load_flask_jinja_xss_9568_6(request_9568_6):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_9568_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_9568_6)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_b3ac070a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_jinja_xss_9568_6)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-d725ba67d28d0bab","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3321_15 = \"defensive\"\n\ndef apply_mass_assignment_3321_15(value_3321_15, scope_3321_15):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3321_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in scope_3321_15.items():\n setattr(value_3321_15, key, value)\n return value_3321_15\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3321_15 = \"defensive\"\n\ndef apply_mass_assignment_3321_15(value_3321_15, scope_3321_15):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3321_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_3321_15.items() if key in allowed_fields}\n value_3321_15.update(safe)\n return value_3321_15\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_d725ba67_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_3321_15)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-5a3867ceb32d8098","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_3009_0 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_3009_0(subject_3009_0, policy_3009_0, allowed_3009_0):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_3009_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_3009_0, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_3009_0 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_3009_0(subject_3009_0, policy_3009_0, allowed_3009_0):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_3009_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_3009_0, policy_3009_0, algorithms=[\"HS256\"], audience=allowed_3009_0)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_5a3867ce_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_3009_0)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-0131c2c4208aed21","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1923_11 = \"defensive\"\n\ndef handle_flask_open_redirect_1923_11(value_1923_11):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1923_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_1923_11)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_1923_11)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1923_11 = \"defensive\"\n\ndef handle_flask_open_redirect_1923_11(value_1923_11):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1923_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_1923_11)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_1923_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_0131c2c4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_1923_11)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-030998bce1b180f3","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_5536_19 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_5536_19(payload_5536_19, policy_5536_19, limit_5536_19):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_5536_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5536_19, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_5536_19 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_5536_19(payload_5536_19, policy_5536_19, limit_5536_19):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_5536_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_5536_19, policy_5536_19, algorithms=[\"HS256\"], audience=limit_5536_19)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_030998bc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyjwt_signature_bypass_5536_19)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-405f7d602c0541e8","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_2800_22 = \"defensive\"\n\ndef handle_resource_consumption_2800_22(request_2800_22, scope_2800_22):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_2800_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2800_22.read(int(scope_2800_22))\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_2800_22 = \"defensive\"\n\ndef handle_resource_consumption_2800_22(request_2800_22, scope_2800_22):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_2800_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_2800_22), 1), 1_048_576)\n data = request_2800_22.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_405f7d60_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_2800_22)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-51150db44de7e528","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8974_15 = \"defensive\"\n\ndef load_cleartext_http_transport_8974_15(value_8974_15):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8974_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_8974_15, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8974_15 = \"defensive\"\n\ndef load_cleartext_http_transport_8974_15(value_8974_15):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8974_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_8974_15, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_51150db4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_8974_15)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-ff0ab8b0fe07b76c","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6322_13 = \"defensive\"\n\ndef process_requests_tls_verification_6322_13(payload_6322_13):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6322_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6322_13, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6322_13 = \"defensive\"\n\ndef process_requests_tls_verification_6322_13(payload_6322_13):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_6322_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6322_13, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_ff0ab8b0_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_requests_tls_verification_6322_13)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-68b84f58fa89123d","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6253_17 = \"defensive\"\n\ndef handle_sensitive_data_exposure_6253_17(request_6253_17, policy_6253_17, allowed_6253_17):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6253_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6253_17.info(\"login user=%s\", policy_6253_17)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6253_17 = \"defensive\"\n\ndef handle_sensitive_data_exposure_6253_17(request_6253_17, policy_6253_17, allowed_6253_17):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_6253_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6253_17.info(\"login user=%s\", policy_6253_17)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_68b84f58_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_6253_17)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-0a5584f121460c84","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_3660_12 = \"defensive\"\n\ndef apply_requests_tls_verification_3660_12(payload_3660_12):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_3660_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_3660_12, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_3660_12 = \"defensive\"\n\ndef apply_requests_tls_verification_3660_12(payload_3660_12):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_3660_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_3660_12, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_0a5584f1_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_3660_12)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-2786de9ab5ed633b","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_8973_24 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_8973_24(request_8973_24):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_8973_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_8973_24, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_8973_24 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_8973_24(request_8973_24):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_8973_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_8973_24)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_2786de9a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_8973_24)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-66aa7ae6dc12625c","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2117_12 = \"defensive\"\n\ndef resolve_lxml_external_entity_2117_12(value_2117_12):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2117_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_2117_12)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2117_12 = \"defensive\"\n\ndef resolve_lxml_external_entity_2117_12(value_2117_12):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_2117_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_2117_12, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_66aa7ae6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_2117_12)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-4aa150e8deac9307","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3183_2 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3183_2(subject_3183_2):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3183_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_3183_2.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_3183_2.size is None or subject_3183_2.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_3183_2.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3183_2 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3183_2(subject_3183_2):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3183_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_3183_2.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_3183_2.size is None or subject_3183_2.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_3183_2.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_4aa150e8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_3183_2)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-008dfe66c0a31243","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_6114_7 = \"defensive\"\n\ndef apply_ldap_filter_injection_6114_7(payload_6114_7, policy_6114_7):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_6114_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={policy_6114_7})\"\n return payload_6114_7.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_6114_7 = \"defensive\"\n\ndef apply_ldap_filter_injection_6114_7(payload_6114_7, policy_6114_7):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_6114_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_6114_7)\n query = f\"(uid={escaped})\"\n return payload_6114_7.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_008dfe66_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ldap_filter_injection_6114_7)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-98a4c7882fed40ad","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4230_5 = \"defensive\"\n\ndef handle_requests_tls_verification_4230_5(payload_4230_5):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4230_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_4230_5, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4230_5 = \"defensive\"\n\ndef handle_requests_tls_verification_4230_5(payload_4230_5):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4230_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_4230_5, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_98a4c788_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_4230_5)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-4d5723cc2ae91f84","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7000_13 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7000_13(request_7000_13, scope_7000_13):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7000_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_7000_13}']\"\n return request_7000_13.xpath(xpath)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7000_13 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7000_13(request_7000_13, scope_7000_13):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7000_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7000_13.xpath(\"//user[@name=$account]\", account=scope_7000_13)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_4d5723cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_7000_13)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-2b38a945d2233272","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9953_8 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_9953_8(request_9953_8, target_9953_8):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9953_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_9953_8.xpath(\"//user[@name=$account]\", account=target_9953_8)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9953_8 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_9953_8(request_9953_8, target_9953_8):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9953_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_9953_8.xpath(\"//user[@name=$account]\", account=target_9953_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_2b38a945_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_9953_8)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-3ed5ccf786092212","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_1334_10 = \"defensive\"\n\ndef handle_ldap_filter_injection_1334_10(subject_1334_10, target_1334_10):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_1334_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={target_1334_10})\"\n return subject_1334_10.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_1334_10 = \"defensive\"\n\ndef handle_ldap_filter_injection_1334_10(subject_1334_10, target_1334_10):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_1334_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_1334_10)\n query = f\"(uid={escaped})\"\n return subject_1334_10.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_3ed5ccf7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_1334_10)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-3919da592343bb2c","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_8383_2 = \"defensive\"\n\ndef process_flask_csrf_validation_8383_2(value_8383_2, target_8383_2):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_8383_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_8383_2.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_8383_2.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_8383_2.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_8383_2 = \"defensive\"\n\ndef process_flask_csrf_validation_8383_2(value_8383_2, target_8383_2):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_8383_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_8383_2.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_8383_2.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_8383_2.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_3919da59_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_8383_2)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-e9d884533067885c","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_1643_29 = \"defensive\"\n\ndef resolve_flask_session_fixation_1643_29(payload_1643_29, context_1643_29):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_1643_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_1643_29.clear()\n payload_1643_29[\"user_id\"] = context_1643_29.id\n payload_1643_29[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_1643_29 = \"defensive\"\n\ndef resolve_flask_session_fixation_1643_29(payload_1643_29, context_1643_29):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_1643_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_1643_29.clear()\n payload_1643_29[\"user_id\"] = context_1643_29.id\n payload_1643_29[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_e9d88453_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_1643_29)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-27403f25fdd6c7b6","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_8749_20 = \"defensive\"\n\ndef load_flask_csrf_validation_8749_20(payload_8749_20, scope_8749_20):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_8749_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_8749_20.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_8749_20.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_8749_20.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_8749_20 = \"defensive\"\n\ndef load_flask_csrf_validation_8749_20(payload_8749_20, scope_8749_20):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_8749_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_8749_20.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_8749_20.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_8749_20.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_27403f25_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_csrf_validation_8749_20)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-bc0795b2d0f0c780","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6304_19 = \"defensive\"\n\ndef apply_insecure_random_token_6304_19(subject_6304_19):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6304_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_6304_19)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6304_19 = \"defensive\"\n\ndef apply_insecure_random_token_6304_19(subject_6304_19):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6304_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_6304_19)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_bc0795b2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_6304_19)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-d4d230ba6614ac82","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_8669_10 = \"defensive\"\n\ndef resolve_insecure_random_token_8669_10(subject_8669_10):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_8669_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_8669_10)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_8669_10 = \"defensive\"\n\ndef resolve_insecure_random_token_8669_10(subject_8669_10):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_8669_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_8669_10)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_d4d230ba_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_random_token_8669_10)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-b74e3c955e68d9e9","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7541_2 = \"defensive\"\n\ndef handle_csv_formula_injection_7541_2(payload_7541_2):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7541_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7541_2)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7541_2 = \"defensive\"\n\ndef handle_csv_formula_injection_7541_2(payload_7541_2):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7541_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7541_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_b74e3c95_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_7541_2)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-18253bfb69c96718","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7787_20 = \"defensive\"\n\ndef load_cleartext_http_transport_7787_20(value_7787_20):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7787_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7787_20, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7787_20 = \"defensive\"\n\ndef load_cleartext_http_transport_7787_20(value_7787_20):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7787_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7787_20, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_18253bfb_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_7787_20)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-f0caaf1a4160ecd1","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6408_27 = \"defensive\"\n\ndef handle_missing_authorization_6408_27(value_6408_27, target_6408_27):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6408_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n target_6408_27.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6408_27 = \"defensive\"\n\ndef handle_missing_authorization_6408_27(value_6408_27, target_6408_27):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6408_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_6408_27.id != target_6408_27.owner_id:\n raise PermissionError(\"record ownership required\")\n target_6408_27.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_f0caaf1a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_6408_27)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-d2ce76508007c5d3","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_4344_8 = \"defensive\"\n\ndef apply_path_traversal_4344_8(value_4344_8, target_4344_8):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_4344_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_4344_8).resolve()\n candidate = (root / target_4344_8).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_4344_8 = \"defensive\"\n\ndef apply_path_traversal_4344_8(value_4344_8, target_4344_8):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_4344_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_4344_8).resolve()\n candidate = (root / target_4344_8).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_d2ce7650_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_4344_8)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-82eebd54e7403e03","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_7793_8 = \"defensive\"\n\ndef process_regex_dos_7793_8(subject_7793_8, context_7793_8):\n if HANDLER_KIND_PROCESS_REGEX_DOS_7793_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_7793_8) > 256 or len(context_7793_8) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_7793_8), context_7793_8) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_7793_8 = \"defensive\"\n\ndef process_regex_dos_7793_8(subject_7793_8, context_7793_8):\n if HANDLER_KIND_PROCESS_REGEX_DOS_7793_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_7793_8) > 256 or len(context_7793_8) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_7793_8), context_7793_8) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_82eebd54_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_7793_8)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-b81a336993a8ff5f","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5552_6 = \"defensive\"\n\ndef resolve_requests_tls_verification_5552_6(subject_5552_6):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5552_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_5552_6, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5552_6 = \"defensive\"\n\ndef resolve_requests_tls_verification_5552_6(subject_5552_6):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_5552_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_5552_6, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_b81a3369_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_requests_tls_verification_5552_6)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-88cccee3185c302f","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_7728_19 = \"defensive\"\n\ndef resolve_sql_injection_7728_19(subject_7728_19, policy_7728_19):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_7728_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {policy_7728_19}\"\n return subject_7728_19.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_7728_19 = \"defensive\"\n\ndef resolve_sql_injection_7728_19(subject_7728_19, policy_7728_19):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_7728_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7728_19.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (policy_7728_19,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_88cccee3_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_7728_19)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-f3f1503f96c2781d","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_2779_21 = \"defensive\"\n\ndef apply_django_safe_string_xss_2779_21(payload_2779_21):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_2779_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_2779_21}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_2779_21 = \"defensive\"\n\ndef apply_django_safe_string_xss_2779_21(payload_2779_21):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_2779_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_2779_21)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_f3f1503f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_2779_21)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-f0d1351585c94dc1","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_8315_28 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_8315_28(payload_8315_28):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_8315_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(payload_8315_28, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_8315_28 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_8315_28(payload_8315_28):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_8315_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_8315_28)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_f0d13515_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_8315_28)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-e64622020830a7c5","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_9646_16 = \"defensive\"\n\ndef load_unsafe_deserialization_9646_16(subject_9646_16):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_9646_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(subject_9646_16)\n","fixed_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_9646_16 = \"defensive\"\n\ndef load_unsafe_deserialization_9646_16(subject_9646_16):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_9646_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_9646_16.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_e6462202_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_unsafe_deserialization_9646_16)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-606ae05a9daa4574","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_7485_0 = \"defensive\"\n\ndef apply_flask_open_redirect_7485_0(request_7485_0):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_7485_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(request_7485_0)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_7485_0 = \"defensive\"\n\ndef apply_flask_open_redirect_7485_0(request_7485_0):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_7485_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_7485_0)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_7485_0)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_606ae05a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_open_redirect_7485_0)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-2294886d5e127279","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7794_28 = \"defensive\"\n\ndef handle_ldap_filter_injection_7794_28(request_7794_28, scope_7794_28):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7794_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={scope_7794_28})\"\n return request_7794_28.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7794_28 = \"defensive\"\n\ndef handle_ldap_filter_injection_7794_28(request_7794_28, scope_7794_28):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7794_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_7794_28)\n query = f\"(uid={escaped})\"\n return request_7794_28.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_2294886d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_7794_28)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-5c897cde085a6478","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_7060_16 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_7060_16(value_7060_16, policy_7060_16, allowed_7060_16):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_7060_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_7060_16, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_7060_16 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_7060_16(value_7060_16, policy_7060_16, allowed_7060_16):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_7060_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_7060_16, policy_7060_16, algorithms=[\"HS256\"], audience=allowed_7060_16)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_5c897cde_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_7060_16)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-beee2bd798cbccc7","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_1884_8 = \"defensive\"\n\ndef load_insecure_random_token_1884_8(payload_1884_8):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_1884_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_1884_8)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_1884_8 = \"defensive\"\n\ndef load_insecure_random_token_1884_8(payload_1884_8):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_1884_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_1884_8)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_beee2bd7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_random_token_1884_8)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-6e743fe97bd02df7","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_2267_22 = \"defensive\"\n\ndef process_weak_cryptography_2267_22(payload_2267_22, policy_2267_22):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_2267_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_2267_22.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_2267_22 = \"defensive\"\n\ndef process_weak_cryptography_2267_22(payload_2267_22, policy_2267_22):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_2267_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_2267_22.encode(\"utf-8\"), policy_2267_22, 220000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_6e743fe9_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_2267_22)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-bd42df4eeb21dc2c","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2712_18 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_2712_18(payload_2712_18, context_2712_18):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2712_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2712_18.extractall(context_2712_18)\n return context_2712_18\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2712_18 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_2712_18(payload_2712_18, context_2712_18):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_2712_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2712_18.extractall(context_2712_18, filter=\"data\")\n return context_2712_18\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_bd42df4e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_2712_18)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-5bd1d2d0daddb370","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_7145_12 = \"defensive\"\n\ndef apply_sql_injection_7145_12(subject_7145_12, context_7145_12):\n if HANDLER_KIND_APPLY_SQL_INJECTION_7145_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {context_7145_12}\"\n return subject_7145_12.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_7145_12 = \"defensive\"\n\ndef apply_sql_injection_7145_12(subject_7145_12, context_7145_12):\n if HANDLER_KIND_APPLY_SQL_INJECTION_7145_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7145_12.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (context_7145_12,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_5bd1d2d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_7145_12)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-41f0a3c583c5d0e4","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_7402_26 = \"defensive\"\n\ndef resolve_missing_authorization_7402_26(payload_7402_26, context_7402_26):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_7402_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_7402_26.id != context_7402_26.owner_id:\n raise PermissionError(\"record ownership required\")\n context_7402_26.delete()\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_7402_26 = \"defensive\"\n\ndef resolve_missing_authorization_7402_26(payload_7402_26, context_7402_26):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_7402_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_7402_26.id != context_7402_26.owner_id:\n raise PermissionError(\"record ownership required\")\n context_7402_26.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_41f0a3c5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_missing_authorization_7402_26)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-f59ef2f8d1f00676","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_2972_20 = \"defensive\"\n\ndef load_hardcoded_credentials_2972_20(subject_2972_20):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_2972_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_2972_20)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_2972_20 = \"defensive\"\n\ndef load_hardcoded_credentials_2972_20(subject_2972_20):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_2972_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_2972_20)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_f59ef2f8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_2972_20)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-0d0e948eb332c625","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_6885_17 = \"defensive\"\n\ndef resolve_ldap_filter_injection_6885_17(request_6885_17, policy_6885_17):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_6885_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_6885_17)\n query = f\"(uid={escaped})\"\n return request_6885_17.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_6885_17 = \"defensive\"\n\ndef resolve_ldap_filter_injection_6885_17(request_6885_17, policy_6885_17):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_6885_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_6885_17)\n query = f\"(uid={escaped})\"\n return request_6885_17.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_0d0e948e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_6885_17)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-33e96f8028ff2716","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1746_20 = \"defensive\"\n\ndef apply_flask_session_fixation_1746_20(subject_1746_20, target_1746_20):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1746_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1746_20.clear()\n subject_1746_20[\"user_id\"] = target_1746_20.id\n subject_1746_20[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1746_20 = \"defensive\"\n\ndef apply_flask_session_fixation_1746_20(subject_1746_20, target_1746_20):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1746_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1746_20.clear()\n subject_1746_20[\"user_id\"] = target_1746_20.id\n subject_1746_20[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_33e96f80_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_1746_20)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-b6d2b361f2da924e","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2097_3 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2097_3(value_2097_3, scope_2097_3):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2097_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return scope_2097_3.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2097_3 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2097_3(value_2097_3, scope_2097_3):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2097_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_2097_3 is None or not value_2097_3.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_2097_3.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_b6d2b361_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_missing_authentication_2097_3)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-0dfcaf5ab11bd70d","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9983_15 = \"defensive\"\n\ndef handle_flask_session_fixation_9983_15(request_9983_15, target_9983_15):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9983_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9983_15[\"user_id\"] = target_9983_15.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9983_15 = \"defensive\"\n\ndef handle_flask_session_fixation_9983_15(request_9983_15, target_9983_15):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9983_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9983_15.clear()\n request_9983_15[\"user_id\"] = target_9983_15.id\n request_9983_15[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_0dfcaf5a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_9983_15)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-8dd7ea9b56c2c426","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_8335_1 = \"defensive\"\n\ndef handle_log_injection_8335_1(payload_8335_1, policy_8335_1):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_8335_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8335_1.warning(\"audit=%s\", policy_8335_1)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_8335_1 = \"defensive\"\n\ndef handle_log_injection_8335_1(payload_8335_1, policy_8335_1):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_8335_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_8335_1).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_8335_1.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_8dd7ea9b_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_log_injection_8335_1)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-b9186a4d617ed991","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_SSRF_4286_8 = \"defensive\"\n\ndef resolve_ssrf_4286_8(subject_4286_8, policy_4286_8):\n if HANDLER_KIND_RESOLVE_SSRF_4286_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4286_8)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_4286_8):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_4286_8, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_SSRF_4286_8 = \"defensive\"\n\ndef resolve_ssrf_4286_8(subject_4286_8, policy_4286_8):\n if HANDLER_KIND_RESOLVE_SSRF_4286_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4286_8)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_4286_8):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_4286_8, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_b9186a4d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ssrf_4286_8)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-8d47019b494a1f55","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_9069_6 = \"defensive\"\n\ndef handle_zip_decompression_bomb_9069_6(request_9069_6, context_9069_6):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_9069_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9069_6.extractall(context_9069_6)\n return context_9069_6\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_9069_6 = \"defensive\"\n\ndef handle_zip_decompression_bomb_9069_6(request_9069_6, context_9069_6):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_9069_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_9069_6.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_9069_6.extractall(context_9069_6)\n return context_9069_6\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_8d47019b_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_9069_6)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-f8aa1166cd5460c7","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_4524_1 = \"defensive\"\n\ndef handle_lxml_xpath_injection_4524_1(request_4524_1, scope_4524_1):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_4524_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_4524_1}']\"\n return request_4524_1.xpath(xpath)\n","fixed_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_4524_1 = \"defensive\"\n\ndef handle_lxml_xpath_injection_4524_1(request_4524_1, scope_4524_1):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_4524_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4524_1.xpath(\"//user[@name=$account]\", account=scope_4524_1)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_f8aa1166_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_xpath_injection_4524_1)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-c7c78e51e734d40e","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_4344_0 = \"defensive\"\n\ndef apply_unsafe_deserialization_4344_0(subject_4344_0):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_4344_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(subject_4344_0)\n","fixed_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_4344_0 = \"defensive\"\n\ndef apply_unsafe_deserialization_4344_0(subject_4344_0):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_4344_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_4344_0.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_c7c78e51_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_unsafe_deserialization_4344_0)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-effb1c28f302124c","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5200_4 = \"defensive\"\n\ndef process_tarfile_path_traversal_5200_4(value_5200_4, context_5200_4):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5200_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5200_4.extractall(context_5200_4)\n return context_5200_4\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5200_4 = \"defensive\"\n\ndef process_tarfile_path_traversal_5200_4(value_5200_4, context_5200_4):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5200_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5200_4.extractall(context_5200_4, filter=\"data\")\n return context_5200_4\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_effb1c28_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_5200_4)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-d6b1b1373b483773","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_8921_13 = \"defensive\"\n\ndef process_weak_cryptography_8921_13(value_8921_13, context_8921_13):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_8921_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(value_8921_13.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_8921_13 = \"defensive\"\n\ndef process_weak_cryptography_8921_13(value_8921_13, context_8921_13):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_8921_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_8921_13.encode(\"utf-8\"), context_8921_13, 230000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_d6b1b137_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_8921_13)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-ae1fb545a4f4b24e","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_2061_27 = \"defensive\"\n\ndef apply_hardcoded_credentials_2061_27(value_2061_27):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_2061_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000027\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_2061_27)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_2061_27 = \"defensive\"\n\ndef apply_hardcoded_credentials_2061_27(value_2061_27):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_2061_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_2061_27)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_ae1fb545_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_2061_27)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-2135d357c3e9333b","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7643_18 = \"defensive\"\n\ndef handle_starlette_permissive_cors_7643_18(value_7643_18, target_7643_18):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7643_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_7643_18.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return value_7643_18\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7643_18 = \"defensive\"\n\ndef handle_starlette_permissive_cors_7643_18(value_7643_18, target_7643_18):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7643_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_7643_18)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_7643_18.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_7643_18\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_2135d357_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_starlette_permissive_cors_7643_18)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-a8e29de3bba50d09","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8784_10 = \"defensive\"\n\ndef process_sensitive_data_exposure_8784_10(subject_8784_10, policy_8784_10, options_8784_10):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8784_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8784_10.info(\"login user=%s password=%s\", policy_8784_10, options_8784_10)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8784_10 = \"defensive\"\n\ndef process_sensitive_data_exposure_8784_10(subject_8784_10, policy_8784_10, options_8784_10):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8784_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8784_10.info(\"login user=%s\", policy_8784_10)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_a8e29de3_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_8784_10)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-f4845c554e9b701b","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_2237_24 = \"defensive\"\n\ndef handle_path_traversal_2237_24(value_2237_24, scope_2237_24):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_2237_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_2237_24) / scope_2237_24).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_2237_24 = \"defensive\"\n\ndef handle_path_traversal_2237_24(value_2237_24, scope_2237_24):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_2237_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_2237_24).resolve()\n candidate = (root / scope_2237_24).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_f4845c55_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_2237_24)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-ecd784f78fa86e04","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7797_8 = \"defensive\"\n\ndef apply_cleartext_http_transport_7797_8(value_7797_8):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7797_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7797_8, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7797_8 = \"defensive\"\n\ndef apply_cleartext_http_transport_7797_8(value_7797_8):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7797_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7797_8, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_ecd784f7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_7797_8)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-23b5d5e41d04813f","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_6018_17 = \"defensive\"\n\ndef process_flask_open_redirect_6018_17(subject_6018_17):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_6018_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_6018_17)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_6018_17)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_6018_17 = \"defensive\"\n\ndef process_flask_open_redirect_6018_17(subject_6018_17):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_6018_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_6018_17)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_6018_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_23b5d5e4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_open_redirect_6018_17)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-37108fe074333f42","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1688_18 = \"defensive\"\n\ndef process_csv_formula_injection_1688_18(value_1688_18):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1688_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_1688_18)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1688_18 = \"defensive\"\n\ndef process_csv_formula_injection_1688_18(value_1688_18):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_1688_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_1688_18)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_37108fe0_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_1688_18)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-201cf1ad5e0e4eec","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4229_9 = \"defensive\"\n\ndef handle_dynamic_code_injection_4229_9(value_4229_9):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4229_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(value_4229_9, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4229_9 = \"defensive\"\n\ndef handle_dynamic_code_injection_4229_9(value_4229_9):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4229_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_4229_9) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(value_4229_9)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_201cf1ad_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_4229_9)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-d4716944124c3481","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1754_0 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1754_0(subject_1754_0, policy_1754_0):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1754_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return policy_1754_0.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1754_0 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1754_0(subject_1754_0, policy_1754_0):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1754_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1754_0 is None or not subject_1754_0.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_1754_0.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_d4716944_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_1754_0)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-75b4c48ed4487bbc","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2334_6 = \"defensive\"\n\ndef handle_flask_csrf_validation_2334_6(subject_2334_6, policy_2334_6):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2334_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_2334_6.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2334_6 = \"defensive\"\n\ndef handle_flask_csrf_validation_2334_6(subject_2334_6, policy_2334_6):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2334_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_2334_6.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_2334_6.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_2334_6.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_75b4c48e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_2334_6)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-6a835b644cf6012d","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_6575_6 = \"defensive\"\n\ndef process_csv_formula_injection_6575_6(subject_6575_6):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_6575_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in subject_6575_6)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_6575_6 = \"defensive\"\n\ndef process_csv_formula_injection_6575_6(subject_6575_6):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_6575_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_6575_6)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_6a835b64_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_6575_6)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-de12c21dbc3598fd","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_3725_10 = \"defensive\"\n\ndef resolve_flask_csrf_validation_3725_10(subject_3725_10, policy_3725_10):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_3725_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3725_10.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_3725_10 = \"defensive\"\n\ndef resolve_flask_csrf_validation_3725_10(subject_3725_10, policy_3725_10):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_3725_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_3725_10.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_3725_10.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_3725_10.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_de12c21d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_csrf_validation_3725_10)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-76e5b513edcce4a6","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9270_3 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_9270_3(request_9270_3, scope_9270_3):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9270_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9270_3.extractall(scope_9270_3)\n return scope_9270_3\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9270_3 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_9270_3(request_9270_3, scope_9270_3):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9270_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9270_3.extractall(scope_9270_3, filter=\"data\")\n return scope_9270_3\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_76e5b513_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_9270_3)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-71d8e8470b6277bb","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7261_25 = \"defensive\"\n\ndef load_http_response_splitting_7261_25(value_7261_25, target_7261_25):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7261_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_7261_25.headers[\"X-Next\"] = target_7261_25\n return value_7261_25\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7261_25 = \"defensive\"\n\ndef load_http_response_splitting_7261_25(value_7261_25, target_7261_25):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7261_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_7261_25 or \"\\n\" in target_7261_25:\n raise ValueError(\"invalid header value\")\n value_7261_25.headers[\"X-Next\"] = target_7261_25\n return value_7261_25\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_71d8e847_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_7261_25)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-ac206a15ec70ced9","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5626_15 = \"defensive\"\n\ndef handle_resource_consumption_5626_15(request_5626_15, policy_5626_15):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5626_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_5626_15.read(int(policy_5626_15))\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5626_15 = \"defensive\"\n\ndef handle_resource_consumption_5626_15(request_5626_15, policy_5626_15):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5626_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_5626_15), 1), 1_048_576)\n data = request_5626_15.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_ac206a15_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_5626_15)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-0786370903533546","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9747_4 = \"defensive\"\n\ndef load_django_error_details_9747_4(request_9747_4, context_9747_4):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9747_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_9747_4()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9747_4 = \"defensive\"\n\ndef load_django_error_details_9747_4(request_9747_4, context_9747_4):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9747_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_9747_4()\n except Exception:\n request_9747_4.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_07863709_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_9747_4)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-086f18c534c6165f","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8957_14 = \"defensive\"\n\ndef apply_hardcoded_credentials_8957_14(value_8957_14):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8957_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_8957_14)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8957_14 = \"defensive\"\n\ndef apply_hardcoded_credentials_8957_14(value_8957_14):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_8957_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_8957_14)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_086f18c5_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_8957_14)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-ee92b9a95453e841","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_1070_28 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_1070_28(value_1070_28, scope_1070_28, allowed_1070_28):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_1070_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_1070_28.get(scope_1070_28, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_1070_28 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_1070_28(value_1070_28, scope_1070_28, allowed_1070_28):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_1070_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_1070_28)\n if parsed.scheme != \"https\" or parsed.hostname not in set(allowed_1070_28):\n raise ValueError(\"destination is not allowed\")\n return value_1070_28.get(scope_1070_28, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_ee92b9a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_httpx_client_ssrf_1070_28)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-0be79cf47c6fd1b9","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8314_26 = \"defensive\"\n\ndef handle_path_traversal_8314_26(subject_8314_26, context_8314_26):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8314_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8314_26).resolve()\n candidate = (root / context_8314_26).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8314_26 = \"defensive\"\n\ndef handle_path_traversal_8314_26(subject_8314_26, context_8314_26):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8314_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8314_26).resolve()\n candidate = (root / context_8314_26).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_0be79cf4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_8314_26)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-aaa9526cedddede2","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_5527_26 = \"defensive\"\n\ndef resolve_csv_formula_injection_5527_26(subject_5527_26):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_5527_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_5527_26)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_5527_26 = \"defensive\"\n\ndef resolve_csv_formula_injection_5527_26(subject_5527_26):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_5527_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_5527_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_aaa9526c_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_5527_26)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-89ce358715b27ab7","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1491_5 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_1491_5(subject_1491_5, scope_1491_5, owner_1491_5):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1491_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_1491_5, scope_1491_5, algorithms=[\"HS256\"], audience=owner_1491_5)\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1491_5 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_1491_5(subject_1491_5, scope_1491_5, owner_1491_5):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1491_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_1491_5, scope_1491_5, algorithms=[\"HS256\"], audience=owner_1491_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_89ce3587_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_1491_5)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-a8c76170de221676","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_1061_25 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_1061_25(request_1061_25, context_1061_25):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_1061_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_1061_25.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_1061_25 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_1061_25(request_1061_25, context_1061_25):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_1061_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_1061_25 is None or not request_1061_25.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_1061_25.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_a8c76170_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_missing_authentication_1061_25)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-b31b92a6ab8bb23f","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_8391_9 = \"defensive\"\n\ndef handle_weak_cryptography_8391_9(payload_8391_9, context_8391_9):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_8391_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_8391_9.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_8391_9 = \"defensive\"\n\ndef handle_weak_cryptography_8391_9(payload_8391_9, context_8391_9):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_8391_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_8391_9.encode(\"utf-8\"), context_8391_9, 240000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_b31b92a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_8391_9)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-931adf43910e3cac","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_5853_29 = \"defensive\"\n\ndef resolve_regex_dos_5853_29(subject_5853_29, scope_5853_29):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_5853_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5853_29) > 256 or len(scope_5853_29) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_5853_29), scope_5853_29) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_5853_29 = \"defensive\"\n\ndef resolve_regex_dos_5853_29(subject_5853_29, scope_5853_29):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_5853_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5853_29) > 256 or len(scope_5853_29) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_5853_29), scope_5853_29) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_931adf43_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_regex_dos_5853_29)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-32bc79750eb92573","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_7998_4 = \"defensive\"\n\ndef process_dynamic_code_injection_7998_4(request_7998_4):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_7998_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_7998_4, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_7998_4 = \"defensive\"\n\ndef process_dynamic_code_injection_7998_4(request_7998_4):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_7998_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_7998_4) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_7998_4)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_32bc7975_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_7998_4)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-e6e680668d08e8cc","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_LOG_INJECTION_4937_20 = \"defensive\"\n\ndef load_log_injection_4937_20(request_4937_20, policy_4937_20):\n if HANDLER_KIND_LOAD_LOG_INJECTION_4937_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_4937_20).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_4937_20.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_LOG_INJECTION_4937_20 = \"defensive\"\n\ndef load_log_injection_4937_20(request_4937_20, policy_4937_20):\n if HANDLER_KIND_LOAD_LOG_INJECTION_4937_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_4937_20).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_4937_20.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_e6e68066_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_log_injection_4937_20)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-5e53a785f52c80db","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_1765_27 = \"defensive\"\n\ndef apply_command_injection_1765_27(value_1765_27, context_1765_27):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_1765_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {value_1765_27} {context_1765_27}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_1765_27 = \"defensive\"\n\ndef apply_command_injection_1765_27(value_1765_27, context_1765_27):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_1765_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_1765_27, context_1765_27], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_5e53a785_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_1765_27)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-5adb6043839fd448","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_8204_12 = \"defensive\"\n\ndef load_httpx_client_ssrf_8204_12(value_8204_12, scope_8204_12, limit_8204_12):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_8204_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_8204_12.get(scope_8204_12, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_8204_12 = \"defensive\"\n\ndef load_httpx_client_ssrf_8204_12(value_8204_12, scope_8204_12, limit_8204_12):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_8204_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_8204_12)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_8204_12):\n raise ValueError(\"destination is not allowed\")\n return value_8204_12.get(scope_8204_12, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_5adb6043_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_8204_12)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-aaa3d1e8b91c9e8b","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7183_23 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_7183_23(value_7183_23, target_7183_23):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7183_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7183_23.xpath(\"//user[@name=$account]\", account=target_7183_23)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7183_23 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_7183_23(value_7183_23, target_7183_23):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_7183_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7183_23.xpath(\"//user[@name=$account]\", account=target_7183_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_aaa3d1e8_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_7183_23)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-1857c0f6da5a3ea9","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_6697_14 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_6697_14(value_6697_14, policy_6697_14):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_6697_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6697_14.extractall(policy_6697_14, filter=\"data\")\n return policy_6697_14\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_6697_14 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_6697_14(value_6697_14, policy_6697_14):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_6697_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_6697_14.extractall(policy_6697_14, filter=\"data\")\n return policy_6697_14\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_1857c0f6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_6697_14)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-1c1de93b84d1447c","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_2557_8 = \"defensive\"\n\ndef process_requests_tls_verification_2557_8(subject_2557_8):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_2557_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_2557_8, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_2557_8 = \"defensive\"\n\ndef process_requests_tls_verification_2557_8(subject_2557_8):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_2557_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_2557_8, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_1c1de93b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_requests_tls_verification_2557_8)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-14d065656f906bc1","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_9063_22 = \"defensive\"\n\ndef handle_django_error_details_9063_22(request_9063_22, target_9063_22):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_9063_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_9063_22()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_9063_22 = \"defensive\"\n\ndef handle_django_error_details_9063_22(request_9063_22, target_9063_22):\n if HANDLER_KIND_HANDLE_DJANGO_ERROR_DETAILS_9063_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_9063_22()\n except Exception:\n request_9063_22.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_14d06565_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_error_details_9063_22)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-3451cb52818cd224","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_1745_16 = \"defensive\"\n\ndef apply_ldap_filter_injection_1745_16(payload_1745_16, policy_1745_16):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_1745_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={policy_1745_16})\"\n return payload_1745_16.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_1745_16 = \"defensive\"\n\ndef apply_ldap_filter_injection_1745_16(payload_1745_16, policy_1745_16):\n if HANDLER_KIND_APPLY_LDAP_FILTER_INJECTION_1745_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_1745_16)\n query = f\"(uid={escaped})\"\n return payload_1745_16.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_3451cb52_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ldap_filter_injection_1745_16)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-02fce6644ce5fd1d","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9060_0 = \"defensive\"\n\ndef apply_insecure_file_permissions_9060_0(subject_9060_0, policy_9060_0):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9060_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_9060_0).write_text(policy_9060_0, encoding=\"utf-8\")\n os.chmod(subject_9060_0, 0o777)\n return Path(subject_9060_0)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9060_0 = \"defensive\"\n\ndef apply_insecure_file_permissions_9060_0(subject_9060_0, policy_9060_0):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9060_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_9060_0).write_text(policy_9060_0, encoding=\"utf-8\")\n os.chmod(subject_9060_0, 0o600)\n return Path(subject_9060_0)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_02fce664_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_9060_0)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-b01c54af7fee9b38","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_SSRF_9752_0 = \"defensive\"\n\ndef load_ssrf_9752_0(payload_9752_0, context_9752_0):\n if HANDLER_KIND_LOAD_SSRF_9752_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_9752_0, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_9752_0 = \"defensive\"\n\ndef load_ssrf_9752_0(payload_9752_0, context_9752_0):\n if HANDLER_KIND_LOAD_SSRF_9752_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9752_0)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_9752_0):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_9752_0, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_b01c54af_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_9752_0)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-85268af18af09891","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_2039_29 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_2039_29(payload_2039_29, context_2039_29):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_2039_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_2039_29 is None or not payload_2039_29.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_2039_29.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_2039_29 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_2039_29(payload_2039_29, context_2039_29):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_2039_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_2039_29 is None or not payload_2039_29.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_2039_29.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_85268af1_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_2039_29)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-efe86c528f8497c9","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_1776_15 = \"defensive\"\n\ndef handle_insecure_temp_file_1776_15(value_1776_15, target_1776_15):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_1776_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{value_1776_15}.txt\")\n path.write_text(target_1776_15, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_1776_15 = \"defensive\"\n\ndef handle_insecure_temp_file_1776_15(value_1776_15, target_1776_15):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_1776_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(target_1776_15)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_efe86c52_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_temp_file_1776_15)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-0f27bdda42ff4fb2","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_4804_12 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_4804_12(request_4804_12, policy_4804_12):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_4804_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{policy_4804_12}']\"\n return request_4804_12.xpath(xpath)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_4804_12 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_4804_12(request_4804_12, policy_4804_12):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_4804_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4804_12.xpath(\"//user[@name=$account]\", account=policy_4804_12)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_0f27bdda_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_4804_12)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-dacf87677ccc4e34","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_9299_7 = \"defensive\"\n\ndef process_lxml_external_entity_9299_7(value_9299_7):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_9299_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_9299_7)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_9299_7 = \"defensive\"\n\ndef process_lxml_external_entity_9299_7(value_9299_7):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_9299_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_9299_7, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_dacf8767_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_external_entity_9299_7)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-cc85e9a285b9e884","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_2236_19 = \"defensive\"\n\ndef process_lxml_external_entity_2236_19(subject_2236_19):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_2236_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(subject_2236_19)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_2236_19 = \"defensive\"\n\ndef process_lxml_external_entity_2236_19(subject_2236_19):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_2236_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_2236_19, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_cc85e9a2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_external_entity_2236_19)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-866c3c43f521e83c","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5672_15 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5672_15(payload_5672_15):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5672_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_5672_15.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5672_15 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5672_15(payload_5672_15):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5672_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_5672_15.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_5672_15.size is None or payload_5672_15.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_5672_15.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_866c3c43_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_5672_15)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-3bc2babed4a1c461","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_3148_8 = \"defensive\"\n\ndef load_fastapi_upload_validation_3148_8(request_3148_8):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_3148_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_3148_8.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_3148_8.size is None or request_3148_8.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_3148_8.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_3148_8 = \"defensive\"\n\ndef load_fastapi_upload_validation_3148_8(request_3148_8):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_3148_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_3148_8.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_3148_8.size is None or request_3148_8.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_3148_8.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_3bc2babe_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_upload_validation_3148_8)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-0fc743ddc682ba9b","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_5332_26 = \"defensive\"\n\ndef process_zip_decompression_bomb_5332_26(request_5332_26, scope_5332_26):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_5332_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_5332_26.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_5332_26.extractall(scope_5332_26)\n return scope_5332_26\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_5332_26 = \"defensive\"\n\ndef process_zip_decompression_bomb_5332_26(request_5332_26, scope_5332_26):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_5332_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_5332_26.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_5332_26.extractall(scope_5332_26)\n return scope_5332_26\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_0fc743dd_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_5332_26)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-12d8c955b722ada4","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5844_7 = \"defensive\"\n\ndef process_csv_formula_injection_5844_7(value_5844_7):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5844_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_5844_7)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5844_7 = \"defensive\"\n\ndef process_csv_formula_injection_5844_7(value_5844_7):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5844_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_5844_7)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_12d8c955_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_5844_7)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-6200ed092d3d86f6","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9578_29 = \"defensive\"\n\ndef process_insecure_temp_file_9578_29(payload_9578_29, scope_9578_29):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9578_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_9578_29)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9578_29 = \"defensive\"\n\ndef process_insecure_temp_file_9578_29(payload_9578_29, scope_9578_29):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9578_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_9578_29)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_6200ed09_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_9578_29)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-62eb2e950889dc4e","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_4886_14 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_4886_14(value_4886_14, policy_4886_14):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_4886_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_4886_14 is None or not value_4886_14.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_4886_14.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_4886_14 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_4886_14(value_4886_14, policy_4886_14):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_4886_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_4886_14 is None or not value_4886_14.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_4886_14.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_62eb2e95_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_4886_14)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-8dfbc34ded0446a4","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9365_0 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_9365_0(payload_9365_0, target_9365_0):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9365_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9365_0.extractall(target_9365_0)\n return target_9365_0\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9365_0 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_9365_0(payload_9365_0, target_9365_0):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_9365_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9365_0.extractall(target_9365_0, filter=\"data\")\n return target_9365_0\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_8dfbc34d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_9365_0)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-2283c7a1dfd00527","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5532_20 = \"defensive\"\n\ndef load_sensitive_data_exposure_5532_20(request_5532_20, policy_5532_20, options_5532_20):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5532_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5532_20.info(\"login user=%s\", policy_5532_20)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5532_20 = \"defensive\"\n\ndef load_sensitive_data_exposure_5532_20(request_5532_20, policy_5532_20, options_5532_20):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5532_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5532_20.info(\"login user=%s\", policy_5532_20)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_2283c7a1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_5532_20)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-d4e1b0aa338fc3bd","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_5034_29 = \"defensive\"\n\ndef load_plaintext_password_storage_5034_29(subject_5034_29, policy_5034_29, options_5034_29):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_5034_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_5034_29) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_5034_29.encode(\"utf-8\"), options_5034_29, 240_000).hex()\n Path(subject_5034_29).write_text(verifier, encoding=\"ascii\")\n return Path(subject_5034_29)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_5034_29 = \"defensive\"\n\ndef load_plaintext_password_storage_5034_29(subject_5034_29, policy_5034_29, options_5034_29):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_5034_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_5034_29) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_5034_29.encode(\"utf-8\"), options_5034_29, 240_000).hex()\n Path(subject_5034_29).write_text(verifier, encoding=\"ascii\")\n return Path(subject_5034_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_d4e1b0aa_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_5034_29)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-2d0191c28afafdaa","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9402_9 = \"defensive\"\n\ndef load_csv_formula_injection_9402_9(subject_9402_9):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9402_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in subject_9402_9)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9402_9 = \"defensive\"\n\ndef load_csv_formula_injection_9402_9(subject_9402_9):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9402_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_9402_9)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_2d0191c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_9402_9)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-b335cabfdc8e23c9","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_8342_28 = \"defensive\"\n\ndef process_path_traversal_8342_28(value_8342_28, scope_8342_28):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_8342_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_8342_28) / scope_8342_28).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_8342_28 = \"defensive\"\n\ndef process_path_traversal_8342_28(value_8342_28, scope_8342_28):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_8342_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_8342_28).resolve()\n candidate = (root / scope_8342_28).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_b335cabf_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_8342_28)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-721569b8aea3800e","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3153_7 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_3153_7(subject_3153_7, policy_3153_7):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3153_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_3153_7}\")\n return subject_3153_7.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3153_7 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_3153_7(subject_3153_7, policy_3153_7):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_3153_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_3153_7.execute(statement, {\"account_id\": policy_3153_7}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_721569b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_3153_7)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-d3e6df3315d3cdf6","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3217_7 = \"defensive\"\n\ndef load_fastapi_missing_authentication_3217_7(subject_3217_7, context_3217_7):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3217_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_3217_7.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3217_7 = \"defensive\"\n\ndef load_fastapi_missing_authentication_3217_7(subject_3217_7, context_3217_7):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_3217_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_3217_7 is None or not subject_3217_7.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_3217_7.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_d3e6df33_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_3217_7)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-3cdd3d819f06d12d","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_1538_9 = \"defensive\"\n\ndef resolve_django_error_details_1538_9(subject_1538_9, scope_1538_9):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_1538_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_1538_9()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_1538_9 = \"defensive\"\n\ndef resolve_django_error_details_1538_9(subject_1538_9, scope_1538_9):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_1538_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_1538_9()\n except Exception:\n subject_1538_9.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_3cdd3d81_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_1538_9)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-e0de853501a70b70","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_9975_16 = \"defensive\"\n\ndef apply_httpx_client_ssrf_9975_16(payload_9975_16, policy_9975_16, allowed_9975_16):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_9975_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9975_16.get(policy_9975_16, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_9975_16 = \"defensive\"\n\ndef apply_httpx_client_ssrf_9975_16(payload_9975_16, policy_9975_16, allowed_9975_16):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_9975_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_9975_16)\n if parsed.scheme != \"https\" or parsed.hostname not in set(allowed_9975_16):\n raise ValueError(\"destination is not allowed\")\n return payload_9975_16.get(policy_9975_16, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_e0de8535_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_9975_16)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-a67fc9d1a1212329","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_7960_6 = \"defensive\"\n\ndef handle_log_injection_7960_6(request_7960_6, policy_7960_6):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_7960_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_7960_6.warning(\"audit=%s\", policy_7960_6)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_7960_6 = \"defensive\"\n\ndef handle_log_injection_7960_6(request_7960_6, policy_7960_6):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_7960_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_7960_6).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_7960_6.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_a67fc9d1_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_log_injection_7960_6)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-4111fe6f5176f9a5","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_8348_4 = \"defensive\"\n\ndef apply_starlette_permissive_cors_8348_4(subject_8348_4, context_8348_4):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_8348_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8348_4.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_8348_4\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_8348_4 = \"defensive\"\n\ndef apply_starlette_permissive_cors_8348_4(subject_8348_4, context_8348_4):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_8348_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_8348_4)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_8348_4.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_8348_4\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_4111fe6f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_8348_4)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-5e488364a961258f","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7764_18 = \"defensive\"\n\ndef apply_dynamic_code_injection_7764_18(request_7764_18):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7764_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_7764_18, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7764_18 = \"defensive\"\n\ndef apply_dynamic_code_injection_7764_18(request_7764_18):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7764_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_7764_18) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_7764_18)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_5e488364_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_7764_18)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-d5097f58f1a71336","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2634_27 = \"defensive\"\n\ndef process_log_injection_2634_27(payload_2634_27, target_2634_27):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2634_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2634_27.warning(\"audit=%s\", target_2634_27)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2634_27 = \"defensive\"\n\ndef process_log_injection_2634_27(payload_2634_27, target_2634_27):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2634_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_2634_27).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_2634_27.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_d5097f58_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_2634_27)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-7233fd3f524af779","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_6732_6 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_6732_6(subject_6732_6, scope_6732_6, allowed_6732_6):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_6732_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_6732_6, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_6732_6 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_6732_6(subject_6732_6, scope_6732_6, allowed_6732_6):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_6732_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_6732_6, scope_6732_6, algorithms=[\"HS256\"], audience=allowed_6732_6)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_7233fd3f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_6732_6)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-3bbad2bb0e6d2d8e","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_3896_8 = \"defensive\"\n\ndef handle_http_response_splitting_3896_8(value_3896_8, scope_3896_8):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_3896_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_3896_8 or \"\\n\" in scope_3896_8:\n raise ValueError(\"invalid header value\")\n value_3896_8.headers[\"X-Next\"] = scope_3896_8\n return value_3896_8\n","fixed_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_3896_8 = \"defensive\"\n\ndef handle_http_response_splitting_3896_8(value_3896_8, scope_3896_8):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_3896_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_3896_8 or \"\\n\" in scope_3896_8:\n raise ValueError(\"invalid header value\")\n value_3896_8.headers[\"X-Next\"] = scope_3896_8\n return value_3896_8\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_3bbad2bb_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_http_response_splitting_3896_8)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-ce20168178a2c39b","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_6871_26 = \"defensive\"\n\ndef handle_tarfile_path_traversal_6871_26(payload_6871_26, target_6871_26):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_6871_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_6871_26.extractall(target_6871_26, filter=\"data\")\n return target_6871_26\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_6871_26 = \"defensive\"\n\ndef handle_tarfile_path_traversal_6871_26(payload_6871_26, target_6871_26):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_6871_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_6871_26.extractall(target_6871_26, filter=\"data\")\n return target_6871_26\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_ce201681_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_6871_26)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-3b42358453a79448","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_8719_3 = \"defensive\"\n\ndef apply_flask_jinja_xss_8719_3(payload_8719_3):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_8719_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(payload_8719_3)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_8719_3 = \"defensive\"\n\ndef apply_flask_jinja_xss_8719_3(payload_8719_3):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_8719_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_8719_3)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_3b423584_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_8719_3)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-006c9c1413edecff","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_5478_19 = \"defensive\"\n\ndef resolve_flask_open_redirect_5478_19(payload_5478_19):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_5478_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(payload_5478_19)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_5478_19 = \"defensive\"\n\ndef resolve_flask_open_redirect_5478_19(payload_5478_19):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_5478_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_5478_19)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_5478_19)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_006c9c14_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_5478_19)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-7ce51795ba44e5cd","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4119_27 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_4119_27(subject_4119_27):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4119_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(subject_4119_27, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4119_27 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_4119_27(subject_4119_27):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_4119_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_4119_27)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_7ce51795_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyyaml_unsafe_load_4119_27)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-b7c6bb4e15bcfa2f","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4532_8 = \"defensive\"\n\ndef handle_dynamic_code_injection_4532_8(request_4532_8):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4532_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_4532_8) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_4532_8)\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4532_8 = \"defensive\"\n\ndef handle_dynamic_code_injection_4532_8(request_4532_8):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_4532_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_4532_8) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_4532_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_b7c6bb4e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_4532_8)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-4858d53fb7b41771","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1023_18 = \"defensive\"\n\ndef apply_flask_session_fixation_1023_18(subject_1023_18, scope_1023_18):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1023_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1023_18[\"user_id\"] = scope_1023_18.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1023_18 = \"defensive\"\n\ndef apply_flask_session_fixation_1023_18(subject_1023_18, scope_1023_18):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_1023_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1023_18.clear()\n subject_1023_18[\"user_id\"] = scope_1023_18.id\n subject_1023_18[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_4858d53f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_1023_18)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-64a4edad66b96daf","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_7807_3 = \"defensive\"\n\ndef load_flask_session_fixation_7807_3(payload_7807_3, context_7807_3):\n if HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_7807_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7807_3[\"user_id\"] = context_7807_3.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_7807_3 = \"defensive\"\n\ndef load_flask_session_fixation_7807_3(payload_7807_3, context_7807_3):\n if HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_7807_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7807_3.clear()\n payload_7807_3[\"user_id\"] = context_7807_3.id\n payload_7807_3[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_64a4edad_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_session_fixation_7807_3)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-6581d1800c75bc01","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_1568_25 = \"defensive\"\n\ndef resolve_path_traversal_1568_25(value_1568_25, target_1568_25):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_1568_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_1568_25) / target_1568_25).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_1568_25 = \"defensive\"\n\ndef resolve_path_traversal_1568_25(value_1568_25, target_1568_25):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_1568_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_1568_25).resolve()\n candidate = (root / target_1568_25).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_6581d180_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_path_traversal_1568_25)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a3a64fee87a0933f","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9447_5 = \"defensive\"\n\ndef resolve_sql_injection_9447_5(payload_9447_5, target_9447_5):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9447_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9447_5.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9447_5,)).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9447_5 = \"defensive\"\n\ndef resolve_sql_injection_9447_5(payload_9447_5, target_9447_5):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9447_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9447_5.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9447_5,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_a3a64fee_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_9447_5)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-96bed29d3b660082","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_9166_20 = \"defensive\"\n\ndef apply_dynamic_code_injection_9166_20(payload_9166_20):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_9166_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_9166_20) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_9166_20)\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_9166_20 = \"defensive\"\n\ndef apply_dynamic_code_injection_9166_20(payload_9166_20):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_9166_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_9166_20) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_9166_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_96bed29d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_9166_20)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-d45c3ea4d69fd695","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7412_11 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7412_11(value_7412_11, target_7412_11):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7412_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_7412_11)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_7412_11.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_7412_11\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7412_11 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7412_11(value_7412_11, target_7412_11):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7412_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_7412_11)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_7412_11.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_7412_11\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_d45c3ea4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_7412_11)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-60505e8cdd5b222c","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3971_25 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_3971_25(payload_3971_25, scope_3971_25, allowed_3971_25):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3971_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_3971_25, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3971_25 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_3971_25(payload_3971_25, scope_3971_25, allowed_3971_25):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3971_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_3971_25, scope_3971_25, algorithms=[\"HS256\"], audience=allowed_3971_25)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_60505e8c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_3971_25)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-de08f094fdd3625a","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_8762_10 = \"defensive\"\n\ndef apply_flask_jinja_xss_8762_10(request_8762_10):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_8762_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_8762_10)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_8762_10 = \"defensive\"\n\ndef apply_flask_jinja_xss_8762_10(request_8762_10):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_8762_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_8762_10)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_de08f094_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_8762_10)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-1f4dd54e409e5ea6","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_4368_18 = \"defensive\"\n\ndef process_fastapi_upload_validation_4368_18(request_4368_18):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_4368_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4368_18.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_4368_18 = \"defensive\"\n\ndef process_fastapi_upload_validation_4368_18(request_4368_18):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_4368_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_4368_18.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_4368_18.size is None or request_4368_18.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_4368_18.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_1f4dd54e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_4368_18)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-b81622a93a5a31b6","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8890_1 = \"defensive\"\n\ndef resolve_mass_assignment_8890_1(subject_8890_1, policy_8890_1):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8890_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_8890_1.items():\n setattr(subject_8890_1, key, value)\n return subject_8890_1\n","fixed_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8890_1 = \"defensive\"\n\ndef resolve_mass_assignment_8890_1(subject_8890_1, policy_8890_1):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8890_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_8890_1.items() if key in allowed_fields}\n subject_8890_1.update(safe)\n return subject_8890_1\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_b81622a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_mass_assignment_8890_1)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-c4e75448503deb05","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6135_9 = \"defensive\"\n\ndef handle_plaintext_password_storage_6135_9(value_6135_9, scope_6135_9, limit_6135_9):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6135_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_6135_9).write_text(scope_6135_9, encoding=\"utf-8\")\n return Path(value_6135_9)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6135_9 = \"defensive\"\n\ndef handle_plaintext_password_storage_6135_9(value_6135_9, scope_6135_9, limit_6135_9):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6135_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_6135_9) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_6135_9.encode(\"utf-8\"), limit_6135_9, 240_000).hex()\n Path(value_6135_9).write_text(verifier, encoding=\"ascii\")\n return Path(value_6135_9)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_c4e75448_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_6135_9)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-a904e216c25d7d82","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2761_11 = \"defensive\"\n\ndef apply_flask_session_fixation_2761_11(request_2761_11, target_2761_11):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2761_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2761_11.clear()\n request_2761_11[\"user_id\"] = target_2761_11.id\n request_2761_11[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2761_11 = \"defensive\"\n\ndef apply_flask_session_fixation_2761_11(request_2761_11, target_2761_11):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2761_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2761_11.clear()\n request_2761_11[\"user_id\"] = target_2761_11.id\n request_2761_11[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_a904e216_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_2761_11)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-c589c1bde9209dca","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_8388_12 = \"defensive\"\n\ndef process_fastapi_missing_authentication_8388_12(value_8388_12, policy_8388_12):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_8388_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return policy_8388_12.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_8388_12 = \"defensive\"\n\ndef process_fastapi_missing_authentication_8388_12(value_8388_12, policy_8388_12):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_8388_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_8388_12 is None or not value_8388_12.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_8388_12.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_c589c1bd_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_8388_12)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-cea9d2b7c8355364","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_9824_1 = \"defensive\"\n\ndef handle_flask_jinja_xss_9824_1(value_9824_1):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_9824_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_9824_1)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_9824_1 = \"defensive\"\n\ndef handle_flask_jinja_xss_9824_1(value_9824_1):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_9824_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_9824_1)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_cea9d2b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_jinja_xss_9824_1)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-fae40cd56f6f14bc","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7698_17 = \"defensive\"\n\ndef process_lxml_xpath_injection_7698_17(value_7698_17, scope_7698_17):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7698_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7698_17.xpath(\"//user[@name=$account]\", account=scope_7698_17)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7698_17 = \"defensive\"\n\ndef process_lxml_xpath_injection_7698_17(value_7698_17, scope_7698_17):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7698_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7698_17.xpath(\"//user[@name=$account]\", account=scope_7698_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_fae40cd5_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_7698_17)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-804e0e86f6031572","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5145_24 = \"defensive\"\n\ndef handle_dynamic_code_injection_5145_24(subject_5145_24):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5145_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_5145_24, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5145_24 = \"defensive\"\n\ndef handle_dynamic_code_injection_5145_24(subject_5145_24):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5145_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5145_24) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_5145_24)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_804e0e86_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_5145_24)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-1a179bdd2d4ac56d","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3922_24 = \"defensive\"\n\ndef handle_httpx_client_ssrf_3922_24(value_3922_24, target_3922_24, owner_3922_24):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3922_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_3922_24.get(target_3922_24, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3922_24 = \"defensive\"\n\ndef handle_httpx_client_ssrf_3922_24(value_3922_24, target_3922_24, owner_3922_24):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3922_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_3922_24)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3922_24):\n raise ValueError(\"destination is not allowed\")\n return value_3922_24.get(target_3922_24, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_1a179bdd_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_httpx_client_ssrf_3922_24)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-7daea7a9aacf21fc","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7701_8 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7701_8(request_7701_8, policy_7701_8):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7701_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_7701_8)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_7701_8.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_7701_8\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7701_8 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7701_8(request_7701_8, policy_7701_8):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7701_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_7701_8)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_7701_8.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_7701_8\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_7daea7a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_7701_8)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-50ac8d898bd7353d","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_6371_14 = \"defensive\"\n\ndef handle_command_injection_6371_14(request_6371_14, scope_6371_14):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_6371_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_6371_14, scope_6371_14], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_6371_14 = \"defensive\"\n\ndef handle_command_injection_6371_14(request_6371_14, scope_6371_14):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_6371_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_6371_14, scope_6371_14], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_50ac8d89_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_6371_14)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-08e4bfa1f5d9b010","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_8046_24 = \"defensive\"\n\ndef handle_fastapi_upload_validation_8046_24(subject_8046_24):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_8046_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8046_24.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_8046_24 = \"defensive\"\n\ndef handle_fastapi_upload_validation_8046_24(subject_8046_24):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_8046_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_8046_24.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_8046_24.size is None or subject_8046_24.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_8046_24.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_08e4bfa1_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_8046_24)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-4e7ab6dd198bde0d","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_4493_18 = \"defensive\"\n\ndef process_fastapi_missing_authentication_4493_18(subject_4493_18, policy_4493_18):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_4493_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return policy_4493_18.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_4493_18 = \"defensive\"\n\ndef process_fastapi_missing_authentication_4493_18(subject_4493_18, policy_4493_18):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_4493_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_4493_18 is None or not subject_4493_18.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_4493_18.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_4e7ab6dd_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_4493_18)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-40af6836b33296d0","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_4253_14 = \"defensive\"\n\ndef apply_flask_jinja_xss_4253_14(payload_4253_14):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_4253_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_4253_14)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_4253_14 = \"defensive\"\n\ndef apply_flask_jinja_xss_4253_14(payload_4253_14):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_4253_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_4253_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_40af6836_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_4253_14)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-6c2a333856395524","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4723_9 = \"defensive\"\n\ndef process_flask_jinja_xss_4723_9(request_4723_9):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4723_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_4723_9)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4723_9 = \"defensive\"\n\ndef process_flask_jinja_xss_4723_9(request_4723_9):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4723_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_4723_9)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_6c2a3338_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_4723_9)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-52ceb0550592a85a","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_1833_26 = \"defensive\"\n\ndef process_django_safe_string_xss_1833_26(request_1833_26):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_1833_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_1833_26)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_1833_26 = \"defensive\"\n\ndef process_django_safe_string_xss_1833_26(request_1833_26):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_1833_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_1833_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_52ceb055_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_safe_string_xss_1833_26)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-7dfaeab7260a4a14","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6278_7 = \"defensive\"\n\ndef load_insecure_random_token_6278_7(request_6278_7):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6278_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_6278_7)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6278_7 = \"defensive\"\n\ndef load_insecure_random_token_6278_7(request_6278_7):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6278_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_6278_7)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_7dfaeab7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_random_token_6278_7)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-be53d6994b5b9327","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3554_22 = \"defensive\"\n\ndef handle_httpx_client_ssrf_3554_22(subject_3554_22, scope_3554_22, options_3554_22):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3554_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3554_22.get(scope_3554_22, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3554_22 = \"defensive\"\n\ndef handle_httpx_client_ssrf_3554_22(subject_3554_22, scope_3554_22, options_3554_22):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_3554_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_3554_22)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_3554_22):\n raise ValueError(\"destination is not allowed\")\n return subject_3554_22.get(scope_3554_22, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_be53d699_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_httpx_client_ssrf_3554_22)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-33f7410f6291d8e9","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_5492_11 = \"defensive\"\n\ndef process_requests_tls_verification_5492_11(payload_5492_11):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_5492_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_5492_11, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_5492_11 = \"defensive\"\n\ndef process_requests_tls_verification_5492_11(payload_5492_11):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_5492_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_5492_11, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_33f7410f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_requests_tls_verification_5492_11)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-624defeab4b848f6","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_8009_10 = \"defensive\"\n\ndef process_regex_dos_8009_10(payload_8009_10, target_8009_10):\n if HANDLER_KIND_PROCESS_REGEX_DOS_8009_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_8009_10, target_8009_10) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_8009_10 = \"defensive\"\n\ndef process_regex_dos_8009_10(payload_8009_10, target_8009_10):\n if HANDLER_KIND_PROCESS_REGEX_DOS_8009_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_8009_10) > 256 or len(target_8009_10) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_8009_10), target_8009_10) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_624defea_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_8009_10)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-6d5de1e3b3641d94","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_7501_21 = \"defensive\"\n\ndef handle_lxml_xpath_injection_7501_21(value_7501_21, scope_7501_21):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_7501_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_7501_21}']\"\n return value_7501_21.xpath(xpath)\n","fixed_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_7501_21 = \"defensive\"\n\ndef handle_lxml_xpath_injection_7501_21(value_7501_21, scope_7501_21):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_7501_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7501_21.xpath(\"//user[@name=$account]\", account=scope_7501_21)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_6d5de1e3_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_xpath_injection_7501_21)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-f5cba636461d8bec","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2879_28 = \"defensive\"\n\ndef apply_fastapi_upload_validation_2879_28(value_2879_28):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2879_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_2879_28.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2879_28 = \"defensive\"\n\ndef apply_fastapi_upload_validation_2879_28(value_2879_28):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2879_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_2879_28.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_2879_28.size is None or value_2879_28.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_2879_28.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_f5cba636_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_upload_validation_2879_28)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-d0233eb4422ebfd4","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_5795_22 = \"defensive\"\n\ndef load_flask_jinja_xss_5795_22(request_5795_22):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_5795_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_5795_22)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_5795_22 = \"defensive\"\n\ndef load_flask_jinja_xss_5795_22(request_5795_22):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_5795_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_5795_22)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_d0233eb4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_jinja_xss_5795_22)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-90b8fda6ecb4e59f","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_3329_8 = \"defensive\"\n\ndef apply_unsafe_deserialization_3329_8(subject_3329_8):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_3329_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_3329_8.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_3329_8 = \"defensive\"\n\ndef apply_unsafe_deserialization_3329_8(subject_3329_8):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_3329_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_3329_8.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_90b8fda6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_unsafe_deserialization_3329_8)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-2714ddfcf6f66b59","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5178_2 = \"defensive\"\n\ndef process_dynamic_code_injection_5178_2(value_5178_2):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5178_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_5178_2) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(value_5178_2)\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5178_2 = \"defensive\"\n\ndef process_dynamic_code_injection_5178_2(value_5178_2):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5178_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_5178_2) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(value_5178_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_2714ddfc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_5178_2)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-4db57bbfce3a30cc","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7953_11 = \"defensive\"\n\ndef handle_django_safe_string_xss_7953_11(request_7953_11):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7953_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_7953_11)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7953_11 = \"defensive\"\n\ndef handle_django_safe_string_xss_7953_11(request_7953_11):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_7953_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_7953_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_4db57bbf_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_7953_11)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-7b659171f3c047e9","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_7224_15 = \"defensive\"\n\ndef apply_zip_decompression_bomb_7224_15(request_7224_15, context_7224_15):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_7224_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_7224_15.extractall(context_7224_15)\n return context_7224_15\n","fixed_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_7224_15 = \"defensive\"\n\ndef apply_zip_decompression_bomb_7224_15(request_7224_15, context_7224_15):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_7224_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_7224_15.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_7224_15.extractall(context_7224_15)\n return context_7224_15\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_7b659171_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_zip_decompression_bomb_7224_15)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-c5d94d35122d08e5","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_1213_12 = \"defensive\"\n\ndef handle_insecure_file_permissions_1213_12(payload_1213_12, target_1213_12):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_1213_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1213_12).write_text(target_1213_12, encoding=\"utf-8\")\n os.chmod(payload_1213_12, 0o777)\n return Path(payload_1213_12)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_1213_12 = \"defensive\"\n\ndef handle_insecure_file_permissions_1213_12(payload_1213_12, target_1213_12):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_1213_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1213_12).write_text(target_1213_12, encoding=\"utf-8\")\n os.chmod(payload_1213_12, 0o600)\n return Path(payload_1213_12)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_c5d94d35_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_1213_12)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-07e347448dd31422","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_4641_29 = \"defensive\"\n\ndef resolve_cleartext_http_transport_4641_29(request_4641_29):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_4641_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=request_4641_29, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_4641_29 = \"defensive\"\n\ndef resolve_cleartext_http_transport_4641_29(request_4641_29):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_4641_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=request_4641_29, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_07e34744_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_cleartext_http_transport_4641_29)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-b6891ef090d1e62d","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_3819_21 = \"defensive\"\n\ndef apply_flask_csrf_validation_3819_21(value_3819_21, scope_3819_21):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_3819_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_3819_21.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_3819_21 = \"defensive\"\n\ndef apply_flask_csrf_validation_3819_21(value_3819_21, scope_3819_21):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_3819_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_3819_21.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_3819_21.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_3819_21.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_b6891ef0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_csrf_validation_3819_21)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-1d8d812f09de7156","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_1489_8 = \"defensive\"\n\ndef apply_hardcoded_credentials_1489_8(value_1489_8):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_1489_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_1489_8)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_1489_8 = \"defensive\"\n\ndef apply_hardcoded_credentials_1489_8(value_1489_8):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_1489_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_1489_8)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_1d8d812f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_1489_8)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-6918a84d35942785","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2785_17 = \"defensive\"\n\ndef apply_flask_csrf_validation_2785_17(subject_2785_17, target_2785_17):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2785_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_2785_17.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_2785_17.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_2785_17.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2785_17 = \"defensive\"\n\ndef apply_flask_csrf_validation_2785_17(subject_2785_17, target_2785_17):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2785_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_2785_17.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_2785_17.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_2785_17.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_6918a84d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_csrf_validation_2785_17)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-8afa896a49276457","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_8427_3 = \"defensive\"\n\ndef apply_cleartext_http_transport_8427_3(payload_8427_3):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_8427_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_8427_3, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_8427_3 = \"defensive\"\n\ndef apply_cleartext_http_transport_8427_3(payload_8427_3):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_8427_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_8427_3, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_8afa896a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_8427_3)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-2547ba6ea1afca6b","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_6610_22 = \"defensive\"\n\ndef apply_path_traversal_6610_22(subject_6610_22, context_6610_22):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_6610_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(subject_6610_22) / context_6610_22).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_6610_22 = \"defensive\"\n\ndef apply_path_traversal_6610_22(subject_6610_22, context_6610_22):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_6610_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_6610_22).resolve()\n candidate = (root / context_6610_22).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_2547ba6e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_6610_22)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-2bb2c143a2fea7b9","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_1645_27 = \"defensive\"\n\ndef resolve_requests_tls_verification_1645_27(subject_1645_27):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_1645_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_1645_27, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_1645_27 = \"defensive\"\n\ndef resolve_requests_tls_verification_1645_27(subject_1645_27):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_1645_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_1645_27, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_2bb2c143_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_requests_tls_verification_1645_27)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-a380cedaae57bf9f","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4253_3 = \"defensive\"\n\ndef handle_flask_csrf_validation_4253_3(subject_4253_3, context_4253_3):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4253_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_4253_3.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4253_3 = \"defensive\"\n\ndef handle_flask_csrf_validation_4253_3(subject_4253_3, context_4253_3):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4253_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_4253_3.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_4253_3.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_4253_3.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_a380ceda_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_4253_3)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-444ea4b9bc05b181","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_8274_7 = \"defensive\"\n\ndef apply_command_injection_8274_7(subject_8274_7, scope_8274_7):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_8274_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_8274_7} {scope_8274_7}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_8274_7 = \"defensive\"\n\ndef apply_command_injection_8274_7(subject_8274_7, scope_8274_7):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_8274_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_8274_7, scope_8274_7], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_444ea4b9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_8274_7)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-a38750f99e059c15","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_3965_26 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_3965_26(value_3965_26, scope_3965_26):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_3965_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_3965_26)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3965_26.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3965_26\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_3965_26 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_3965_26(value_3965_26, scope_3965_26):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_3965_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_3965_26)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3965_26.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3965_26\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_a38750f9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_3965_26)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-0564123082219e68","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5795_9 = \"defensive\"\n\ndef handle_resource_consumption_5795_9(value_5795_9, policy_5795_9):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5795_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5795_9.read(int(policy_5795_9))\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5795_9 = \"defensive\"\n\ndef handle_resource_consumption_5795_9(value_5795_9, policy_5795_9):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_5795_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_5795_9), 1), 1_048_576)\n data = value_5795_9.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_05641230_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_5795_9)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-6c49f458dc13be52","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7457_11 = \"defensive\"\n\ndef resolve_django_error_details_7457_11(payload_7457_11, target_7457_11):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7457_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7457_11()\n except Exception:\n payload_7457_11.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7457_11 = \"defensive\"\n\ndef resolve_django_error_details_7457_11(payload_7457_11, target_7457_11):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_7457_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7457_11()\n except Exception:\n payload_7457_11.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_6c49f458_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_7457_11)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-29d8109798664997","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_7218_24 = \"defensive\"\n\ndef apply_requests_tls_verification_7218_24(request_7218_24):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_7218_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_7218_24, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_7218_24 = \"defensive\"\n\ndef apply_requests_tls_verification_7218_24(request_7218_24):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_7218_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_7218_24, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_29d81097_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_7218_24)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-303c5dfb55238c15","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_3588_0 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_3588_0(value_3588_0, policy_3588_0):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_3588_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{policy_3588_0}']\"\n return value_3588_0.xpath(xpath)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_3588_0 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_3588_0(value_3588_0, policy_3588_0):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_3588_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_3588_0.xpath(\"//user[@name=$account]\", account=policy_3588_0)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_303c5dfb_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_3588_0)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-83d27d5b3d317261","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_6309_19 = \"defensive\"\n\ndef process_regex_dos_6309_19(request_6309_19, policy_6309_19):\n if HANDLER_KIND_PROCESS_REGEX_DOS_6309_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(request_6309_19, policy_6309_19) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_6309_19 = \"defensive\"\n\ndef process_regex_dos_6309_19(request_6309_19, policy_6309_19):\n if HANDLER_KIND_PROCESS_REGEX_DOS_6309_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_6309_19) > 256 or len(policy_6309_19) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(request_6309_19), policy_6309_19) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_83d27d5b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_6309_19)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-142d3f956f386631","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2688_24 = \"defensive\"\n\ndef load_django_safe_string_xss_2688_24(subject_2688_24):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2688_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{subject_2688_24}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2688_24 = \"defensive\"\n\ndef load_django_safe_string_xss_2688_24(subject_2688_24):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2688_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_2688_24)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_142d3f95_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_2688_24)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-124bc8604a5f1a20","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_1544_11 = \"defensive\"\n\ndef resolve_flask_jinja_xss_1544_11(value_1544_11):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_1544_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_1544_11)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_1544_11 = \"defensive\"\n\ndef resolve_flask_jinja_xss_1544_11(value_1544_11):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_1544_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_1544_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_124bc860_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_1544_11)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-55cc631ddc3f7bcc","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8905_7 = \"defensive\"\n\ndef load_cleartext_http_transport_8905_7(value_8905_7):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8905_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_8905_7, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8905_7 = \"defensive\"\n\ndef load_cleartext_http_transport_8905_7(value_8905_7):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8905_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_8905_7, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_55cc631d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_8905_7)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-384bc6e61ec2710e","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1455_3 = \"defensive\"\n\ndef apply_insecure_temp_file_1455_3(request_1455_3, scope_1455_3):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1455_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{request_1455_3}.txt\")\n path.write_text(scope_1455_3, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1455_3 = \"defensive\"\n\ndef apply_insecure_temp_file_1455_3(request_1455_3, scope_1455_3):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_1455_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_1455_3)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_384bc6e6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_1455_3)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-b0942a6139d99c95","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6564_9 = \"defensive\"\n\ndef apply_flask_open_redirect_6564_9(value_6564_9):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6564_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_6564_9)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6564_9 = \"defensive\"\n\ndef apply_flask_open_redirect_6564_9(value_6564_9):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6564_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_6564_9)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_6564_9)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_b0942a61_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_open_redirect_6564_9)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-eb6a8680b4d001b5","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_6549_2 = \"defensive\"\n\ndef apply_lxml_xpath_injection_6549_2(request_6549_2, target_6549_2):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_6549_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_6549_2.xpath(\"//user[@name=$account]\", account=target_6549_2)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_6549_2 = \"defensive\"\n\ndef apply_lxml_xpath_injection_6549_2(request_6549_2, target_6549_2):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_6549_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_6549_2.xpath(\"//user[@name=$account]\", account=target_6549_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_eb6a8680_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_6549_2)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-8753fa89ee838ad7","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2909_6 = \"defensive\"\n\ndef apply_insecure_file_permissions_2909_6(value_2909_6, context_2909_6):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2909_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_2909_6).write_text(context_2909_6, encoding=\"utf-8\")\n os.chmod(value_2909_6, 0o777)\n return Path(value_2909_6)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2909_6 = \"defensive\"\n\ndef apply_insecure_file_permissions_2909_6(value_2909_6, context_2909_6):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2909_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_2909_6).write_text(context_2909_6, encoding=\"utf-8\")\n os.chmod(value_2909_6, 0o600)\n return Path(value_2909_6)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_8753fa89_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_2909_6)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-3333c4e9ca5d9dbf","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7675_24 = \"defensive\"\n\ndef apply_django_error_details_7675_24(subject_7675_24, target_7675_24):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7675_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7675_24()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7675_24 = \"defensive\"\n\ndef apply_django_error_details_7675_24(subject_7675_24, target_7675_24):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7675_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7675_24()\n except Exception:\n subject_7675_24.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_3333c4e9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_7675_24)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-557adb56e374e50a","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_4243_12 = \"defensive\"\n\ndef handle_command_injection_4243_12(payload_4243_12, scope_4243_12):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_4243_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_4243_12} {scope_4243_12}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_4243_12 = \"defensive\"\n\ndef handle_command_injection_4243_12(payload_4243_12, scope_4243_12):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_4243_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_4243_12, scope_4243_12], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_557adb56_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_4243_12)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-7c520a6a216d9841","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4341_8 = \"defensive\"\n\ndef load_fastapi_missing_authentication_4341_8(subject_4341_8, target_4341_8):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4341_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_4341_8 is None or not subject_4341_8.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_4341_8.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4341_8 = \"defensive\"\n\ndef load_fastapi_missing_authentication_4341_8(subject_4341_8, target_4341_8):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4341_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_4341_8 is None or not subject_4341_8.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_4341_8.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_7c520a6a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_4341_8)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-f5099b9772952bcf","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_4902_25 = \"defensive\"\n\ndef resolve_dynamic_code_injection_4902_25(payload_4902_25):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_4902_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(payload_4902_25, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_4902_25 = \"defensive\"\n\ndef resolve_dynamic_code_injection_4902_25(payload_4902_25):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_4902_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_4902_25) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_4902_25)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_f5099b97_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_dynamic_code_injection_4902_25)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-f23945511356ea0e","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_6217_14 = \"defensive\"\n\ndef resolve_lxml_external_entity_6217_14(value_6217_14):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_6217_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_6217_14, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_6217_14 = \"defensive\"\n\ndef resolve_lxml_external_entity_6217_14(value_6217_14):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_6217_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_6217_14, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_f2394551_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_6217_14)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-44bfc735d2ddb338","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_4400_11 = \"defensive\"\n\ndef apply_ssrf_4400_11(subject_4400_11, policy_4400_11):\n if HANDLER_KIND_APPLY_SSRF_4400_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4400_11)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_4400_11):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_4400_11, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_4400_11 = \"defensive\"\n\ndef apply_ssrf_4400_11(subject_4400_11, policy_4400_11):\n if HANDLER_KIND_APPLY_SSRF_4400_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4400_11)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_4400_11):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_4400_11, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_44bfc735_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_4400_11)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-d00aa90b357c48da","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7248_8 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_7248_8(subject_7248_8, policy_7248_8, options_7248_8):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7248_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7248_8.info(\"login user=%s\", policy_7248_8)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7248_8 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_7248_8(subject_7248_8, policy_7248_8, options_7248_8):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7248_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7248_8.info(\"login user=%s\", policy_7248_8)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_d00aa90b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sensitive_data_exposure_7248_8)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-c2cfa870d74f1739","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_1088_29 = \"defensive\"\n\ndef apply_command_injection_1088_29(value_1088_29, policy_1088_29):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_1088_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_1088_29, policy_1088_29], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_1088_29 = \"defensive\"\n\ndef apply_command_injection_1088_29(value_1088_29, policy_1088_29):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_1088_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_1088_29, policy_1088_29], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_c2cfa870_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_1088_29)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-6f724eda6e608a55","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9449_26 = \"defensive\"\n\ndef handle_lxml_external_entity_9449_26(subject_9449_26):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9449_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_9449_26, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9449_26 = \"defensive\"\n\ndef handle_lxml_external_entity_9449_26(subject_9449_26):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9449_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_9449_26, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_6f724eda_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_9449_26)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-fdac3b31707e97a1","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4547_13 = \"defensive\"\n\ndef process_flask_jinja_xss_4547_13(subject_4547_13):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4547_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(subject_4547_13)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4547_13 = \"defensive\"\n\ndef process_flask_jinja_xss_4547_13(subject_4547_13):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_4547_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(subject_4547_13)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_fdac3b31_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_4547_13)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-6d25cb1c5d7c7eef","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_9197_7 = \"defensive\"\n\ndef apply_missing_authorization_9197_7(payload_9197_7, scope_9197_7):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_9197_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n scope_9197_7.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_9197_7 = \"defensive\"\n\ndef apply_missing_authorization_9197_7(payload_9197_7, scope_9197_7):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_9197_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_9197_7.id != scope_9197_7.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_9197_7.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_6d25cb1c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_9197_7)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-bc607c80689886d4","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9856_5 = \"defensive\"\n\ndef load_csv_formula_injection_9856_5(subject_9856_5):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9856_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_9856_5)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9856_5 = \"defensive\"\n\ndef load_csv_formula_injection_9856_5(subject_9856_5):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_9856_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_9856_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_bc607c80_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_9856_5)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-6740378a01c24637","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_7066_29 = \"defensive\"\n\ndef load_django_error_details_7066_29(value_7066_29, scope_7066_29):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_7066_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_7066_29()\n except Exception:\n value_7066_29.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_7066_29 = \"defensive\"\n\ndef load_django_error_details_7066_29(value_7066_29, scope_7066_29):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_7066_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return scope_7066_29()\n except Exception:\n value_7066_29.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_6740378a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_7066_29)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-c47e14f7a013c2f3","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5214_13 = \"defensive\"\n\ndef process_log_injection_5214_13(value_5214_13, scope_5214_13):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5214_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5214_13.warning(\"audit=%s\", scope_5214_13)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5214_13 = \"defensive\"\n\ndef process_log_injection_5214_13(value_5214_13, scope_5214_13):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5214_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_5214_13).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_5214_13.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_c47e14f7_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_5214_13)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-70e86e6d450363d1","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2752_9 = \"defensive\"\n\ndef load_django_safe_string_xss_2752_9(request_2752_9):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2752_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{request_2752_9}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2752_9 = \"defensive\"\n\ndef load_django_safe_string_xss_2752_9(request_2752_9):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2752_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_2752_9)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_70e86e6d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_2752_9)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-347c1cb5400ec653","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4677_10 = \"defensive\"\n\ndef resolve_resource_consumption_4677_10(subject_4677_10, scope_4677_10):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4677_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_4677_10.read(int(scope_4677_10))\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4677_10 = \"defensive\"\n\ndef resolve_resource_consumption_4677_10(subject_4677_10, scope_4677_10):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_4677_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_4677_10), 1), 1_048_576)\n data = subject_4677_10.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_347c1cb5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_4677_10)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-280bbc71bc7fb4c3","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3472_5 = \"defensive\"\n\ndef resolve_dynamic_code_injection_3472_5(request_3472_5):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3472_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_3472_5) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_3472_5)\n","fixed_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3472_5 = \"defensive\"\n\ndef resolve_dynamic_code_injection_3472_5(request_3472_5):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3472_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_3472_5) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_3472_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_280bbc71_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_dynamic_code_injection_3472_5)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-3fc795eea98c592a","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4257_3 = \"defensive\"\n\ndef process_mass_assignment_4257_3(request_4257_3, target_4257_3):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4257_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in target_4257_3.items():\n setattr(request_4257_3, key, value)\n return request_4257_3\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4257_3 = \"defensive\"\n\ndef process_mass_assignment_4257_3(request_4257_3, target_4257_3):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4257_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_4257_3.items() if key in allowed_fields}\n request_4257_3.update(safe)\n return request_4257_3\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_3fc795ee_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_4257_3)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-0317b959d43c4792","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_6015_7 = \"defensive\"\n\ndef load_weak_cryptography_6015_7(value_6015_7, policy_6015_7):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_6015_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(value_6015_7.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_6015_7 = \"defensive\"\n\ndef load_weak_cryptography_6015_7(value_6015_7, policy_6015_7):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_6015_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_6015_7.encode(\"utf-8\"), policy_6015_7, 220000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_0317b959_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_6015_7)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-4328eefadee286a9","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9378_23 = \"defensive\"\n\ndef resolve_insecure_random_token_9378_23(payload_9378_23):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9378_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_9378_23)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9378_23 = \"defensive\"\n\ndef resolve_insecure_random_token_9378_23(payload_9378_23):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9378_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_9378_23)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_4328eefa_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_random_token_9378_23)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-03a08a8fa582aea9","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9559_6 = \"defensive\"\n\ndef resolve_cleartext_http_transport_9559_6(subject_9559_6):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9559_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=subject_9559_6, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9559_6 = \"defensive\"\n\ndef resolve_cleartext_http_transport_9559_6(subject_9559_6):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9559_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_9559_6, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_03a08a8f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_cleartext_http_transport_9559_6)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-ffc53a6600a491f1","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_2827_14 = \"defensive\"\n\ndef load_ssrf_2827_14(subject_2827_14, scope_2827_14):\n if HANDLER_KIND_LOAD_SSRF_2827_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_2827_14)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_2827_14):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_2827_14, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_2827_14 = \"defensive\"\n\ndef load_ssrf_2827_14(subject_2827_14, scope_2827_14):\n if HANDLER_KIND_LOAD_SSRF_2827_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_2827_14)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_2827_14):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_2827_14, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_ffc53a66_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_2827_14)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-c5919695276491dc","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_4558_25 = \"defensive\"\n\ndef resolve_flask_csrf_validation_4558_25(value_4558_25, policy_4558_25):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_4558_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_4558_25.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_4558_25 = \"defensive\"\n\ndef resolve_flask_csrf_validation_4558_25(value_4558_25, policy_4558_25):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_4558_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_4558_25.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_4558_25.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_4558_25.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_c5919695_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_csrf_validation_4558_25)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-fd53e50f66a9cb48","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_4965_15 = \"defensive\"\n\ndef load_unsafe_deserialization_4965_15(value_4965_15):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_4965_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_4965_15)\n","fixed_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_4965_15 = \"defensive\"\n\ndef load_unsafe_deserialization_4965_15(value_4965_15):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_4965_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_4965_15.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_fd53e50f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_unsafe_deserialization_4965_15)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-5ed74cfb20870171","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_3600_6 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_3600_6(request_3600_6):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_3600_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_3600_6.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_3600_6 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_3600_6(request_3600_6):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_3600_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_3600_6.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_3600_6.size is None or request_3600_6.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_3600_6.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_5ed74cfb_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_3600_6)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-5625da23e9ce60f2","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_9862_25 = \"defensive\"\n\ndef load_zip_decompression_bomb_9862_25(subject_9862_25, target_9862_25):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_9862_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_9862_25.extractall(target_9862_25)\n return target_9862_25\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_9862_25 = \"defensive\"\n\ndef load_zip_decompression_bomb_9862_25(subject_9862_25, target_9862_25):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_9862_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_9862_25.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_9862_25.extractall(target_9862_25)\n return target_9862_25\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_5625da23_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_9862_25)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-4d484b3e6019a44c","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_6107_27 = \"defensive\"\n\ndef resolve_csv_formula_injection_6107_27(value_6107_27):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_6107_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_6107_27)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_6107_27 = \"defensive\"\n\ndef resolve_csv_formula_injection_6107_27(value_6107_27):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_6107_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_6107_27)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_4d484b3e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_6107_27)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-95f0b6c93c27f32d","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_2888_0 = \"defensive\"\n\ndef process_csv_formula_injection_2888_0(value_2888_0):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_2888_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_2888_0)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_2888_0 = \"defensive\"\n\ndef process_csv_formula_injection_2888_0(value_2888_0):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_2888_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_2888_0)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_95f0b6c9_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_2888_0)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-36478a8b7d2312af","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2123_8 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_2123_8(payload_2123_8, scope_2123_8, allowed_2123_8):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2123_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_2123_8, scope_2123_8, algorithms=[\"HS256\"], audience=allowed_2123_8)\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2123_8 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_2123_8(payload_2123_8, scope_2123_8, allowed_2123_8):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2123_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_2123_8, scope_2123_8, algorithms=[\"HS256\"], audience=allowed_2123_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_36478a8b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_2123_8)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-8f69ee3d14e45e55","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_9238_3 = \"defensive\"\n\ndef resolve_lxml_external_entity_9238_3(payload_9238_3):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_9238_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_9238_3)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_9238_3 = \"defensive\"\n\ndef resolve_lxml_external_entity_9238_3(payload_9238_3):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_9238_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_9238_3, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_8f69ee3d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_9238_3)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-02260fe485c08552","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_7977_21 = \"defensive\"\n\ndef apply_insecure_file_permissions_7977_21(subject_7977_21, policy_7977_21):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_7977_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_7977_21).write_text(policy_7977_21, encoding=\"utf-8\")\n os.chmod(subject_7977_21, 0o777)\n return Path(subject_7977_21)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_7977_21 = \"defensive\"\n\ndef apply_insecure_file_permissions_7977_21(subject_7977_21, policy_7977_21):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_7977_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_7977_21).write_text(policy_7977_21, encoding=\"utf-8\")\n os.chmod(subject_7977_21, 0o600)\n return Path(subject_7977_21)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_02260fe4_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_7977_21)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-30438bdd1df62693","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_9899_8 = \"defensive\"\n\ndef apply_flask_csrf_validation_9899_8(value_9899_8, policy_9899_8):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_9899_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_9899_8.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_9899_8.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_9899_8.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_9899_8 = \"defensive\"\n\ndef apply_flask_csrf_validation_9899_8(value_9899_8, policy_9899_8):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_9899_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_9899_8.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_9899_8.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_9899_8.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_30438bdd_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_csrf_validation_9899_8)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-0dbaeeabcf6486ee","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7503_19 = \"defensive\"\n\ndef process_flask_csrf_validation_7503_19(request_7503_19, scope_7503_19):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7503_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7503_19.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7503_19 = \"defensive\"\n\ndef process_flask_csrf_validation_7503_19(request_7503_19, scope_7503_19):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7503_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_7503_19.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_7503_19.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_7503_19.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_0dbaeeab_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_7503_19)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-d9af29643804b178","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_5124_13 = \"defensive\"\n\ndef process_command_injection_5124_13(payload_5124_13, context_5124_13):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_5124_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_5124_13} {context_5124_13}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_5124_13 = \"defensive\"\n\ndef process_command_injection_5124_13(payload_5124_13, context_5124_13):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_5124_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_5124_13, context_5124_13], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_d9af2964_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_5124_13)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-665468db720eecdb","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5525_1 = \"defensive\"\n\ndef process_csv_formula_injection_5525_1(payload_5525_1):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5525_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_5525_1)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5525_1 = \"defensive\"\n\ndef process_csv_formula_injection_5525_1(payload_5525_1):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_5525_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_5525_1)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_665468db_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_5525_1)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-d5f76558823f9a37","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_4329_23 = \"defensive\"\n\ndef process_plaintext_password_storage_4329_23(payload_4329_23, policy_4329_23, options_4329_23):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_4329_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_4329_23) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_4329_23.encode(\"utf-8\"), options_4329_23, 240_000).hex()\n Path(payload_4329_23).write_text(verifier, encoding=\"ascii\")\n return Path(payload_4329_23)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_4329_23 = \"defensive\"\n\ndef process_plaintext_password_storage_4329_23(payload_4329_23, policy_4329_23, options_4329_23):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_4329_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_4329_23) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_4329_23.encode(\"utf-8\"), options_4329_23, 240_000).hex()\n Path(payload_4329_23).write_text(verifier, encoding=\"ascii\")\n return Path(payload_4329_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_d5f76558_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_4329_23)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-72523858633ef250","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1581_16 = \"defensive\"\n\ndef load_weak_cryptography_1581_16(value_1581_16, target_1581_16):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1581_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(value_1581_16.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1581_16 = \"defensive\"\n\ndef load_weak_cryptography_1581_16(value_1581_16, target_1581_16):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_1581_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_1581_16.encode(\"utf-8\"), target_1581_16, 210000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_72523858_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_1581_16)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-08685d7cf138c5af","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7958_17 = \"defensive\"\n\ndef apply_fastapi_upload_validation_7958_17(request_7958_17):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7958_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_7958_17.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_7958_17.size is None or request_7958_17.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_7958_17.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7958_17 = \"defensive\"\n\ndef apply_fastapi_upload_validation_7958_17(request_7958_17):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7958_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_7958_17.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_7958_17.size is None or request_7958_17.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_7958_17.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_08685d7c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_upload_validation_7958_17)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-11d6b1bc145786e4","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_7649_6 = \"defensive\"\n\ndef resolve_lxml_external_entity_7649_6(payload_7649_6):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_7649_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_7649_6)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_7649_6 = \"defensive\"\n\ndef resolve_lxml_external_entity_7649_6(payload_7649_6):\n if HANDLER_KIND_RESOLVE_LXML_EXTERNAL_ENTITY_7649_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_7649_6, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_11d6b1bc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_external_entity_7649_6)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-3463fc06e7729752","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8040_9 = \"defensive\"\n\ndef handle_path_traversal_8040_9(request_8040_9, target_8040_9):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8040_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(request_8040_9) / target_8040_9).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8040_9 = \"defensive\"\n\ndef handle_path_traversal_8040_9(request_8040_9, target_8040_9):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8040_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_8040_9).resolve()\n candidate = (root / target_8040_9).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_3463fc06_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_8040_9)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-e27274f29d6ffd8f","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5853_1 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_5853_1(value_5853_1, scope_5853_1):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5853_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return scope_5853_1.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5853_1 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_5853_1(value_5853_1, scope_5853_1):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5853_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_5853_1 is None or not value_5853_1.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_5853_1.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_e27274f2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_5853_1)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-93e3193ef662261f","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_1013_2 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_1013_2(request_1013_2, context_1013_2, options_1013_2):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_1013_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1013_2.info(\"login user=%s\", context_1013_2)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_1013_2 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_1013_2(request_1013_2, context_1013_2, options_1013_2):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_1013_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1013_2.info(\"login user=%s\", context_1013_2)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_93e3193e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sensitive_data_exposure_1013_2)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-735c5f2d97be91bb","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_8868_29 = \"defensive\"\n\ndef handle_lxml_external_entity_8868_29(request_8868_29):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_8868_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_8868_29, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_8868_29 = \"defensive\"\n\ndef handle_lxml_external_entity_8868_29(request_8868_29):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_8868_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_8868_29, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_735c5f2d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_8868_29)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-239d77a4b84e0792","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3008_19 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3008_19(value_3008_19, target_3008_19):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3008_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_3008_19.extractall(target_3008_19)\n return target_3008_19\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3008_19 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3008_19(value_3008_19, target_3008_19):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3008_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_3008_19.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_3008_19.extractall(target_3008_19)\n return target_3008_19\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_239d77a4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_3008_19)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-4aed3ffca6f27612","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8156_4 = \"defensive\"\n\ndef apply_weak_cryptography_8156_4(value_8156_4, scope_8156_4):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8156_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(value_8156_4.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8156_4 = \"defensive\"\n\ndef apply_weak_cryptography_8156_4(value_8156_4, scope_8156_4):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_8156_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_8156_4.encode(\"utf-8\"), scope_8156_4, 240000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_4aed3ffc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_weak_cryptography_8156_4)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-1eaa13afd7fab9ec","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_1428_17 = \"defensive\"\n\ndef process_weak_cryptography_1428_17(request_1428_17, context_1428_17):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_1428_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", request_1428_17.encode(\"utf-8\"), context_1428_17, 220000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_1428_17 = \"defensive\"\n\ndef process_weak_cryptography_1428_17(request_1428_17, context_1428_17):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_1428_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", request_1428_17.encode(\"utf-8\"), context_1428_17, 220000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_1eaa13af_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_1428_17)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-1319c5b3bb531861","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4828_10 = \"defensive\"\n\ndef apply_tarfile_path_traversal_4828_10(value_4828_10, target_4828_10):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4828_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4828_10.extractall(target_4828_10)\n return target_4828_10\n","fixed_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4828_10 = \"defensive\"\n\ndef apply_tarfile_path_traversal_4828_10(value_4828_10, target_4828_10):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4828_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4828_10.extractall(target_4828_10, filter=\"data\")\n return target_4828_10\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_1319c5b3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_tarfile_path_traversal_4828_10)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-50cc43d0fda58374","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7654_8 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_7654_8(subject_7654_8, scope_7654_8):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7654_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_7654_8.execute(statement, {\"account_id\": scope_7654_8}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7654_8 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_7654_8(subject_7654_8, scope_7654_8):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7654_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_7654_8.execute(statement, {\"account_id\": scope_7654_8}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_50cc43d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_7654_8)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-f821a652032d403e","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_4926_9 = \"defensive\"\n\ndef process_regex_dos_4926_9(request_4926_9, context_4926_9):\n if HANDLER_KIND_PROCESS_REGEX_DOS_4926_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(request_4926_9, context_4926_9) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_4926_9 = \"defensive\"\n\ndef process_regex_dos_4926_9(request_4926_9, context_4926_9):\n if HANDLER_KIND_PROCESS_REGEX_DOS_4926_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_4926_9) > 256 or len(context_4926_9) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(request_4926_9), context_4926_9) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_f821a652_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_4926_9)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-9e488ca65623f917","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3833_25 = \"defensive\"\n\ndef process_lxml_xpath_injection_3833_25(request_3833_25, context_3833_25):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3833_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{context_3833_25}']\"\n return request_3833_25.xpath(xpath)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3833_25 = \"defensive\"\n\ndef process_lxml_xpath_injection_3833_25(request_3833_25, context_3833_25):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_3833_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_3833_25.xpath(\"//user[@name=$account]\", account=context_3833_25)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_9e488ca6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_3833_25)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-5090a050df2e6b0b","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5201_25 = \"defensive\"\n\ndef handle_ldap_filter_injection_5201_25(payload_5201_25, context_5201_25):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5201_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_5201_25})\"\n return payload_5201_25.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5201_25 = \"defensive\"\n\ndef handle_ldap_filter_injection_5201_25(payload_5201_25, context_5201_25):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_5201_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_5201_25)\n query = f\"(uid={escaped})\"\n return payload_5201_25.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_5090a050_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_5201_25)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-4b681d1504db52f0","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_1140_16 = \"defensive\"\n\ndef handle_dynamic_code_injection_1140_16(payload_1140_16):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_1140_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(payload_1140_16, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_1140_16 = \"defensive\"\n\ndef handle_dynamic_code_injection_1140_16(payload_1140_16):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_1140_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_1140_16) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_1140_16)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_4b681d15_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_1140_16)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-524abfc4a4366159","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_4181_25 = \"defensive\"\n\ndef resolve_weak_cryptography_4181_25(payload_4181_25, context_4181_25):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_4181_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_4181_25.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_4181_25 = \"defensive\"\n\ndef resolve_weak_cryptography_4181_25(payload_4181_25, context_4181_25):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_4181_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_4181_25.encode(\"utf-8\"), context_4181_25, 200000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_524abfc4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_4181_25)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-d1165dfa3cca34c9","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_2065_27 = \"defensive\"\n\ndef handle_sql_injection_2065_27(subject_2065_27, context_2065_27):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_2065_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {context_2065_27}\"\n return subject_2065_27.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_2065_27 = \"defensive\"\n\ndef handle_sql_injection_2065_27(subject_2065_27, context_2065_27):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_2065_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_2065_27.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (context_2065_27,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_d1165dfa_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_2065_27)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-19c1e8442222d531","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_5897_27 = \"defensive\"\n\ndef apply_cleartext_http_transport_5897_27(subject_5897_27):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_5897_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=subject_5897_27, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_5897_27 = \"defensive\"\n\ndef apply_cleartext_http_transport_5897_27(subject_5897_27):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_5897_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_5897_27, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_19c1e844_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_5897_27)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-0d8be7c65cccf770","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6824_27 = \"defensive\"\n\ndef apply_insecure_random_token_6824_27(subject_6824_27):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6824_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_6824_27)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6824_27 = \"defensive\"\n\ndef apply_insecure_random_token_6824_27(subject_6824_27):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6824_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_6824_27)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_0d8be7c6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_6824_27)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-76eb4f01e5608770","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7712_5 = \"defensive\"\n\ndef handle_ldap_filter_injection_7712_5(request_7712_5, policy_7712_5):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7712_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_7712_5)\n query = f\"(uid={escaped})\"\n return request_7712_5.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7712_5 = \"defensive\"\n\ndef handle_ldap_filter_injection_7712_5(request_7712_5, policy_7712_5):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7712_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_7712_5)\n query = f\"(uid={escaped})\"\n return request_7712_5.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_76eb4f01_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_7712_5)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-465366bb00b2cbd8","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3802_26 = \"defensive\"\n\ndef apply_mass_assignment_3802_26(payload_3802_26, target_3802_26):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3802_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_3802_26.items() if key in allowed_fields}\n payload_3802_26.update(safe)\n return payload_3802_26\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3802_26 = \"defensive\"\n\ndef apply_mass_assignment_3802_26(payload_3802_26, target_3802_26):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_3802_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_3802_26.items() if key in allowed_fields}\n payload_3802_26.update(safe)\n return payload_3802_26\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_465366bb_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_3802_26)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4ab2484140b1b5cb","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9122_25 = \"defensive\"\n\ndef load_tarfile_path_traversal_9122_25(value_9122_25, scope_9122_25):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9122_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9122_25.extractall(scope_9122_25)\n return scope_9122_25\n","fixed_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9122_25 = \"defensive\"\n\ndef load_tarfile_path_traversal_9122_25(value_9122_25, scope_9122_25):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9122_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9122_25.extractall(scope_9122_25, filter=\"data\")\n return scope_9122_25\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_4ab24841_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_tarfile_path_traversal_9122_25)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-267ecdf429abdb1e","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1574_5 = \"defensive\"\n\ndef process_log_injection_1574_5(subject_1574_5, context_1574_5):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1574_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(context_1574_5).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_1574_5.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1574_5 = \"defensive\"\n\ndef process_log_injection_1574_5(subject_1574_5, context_1574_5):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1574_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(context_1574_5).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_1574_5.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_267ecdf4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_1574_5)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-31890b55b6a9d0b2","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LOG_INJECTION_8493_22 = \"defensive\"\n\ndef apply_log_injection_8493_22(subject_8493_22, target_8493_22):\n if HANDLER_KIND_APPLY_LOG_INJECTION_8493_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8493_22.warning(\"audit=%s\", target_8493_22)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_LOG_INJECTION_8493_22 = \"defensive\"\n\ndef apply_log_injection_8493_22(subject_8493_22, target_8493_22):\n if HANDLER_KIND_APPLY_LOG_INJECTION_8493_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_8493_22).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_8493_22.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_31890b55_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_log_injection_8493_22)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-5d5095157bf2fccc","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9429_10 = \"defensive\"\n\ndef process_insecure_temp_file_9429_10(subject_9429_10, context_9429_10):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9429_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{subject_9429_10}.txt\")\n path.write_text(context_9429_10, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9429_10 = \"defensive\"\n\ndef process_insecure_temp_file_9429_10(subject_9429_10, context_9429_10):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_9429_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_9429_10)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_5d509515_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_9429_10)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-6fdd72e4be6ee126","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1179_29 = \"defensive\"\n\ndef apply_missing_authorization_1179_29(subject_1179_29, scope_1179_29):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1179_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1179_29.id != scope_1179_29.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1179_29.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1179_29 = \"defensive\"\n\ndef apply_missing_authorization_1179_29(subject_1179_29, scope_1179_29):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_1179_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1179_29.id != scope_1179_29.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1179_29.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_6fdd72e4_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_1179_29)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-ca97df745b076a9c","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_5310_29 = \"defensive\"\n\ndef apply_httpx_client_ssrf_5310_29(request_5310_29, context_5310_29, options_5310_29):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_5310_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_5310_29)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_5310_29):\n raise ValueError(\"destination is not allowed\")\n return request_5310_29.get(context_5310_29, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_5310_29 = \"defensive\"\n\ndef apply_httpx_client_ssrf_5310_29(request_5310_29, context_5310_29, options_5310_29):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_5310_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_5310_29)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_5310_29):\n raise ValueError(\"destination is not allowed\")\n return request_5310_29.get(context_5310_29, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_ca97df74_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_5310_29)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-171f81023abca380","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_5081_23 = \"defensive\"\n\ndef resolve_insecure_file_permissions_5081_23(payload_5081_23, policy_5081_23):\n if HANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_5081_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_5081_23).write_text(policy_5081_23, encoding=\"utf-8\")\n os.chmod(payload_5081_23, 0o600)\n return Path(payload_5081_23)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_5081_23 = \"defensive\"\n\ndef resolve_insecure_file_permissions_5081_23(payload_5081_23, policy_5081_23):\n if HANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_5081_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_5081_23).write_text(policy_5081_23, encoding=\"utf-8\")\n os.chmod(payload_5081_23, 0o600)\n return Path(payload_5081_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_171f8102_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_file_permissions_5081_23)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-e6ce79515c94cf2f","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_7655_24 = \"defensive\"\n\ndef process_flask_open_redirect_7655_24(value_7655_24):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_7655_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_7655_24)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_7655_24 = \"defensive\"\n\ndef process_flask_open_redirect_7655_24(value_7655_24):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_7655_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_7655_24)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_7655_24)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_e6ce7951_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_open_redirect_7655_24)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-751e77b7327ba29f","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_5171_15 = \"defensive\"\n\ndef handle_httpx_client_ssrf_5171_15(value_5171_15, policy_5171_15, owner_5171_15):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_5171_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5171_15.get(policy_5171_15, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_5171_15 = \"defensive\"\n\ndef handle_httpx_client_ssrf_5171_15(value_5171_15, policy_5171_15, owner_5171_15):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_5171_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_5171_15)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_5171_15):\n raise ValueError(\"destination is not allowed\")\n return value_5171_15.get(policy_5171_15, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_751e77b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_httpx_client_ssrf_5171_15)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-38c6e06714ff32a8","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_2109_15 = \"defensive\"\n\ndef process_flask_jinja_xss_2109_15(value_2109_15):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_2109_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_2109_15)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_2109_15 = \"defensive\"\n\ndef process_flask_jinja_xss_2109_15(value_2109_15):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_2109_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_2109_15)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_38c6e067_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_2109_15)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-b02a29fdfb15c2de","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_3661_25 = \"defensive\"\n\ndef resolve_flask_jinja_xss_3661_25(request_3661_25):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_3661_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_3661_25)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_3661_25 = \"defensive\"\n\ndef resolve_flask_jinja_xss_3661_25(request_3661_25):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_3661_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_3661_25)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_b02a29fd_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_3661_25)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-6adbc4f3b9629291","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_9170_26 = \"defensive\"\n\ndef process_flask_session_fixation_9170_26(subject_9170_26, context_9170_26):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_9170_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_9170_26.clear()\n subject_9170_26[\"user_id\"] = context_9170_26.id\n subject_9170_26[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_9170_26 = \"defensive\"\n\ndef process_flask_session_fixation_9170_26(subject_9170_26, context_9170_26):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_9170_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_9170_26.clear()\n subject_9170_26[\"user_id\"] = context_9170_26.id\n subject_9170_26[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_6adbc4f3_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_9170_26)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-42c0da45158234ec","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3672_17 = \"defensive\"\n\ndef process_insecure_file_permissions_3672_17(subject_3672_17, target_3672_17):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3672_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_3672_17).write_text(target_3672_17, encoding=\"utf-8\")\n os.chmod(subject_3672_17, 0o600)\n return Path(subject_3672_17)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3672_17 = \"defensive\"\n\ndef process_insecure_file_permissions_3672_17(subject_3672_17, target_3672_17):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3672_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_3672_17).write_text(target_3672_17, encoding=\"utf-8\")\n os.chmod(subject_3672_17, 0o600)\n return Path(subject_3672_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_42c0da45_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_3672_17)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-4fd4ce8b79334da4","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2595_5 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2595_5(value_2595_5, target_2595_5):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2595_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_2595_5 is None or not value_2595_5.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_2595_5.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2595_5 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2595_5(value_2595_5, target_2595_5):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2595_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_2595_5 is None or not value_2595_5.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_2595_5.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_4fd4ce8b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_missing_authentication_2595_5)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-034f3463cf31f258","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_SSRF_1571_28 = \"defensive\"\n\ndef load_ssrf_1571_28(subject_1571_28, policy_1571_28):\n if HANDLER_KIND_LOAD_SSRF_1571_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_1571_28, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_1571_28 = \"defensive\"\n\ndef load_ssrf_1571_28(subject_1571_28, policy_1571_28):\n if HANDLER_KIND_LOAD_SSRF_1571_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_1571_28)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_1571_28):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_1571_28, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_034f3463_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_1571_28)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-0e6caa2dc5dd3fd4","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_4744_22 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_4744_22(value_4744_22):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_4744_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(value_4744_22, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_4744_22 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_4744_22(value_4744_22):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_4744_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(value_4744_22)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_0e6caa2d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_4744_22)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-f4c617ece3a26055","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1909_20 = \"defensive\"\n\ndef handle_csv_formula_injection_1909_20(subject_1909_20):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1909_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_1909_20)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1909_20 = \"defensive\"\n\ndef handle_csv_formula_injection_1909_20(subject_1909_20):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_1909_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_1909_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_f4c617ec_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_1909_20)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-88fbf65c041e1a90","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5262_18 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_5262_18(value_5262_18, policy_5262_18, limit_5262_18):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5262_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_5262_18, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5262_18 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_5262_18(value_5262_18, policy_5262_18, limit_5262_18):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_5262_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_5262_18, policy_5262_18, algorithms=[\"HS256\"], audience=limit_5262_18)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_88fbf65c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_5262_18)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-21920b43e59fae61","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4526_25 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_4526_25(value_4526_25, scope_4526_25):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4526_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {scope_4526_25}\")\n return value_4526_25.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4526_25 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_4526_25(value_4526_25, scope_4526_25):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4526_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_4526_25.execute(statement, {\"account_id\": scope_4526_25}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_21920b43_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_4526_25)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-f4c77c8510844ada","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_9755_13 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_9755_13(request_9755_13, scope_9755_13, owner_9755_13):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_9755_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_9755_13, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_9755_13 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_9755_13(request_9755_13, scope_9755_13, owner_9755_13):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_9755_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_9755_13, scope_9755_13, algorithms=[\"HS256\"], audience=owner_9755_13)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_f4c77c85_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_9755_13)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-06d818864b872a02","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_8344_0 = \"defensive\"\n\ndef resolve_weak_cryptography_8344_0(payload_8344_0, scope_8344_0):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_8344_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_8344_0.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_8344_0 = \"defensive\"\n\ndef resolve_weak_cryptography_8344_0(payload_8344_0, scope_8344_0):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_8344_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_8344_0.encode(\"utf-8\"), scope_8344_0, 200000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_06d81886_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_8344_0)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-1ec259447a037c32","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_8676_5 = \"defensive\"\n\ndef resolve_flask_session_fixation_8676_5(value_8676_5, scope_8676_5):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_8676_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8676_5.clear()\n value_8676_5[\"user_id\"] = scope_8676_5.id\n value_8676_5[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_8676_5 = \"defensive\"\n\ndef resolve_flask_session_fixation_8676_5(value_8676_5, scope_8676_5):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_8676_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8676_5.clear()\n value_8676_5[\"user_id\"] = scope_8676_5.id\n value_8676_5[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_1ec25944_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_8676_5)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-b210d26994c82ae4","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3410_26 = \"defensive\"\n\ndef process_fastapi_upload_validation_3410_26(subject_3410_26):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3410_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_3410_26.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_3410_26.size is None or subject_3410_26.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_3410_26.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3410_26 = \"defensive\"\n\ndef process_fastapi_upload_validation_3410_26(subject_3410_26):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3410_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_3410_26.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_3410_26.size is None or subject_3410_26.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_3410_26.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_b210d269_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_3410_26)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-7e701f3f4e3b75b4","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_8722_12 = \"defensive\"\n\ndef resolve_django_error_details_8722_12(request_8722_12, target_8722_12):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_8722_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_8722_12()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_8722_12 = \"defensive\"\n\ndef resolve_django_error_details_8722_12(request_8722_12, target_8722_12):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_8722_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_8722_12()\n except Exception:\n request_8722_12.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_7e701f3f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_8722_12)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-63b82d7df440c9d1","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9562_4 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_9562_4(payload_9562_4, target_9562_4):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9562_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{target_9562_4}']\"\n return payload_9562_4.xpath(xpath)\n","fixed_code":"HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9562_4 = \"defensive\"\n\ndef resolve_lxml_xpath_injection_9562_4(payload_9562_4, target_9562_4):\n if HANDLER_KIND_RESOLVE_LXML_XPATH_INJECTION_9562_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9562_4.xpath(\"//user[@name=$account]\", account=target_9562_4)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_63b82d7d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_lxml_xpath_injection_9562_4)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-1d0d72635f27c9ee","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4145_15 = \"defensive\"\n\ndef load_fastapi_missing_authentication_4145_15(request_4145_15, policy_4145_15):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4145_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return policy_4145_15.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4145_15 = \"defensive\"\n\ndef load_fastapi_missing_authentication_4145_15(request_4145_15, policy_4145_15):\n if HANDLER_KIND_LOAD_FASTAPI_MISSING_AUTHENTICATION_4145_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_4145_15 is None or not request_4145_15.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_4145_15.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_1d0d7263_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_missing_authentication_4145_15)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-379c0de6aa4497bb","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3529_1 = \"defensive\"\n\ndef resolve_flask_open_redirect_3529_1(subject_3529_1):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3529_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(subject_3529_1)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3529_1 = \"defensive\"\n\ndef resolve_flask_open_redirect_3529_1(subject_3529_1):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3529_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_3529_1)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_3529_1)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_379c0de6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_3529_1)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-5d74ec081b8c2459","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2457_18 = \"defensive\"\n\ndef process_mass_assignment_2457_18(value_2457_18, policy_2457_18):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2457_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_2457_18.items():\n setattr(value_2457_18, key, value)\n return value_2457_18\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2457_18 = \"defensive\"\n\ndef process_mass_assignment_2457_18(value_2457_18, policy_2457_18):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2457_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_2457_18.items() if key in allowed_fields}\n value_2457_18.update(safe)\n return value_2457_18\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_5d74ec08_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_2457_18)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-0f9cac5a84318f38","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_5424_21 = \"defensive\"\n\ndef load_tarfile_path_traversal_5424_21(request_5424_21, context_5424_21):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_5424_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5424_21.extractall(context_5424_21)\n return context_5424_21\n","fixed_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_5424_21 = \"defensive\"\n\ndef load_tarfile_path_traversal_5424_21(request_5424_21, context_5424_21):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_5424_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5424_21.extractall(context_5424_21, filter=\"data\")\n return context_5424_21\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_0f9cac5a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_tarfile_path_traversal_5424_21)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-faf17d24d07fae8c","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6028_11 = \"defensive\"\n\ndef handle_unsafe_deserialization_6028_11(subject_6028_11):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6028_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_6028_11.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6028_11 = \"defensive\"\n\ndef handle_unsafe_deserialization_6028_11(subject_6028_11):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6028_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_6028_11.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_faf17d24_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_6028_11)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-cb3cc664404e85b2","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_4498_27 = \"defensive\"\n\ndef resolve_ldap_filter_injection_4498_27(value_4498_27, context_4498_27):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_4498_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_4498_27})\"\n return value_4498_27.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_4498_27 = \"defensive\"\n\ndef resolve_ldap_filter_injection_4498_27(value_4498_27, context_4498_27):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_4498_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_4498_27)\n query = f\"(uid={escaped})\"\n return value_4498_27.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_cb3cc664_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_4498_27)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-353094f425f70487","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_3068_18 = \"defensive\"\n\ndef process_flask_jinja_xss_3068_18(payload_3068_18):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_3068_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(payload_3068_18)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_PROCESS_FLASK_JINJA_XSS_3068_18 = \"defensive\"\n\ndef process_flask_jinja_xss_3068_18(payload_3068_18):\n if HANDLER_KIND_PROCESS_FLASK_JINJA_XSS_3068_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_3068_18)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_353094f4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_jinja_xss_3068_18)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-7e0a797a58bc83af","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9942_19 = \"defensive\"\n\ndef load_tarfile_path_traversal_9942_19(request_9942_19, policy_9942_19):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9942_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9942_19.extractall(policy_9942_19)\n return policy_9942_19\n","fixed_code":"HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9942_19 = \"defensive\"\n\ndef load_tarfile_path_traversal_9942_19(request_9942_19, policy_9942_19):\n if HANDLER_KIND_LOAD_TARFILE_PATH_TRAVERSAL_9942_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9942_19.extractall(policy_9942_19, filter=\"data\")\n return policy_9942_19\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_7e0a797a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_tarfile_path_traversal_9942_19)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-7b26b5e6725ebe36","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_2290_29 = \"defensive\"\n\ndef handle_tarfile_path_traversal_2290_29(subject_2290_29, policy_2290_29):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_2290_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2290_29.extractall(policy_2290_29, filter=\"data\")\n return policy_2290_29\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_2290_29 = \"defensive\"\n\ndef handle_tarfile_path_traversal_2290_29(subject_2290_29, policy_2290_29):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_2290_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2290_29.extractall(policy_2290_29, filter=\"data\")\n return policy_2290_29\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_7b26b5e6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_2290_29)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-a7b1aa9bc7c8be92","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1004_8 = \"defensive\"\n\ndef resolve_missing_authorization_1004_8(value_1004_8, policy_1004_8):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1004_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_1004_8.id != policy_1004_8.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_1004_8.delete()\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1004_8 = \"defensive\"\n\ndef resolve_missing_authorization_1004_8(value_1004_8, policy_1004_8):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1004_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_1004_8.id != policy_1004_8.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_1004_8.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_a7b1aa9b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_missing_authorization_1004_8)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-0180618917d8c35b","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4608_21 = \"defensive\"\n\ndef handle_flask_jinja_xss_4608_21(value_4608_21):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4608_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_4608_21)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4608_21 = \"defensive\"\n\ndef handle_flask_jinja_xss_4608_21(value_4608_21):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_4608_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_4608_21)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_01806189_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_jinja_xss_4608_21)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-9a38b9c3d93c66aa","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_8624_4 = \"defensive\"\n\ndef process_path_traversal_8624_4(request_8624_4, context_8624_4):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_8624_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(request_8624_4) / context_8624_4).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_8624_4 = \"defensive\"\n\ndef process_path_traversal_8624_4(request_8624_4, context_8624_4):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_8624_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_8624_4).resolve()\n candidate = (root / context_8624_4).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_9a38b9c3_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_8624_4)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-10b37a0621670536","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_4988_5 = \"defensive\"\n\ndef apply_flask_jinja_xss_4988_5(payload_4988_5):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_4988_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_4988_5)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_4988_5 = \"defensive\"\n\ndef apply_flask_jinja_xss_4988_5(payload_4988_5):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_4988_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_4988_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_10b37a06_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_4988_5)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-0198cfbc8c5f5b6c","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4728_22 = \"defensive\"\n\ndef handle_plaintext_password_storage_4728_22(payload_4728_22, context_4728_22, options_4728_22):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4728_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_4728_22).write_text(context_4728_22, encoding=\"utf-8\")\n return Path(payload_4728_22)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4728_22 = \"defensive\"\n\ndef handle_plaintext_password_storage_4728_22(payload_4728_22, context_4728_22, options_4728_22):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_4728_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_4728_22) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", context_4728_22.encode(\"utf-8\"), options_4728_22, 240_000).hex()\n Path(payload_4728_22).write_text(verifier, encoding=\"ascii\")\n return Path(payload_4728_22)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_0198cfbc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_4728_22)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-cef0d61222231351","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8526_20 = \"defensive\"\n\ndef handle_path_traversal_8526_20(value_8526_20, target_8526_20):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8526_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_8526_20).resolve()\n candidate = (root / target_8526_20).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8526_20 = \"defensive\"\n\ndef handle_path_traversal_8526_20(value_8526_20, target_8526_20):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8526_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_8526_20).resolve()\n candidate = (root / target_8526_20).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_cef0d612_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_8526_20)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4f79269eabfdbb78","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_6967_24 = \"defensive\"\n\ndef process_tarfile_path_traversal_6967_24(request_6967_24, scope_6967_24):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_6967_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6967_24.extractall(scope_6967_24)\n return scope_6967_24\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_6967_24 = \"defensive\"\n\ndef process_tarfile_path_traversal_6967_24(request_6967_24, scope_6967_24):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_6967_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6967_24.extractall(scope_6967_24, filter=\"data\")\n return scope_6967_24\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_4f79269e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_6967_24)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-2cf8eea60bba4772","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_7035_12 = \"defensive\"\n\ndef handle_missing_authorization_7035_12(request_7035_12, context_7035_12):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_7035_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_7035_12.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_7035_12 = \"defensive\"\n\ndef handle_missing_authorization_7035_12(request_7035_12, context_7035_12):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_7035_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_7035_12.id != context_7035_12.owner_id:\n raise PermissionError(\"record ownership required\")\n context_7035_12.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_2cf8eea6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_7035_12)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-21e01297f6199097","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_6132_25 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_6132_25(value_6132_25, policy_6132_25, owner_6132_25):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_6132_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_6132_25.get(policy_6132_25, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_6132_25 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_6132_25(value_6132_25, policy_6132_25, owner_6132_25):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_6132_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_6132_25)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_6132_25):\n raise ValueError(\"destination is not allowed\")\n return value_6132_25.get(policy_6132_25, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_21e01297_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_httpx_client_ssrf_6132_25)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-0e6f0516eba689b8","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_5299_23 = \"defensive\"\n\ndef load_unsafe_deserialization_5299_23(value_5299_23):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_5299_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5299_23.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_5299_23 = \"defensive\"\n\ndef load_unsafe_deserialization_5299_23(value_5299_23):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_5299_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5299_23.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_0e6f0516_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_unsafe_deserialization_5299_23)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-ad939e249d8ef403","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7833_16 = \"defensive\"\n\ndef load_hardcoded_credentials_7833_16(request_7833_16):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7833_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000016\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_7833_16)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7833_16 = \"defensive\"\n\ndef load_hardcoded_credentials_7833_16(request_7833_16):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7833_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_7833_16)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_ad939e24_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_7833_16)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-c4f81da622d1778a","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4355_9 = \"defensive\"\n\ndef process_flask_session_fixation_4355_9(value_4355_9, target_4355_9):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4355_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4355_9[\"user_id\"] = target_4355_9.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4355_9 = \"defensive\"\n\ndef process_flask_session_fixation_4355_9(value_4355_9, target_4355_9):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4355_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4355_9.clear()\n value_4355_9[\"user_id\"] = target_4355_9.id\n value_4355_9[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_c4f81da6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_4355_9)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-ec0ad88840941064","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6397_5 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_6397_5(subject_6397_5, policy_6397_5):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6397_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_6397_5.execute(statement, {\"account_id\": policy_6397_5}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6397_5 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_6397_5(subject_6397_5, policy_6397_5):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6397_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_6397_5.execute(statement, {\"account_id\": policy_6397_5}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_ec0ad888_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_6397_5)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-8eb736a405958056","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_8070_23 = \"defensive\"\n\ndef process_tarfile_path_traversal_8070_23(value_8070_23, policy_8070_23):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_8070_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8070_23.extractall(policy_8070_23, filter=\"data\")\n return policy_8070_23\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_8070_23 = \"defensive\"\n\ndef process_tarfile_path_traversal_8070_23(value_8070_23, policy_8070_23):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_8070_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8070_23.extractall(policy_8070_23, filter=\"data\")\n return policy_8070_23\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_8eb736a4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_8070_23)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-282bbd89c450012e","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_1030_13 = \"defensive\"\n\ndef resolve_insecure_file_permissions_1030_13(request_1030_13, policy_1030_13):\n if HANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_1030_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1030_13).write_text(policy_1030_13, encoding=\"utf-8\")\n os.chmod(request_1030_13, 0o777)\n return Path(request_1030_13)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_1030_13 = \"defensive\"\n\ndef resolve_insecure_file_permissions_1030_13(request_1030_13, policy_1030_13):\n if HANDLER_KIND_RESOLVE_INSECURE_FILE_PERMISSIONS_1030_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_1030_13).write_text(policy_1030_13, encoding=\"utf-8\")\n os.chmod(request_1030_13, 0o600)\n return Path(request_1030_13)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_282bbd89_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_file_permissions_1030_13)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-b24899800e080d2c","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_SSRF_8640_1 = \"defensive\"\n\ndef apply_ssrf_8640_1(request_8640_1, target_8640_1):\n if HANDLER_KIND_APPLY_SSRF_8640_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_8640_1, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_8640_1 = \"defensive\"\n\ndef apply_ssrf_8640_1(request_8640_1, target_8640_1):\n if HANDLER_KIND_APPLY_SSRF_8640_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_8640_1)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_8640_1):\n raise ValueError(\"destination is not allowed\")\n return requests.get(request_8640_1, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_b2489980_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_8640_1)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4a8d496b20b6ffcf","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4520_9 = \"defensive\"\n\ndef apply_tarfile_path_traversal_4520_9(payload_4520_9, scope_4520_9):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4520_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4520_9.extractall(scope_4520_9)\n return scope_4520_9\n","fixed_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4520_9 = \"defensive\"\n\ndef apply_tarfile_path_traversal_4520_9(payload_4520_9, scope_4520_9):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_4520_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4520_9.extractall(scope_4520_9, filter=\"data\")\n return scope_4520_9\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_4a8d496b_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_tarfile_path_traversal_4520_9)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-90ee85474bc4beaf","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5944_16 = \"defensive\"\n\ndef load_cleartext_http_transport_5944_16(value_5944_16):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5944_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_5944_16, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5944_16 = \"defensive\"\n\ndef load_cleartext_http_transport_5944_16(value_5944_16):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5944_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_5944_16, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_90ee8547_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_5944_16)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-c7a5f1ed5f7f75b4","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_7243_17 = \"defensive\"\n\ndef load_path_traversal_7243_17(value_7243_17, target_7243_17):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_7243_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_7243_17).resolve()\n candidate = (root / target_7243_17).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_7243_17 = \"defensive\"\n\ndef load_path_traversal_7243_17(value_7243_17, target_7243_17):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_7243_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_7243_17).resolve()\n candidate = (root / target_7243_17).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_c7a5f1ed_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_path_traversal_7243_17)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-a165cc010c3f8c32","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2801_2 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_2801_2(request_2801_2):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2801_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_2801_2)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2801_2 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_2801_2(request_2801_2):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2801_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_2801_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_a165cc01_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_2801_2)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-eef804e4564a4665","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5411_10 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_5411_10(value_5411_10, policy_5411_10):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5411_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_5411_10}\")\n return value_5411_10.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5411_10 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_5411_10(value_5411_10, policy_5411_10):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_5411_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_5411_10.execute(statement, {\"account_id\": policy_5411_10}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_eef804e4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sqlalchemy_text_injection_5411_10)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-0b8c910e1e9946ca","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5169_27 = \"defensive\"\n\ndef process_starlette_permissive_cors_5169_27(request_5169_27, policy_5169_27):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5169_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5169_27.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return request_5169_27\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5169_27 = \"defensive\"\n\ndef process_starlette_permissive_cors_5169_27(request_5169_27, policy_5169_27):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5169_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5169_27)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_5169_27.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_5169_27\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_0b8c910e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_5169_27)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-31e6f4b3d6bfb3e1","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8727_7 = \"defensive\"\n\ndef process_sensitive_data_exposure_8727_7(payload_8727_7, policy_8727_7, options_8727_7):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8727_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8727_7.info(\"login user=%s password=%s\", policy_8727_7, options_8727_7)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8727_7 = \"defensive\"\n\ndef process_sensitive_data_exposure_8727_7(payload_8727_7, policy_8727_7, options_8727_7):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_8727_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8727_7.info(\"login user=%s\", policy_8727_7)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_31e6f4b3_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_8727_7)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-d7d6a8aa4a5cca0f","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6515_24 = \"defensive\"\n\ndef process_fastapi_missing_authentication_6515_24(value_6515_24, scope_6515_24):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6515_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return scope_6515_24.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6515_24 = \"defensive\"\n\ndef process_fastapi_missing_authentication_6515_24(value_6515_24, scope_6515_24):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6515_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_6515_24 is None or not value_6515_24.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_6515_24.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_d7d6a8aa_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_6515_24)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-eaa89945ea353e81","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3399_22 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3399_22(request_3399_22):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3399_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_3399_22.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3399_22 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3399_22(request_3399_22):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3399_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_3399_22.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_3399_22.size is None or request_3399_22.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_3399_22.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_eaa89945_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_3399_22)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a8550191c449951c","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1914_13 = \"defensive\"\n\ndef load_httpx_client_ssrf_1914_13(value_1914_13, target_1914_13, limit_1914_13):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1914_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_1914_13.get(target_1914_13, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1914_13 = \"defensive\"\n\ndef load_httpx_client_ssrf_1914_13(value_1914_13, target_1914_13, limit_1914_13):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1914_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_1914_13)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_1914_13):\n raise ValueError(\"destination is not allowed\")\n return value_1914_13.get(target_1914_13, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_a8550191_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_1914_13)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-5e5f2aed2fddfd32","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_9494_16 = \"defensive\"\n\ndef apply_mass_assignment_9494_16(request_9494_16, scope_9494_16):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_9494_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in scope_9494_16.items():\n setattr(request_9494_16, key, value)\n return request_9494_16\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_9494_16 = \"defensive\"\n\ndef apply_mass_assignment_9494_16(request_9494_16, scope_9494_16):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_9494_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_9494_16.items() if key in allowed_fields}\n request_9494_16.update(safe)\n return request_9494_16\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_5e5f2aed_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_9494_16)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-5e0e58b705377c57","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3155_25 = \"defensive\"\n\ndef load_plaintext_password_storage_3155_25(payload_3155_25, scope_3155_25, options_3155_25):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3155_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_3155_25).write_text(scope_3155_25, encoding=\"utf-8\")\n return Path(payload_3155_25)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3155_25 = \"defensive\"\n\ndef load_plaintext_password_storage_3155_25(payload_3155_25, scope_3155_25, options_3155_25):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3155_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_3155_25) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_3155_25.encode(\"utf-8\"), options_3155_25, 240_000).hex()\n Path(payload_3155_25).write_text(verifier, encoding=\"ascii\")\n return Path(payload_3155_25)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_5e0e58b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_3155_25)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-444c378004a63130","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5907_24 = \"defensive\"\n\ndef process_log_injection_5907_24(request_5907_24, target_5907_24):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5907_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5907_24.warning(\"audit=%s\", target_5907_24)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_5907_24 = \"defensive\"\n\ndef process_log_injection_5907_24(request_5907_24, target_5907_24):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_5907_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_5907_24).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_5907_24.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_444c3780_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_5907_24)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-aac5735dca0670ec","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_8686_1 = \"defensive\"\n\ndef apply_command_injection_8686_1(request_8686_1, context_8686_1):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_8686_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {request_8686_1} {context_8686_1}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_8686_1 = \"defensive\"\n\ndef apply_command_injection_8686_1(request_8686_1, context_8686_1):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_8686_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_8686_1, context_8686_1], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_aac5735d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_8686_1)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-d598ecd436b6d305","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_1952_5 = \"defensive\"\n\ndef process_insecure_file_permissions_1952_5(payload_1952_5, scope_1952_5):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_1952_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1952_5).write_text(scope_1952_5, encoding=\"utf-8\")\n os.chmod(payload_1952_5, 0o600)\n return Path(payload_1952_5)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_1952_5 = \"defensive\"\n\ndef process_insecure_file_permissions_1952_5(payload_1952_5, scope_1952_5):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_1952_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1952_5).write_text(scope_1952_5, encoding=\"utf-8\")\n os.chmod(payload_1952_5, 0o600)\n return Path(payload_1952_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_d598ecd4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_1952_5)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-4b97785f42a156c1","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5278_3 = \"defensive\"\n\ndef load_fastapi_upload_validation_5278_3(payload_5278_3):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5278_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_5278_3.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5278_3 = \"defensive\"\n\ndef load_fastapi_upload_validation_5278_3(payload_5278_3):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_5278_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_5278_3.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_5278_3.size is None or payload_5278_3.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_5278_3.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_4b97785f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_upload_validation_5278_3)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-63451e6d92173184","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5956_21 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_5956_21(payload_5956_21, target_5956_21):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5956_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return target_5956_21.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5956_21 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_5956_21(payload_5956_21, target_5956_21):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_5956_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_5956_21 is None or not payload_5956_21.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return target_5956_21.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_63451e6d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_5956_21)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-417bab70f13edfd3","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2424_21 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_2424_21(payload_2424_21):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2424_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_2424_21.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2424_21 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_2424_21(payload_2424_21):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2424_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_2424_21.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_2424_21.size is None or payload_2424_21.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_2424_21.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_417bab70_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_2424_21)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-1223ad08fe8e3482","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7250_9 = \"defensive\"\n\ndef process_starlette_permissive_cors_7250_9(value_7250_9, policy_7250_9):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7250_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_7250_9.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return value_7250_9\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7250_9 = \"defensive\"\n\ndef process_starlette_permissive_cors_7250_9(value_7250_9, policy_7250_9):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_7250_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_7250_9)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_7250_9.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_7250_9\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_1223ad08_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_7250_9)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-30a782f117a0c65e","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_2477_21 = \"defensive\"\n\ndef handle_csv_formula_injection_2477_21(value_2477_21):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_2477_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_2477_21)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_2477_21 = \"defensive\"\n\ndef handle_csv_formula_injection_2477_21(value_2477_21):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_2477_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_2477_21)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_30a782f1_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_2477_21)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-af174530aec66a65","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_5089_15 = \"defensive\"\n\ndef process_path_traversal_5089_15(payload_5089_15, policy_5089_15):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_5089_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_5089_15) / policy_5089_15).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_5089_15 = \"defensive\"\n\ndef process_path_traversal_5089_15(payload_5089_15, policy_5089_15):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_5089_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_5089_15).resolve()\n candidate = (root / policy_5089_15).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_af174530_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_5089_15)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-d3d8e4370a9b3f7f","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_7401_21 = \"defensive\"\n\ndef apply_weak_cryptography_7401_21(payload_7401_21, context_7401_21):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_7401_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_7401_21.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_7401_21 = \"defensive\"\n\ndef apply_weak_cryptography_7401_21(payload_7401_21, context_7401_21):\n if HANDLER_KIND_APPLY_WEAK_CRYPTOGRAPHY_7401_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_7401_21.encode(\"utf-8\"), context_7401_21, 210000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_d3d8e437_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_weak_cryptography_7401_21)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-ecf049cc8a0c3d72","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2003_14 = \"defensive\"\n\ndef process_flask_session_fixation_2003_14(value_2003_14, policy_2003_14):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2003_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2003_14.clear()\n value_2003_14[\"user_id\"] = policy_2003_14.id\n value_2003_14[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2003_14 = \"defensive\"\n\ndef process_flask_session_fixation_2003_14(value_2003_14, policy_2003_14):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_2003_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2003_14.clear()\n value_2003_14[\"user_id\"] = policy_2003_14.id\n value_2003_14[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_ecf049cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_2003_14)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-5af1732a6c096a49","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3022_21 = \"defensive\"\n\ndef load_zip_decompression_bomb_3022_21(request_3022_21, scope_3022_21):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3022_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3022_21.extractall(scope_3022_21)\n return scope_3022_21\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3022_21 = \"defensive\"\n\ndef load_zip_decompression_bomb_3022_21(request_3022_21, scope_3022_21):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3022_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_3022_21.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_3022_21.extractall(scope_3022_21)\n return scope_3022_21\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_5af1732a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_3022_21)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-811ab1f76eb1711b","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_SSRF_5609_12 = \"defensive\"\n\ndef process_ssrf_5609_12(subject_5609_12, context_5609_12):\n if HANDLER_KIND_PROCESS_SSRF_5609_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_5609_12, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_5609_12 = \"defensive\"\n\ndef process_ssrf_5609_12(subject_5609_12, context_5609_12):\n if HANDLER_KIND_PROCESS_SSRF_5609_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_5609_12)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_5609_12):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_5609_12, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_811ab1f7_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ssrf_5609_12)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-6f5912794f1ac09c","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3649_27 = \"defensive\"\n\ndef process_flask_open_redirect_3649_27(value_3649_27):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3649_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_3649_27)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3649_27 = \"defensive\"\n\ndef process_flask_open_redirect_3649_27(value_3649_27):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_3649_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_3649_27)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_3649_27)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_6f591279_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_open_redirect_3649_27)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-2ed26658c3a7f780","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_2030_22 = \"defensive\"\n\ndef load_lxml_xpath_injection_2030_22(payload_2030_22, context_2030_22):\n if HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_2030_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{context_2030_22}']\"\n return payload_2030_22.xpath(xpath)\n","fixed_code":"HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_2030_22 = \"defensive\"\n\ndef load_lxml_xpath_injection_2030_22(payload_2030_22, context_2030_22):\n if HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_2030_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_2030_22.xpath(\"//user[@name=$account]\", account=context_2030_22)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_2ed26658_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_xpath_injection_2030_22)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-bb7dd85a0efe2ca9","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2113_10 = \"defensive\"\n\ndef process_hardcoded_credentials_2113_10(request_2113_10):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2113_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000010\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2113_10)}\n","fixed_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2113_10 = \"defensive\"\n\ndef process_hardcoded_credentials_2113_10(request_2113_10):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2113_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2113_10)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_bb7dd85a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_hardcoded_credentials_2113_10)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-7752c36f4793fbd4","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_7733_13 = \"defensive\"\n\ndef process_zip_decompression_bomb_7733_13(payload_7733_13, context_7733_13):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_7733_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7733_13.extractall(context_7733_13)\n return context_7733_13\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_7733_13 = \"defensive\"\n\ndef process_zip_decompression_bomb_7733_13(payload_7733_13, context_7733_13):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_7733_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_7733_13.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_7733_13.extractall(context_7733_13)\n return context_7733_13\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_7752c36f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_7733_13)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-79409005b913afe6","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5699_16 = \"defensive\"\n\ndef load_starlette_permissive_cors_5699_16(payload_5699_16, policy_5699_16):\n if HANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5699_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5699_16.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return payload_5699_16\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5699_16 = \"defensive\"\n\ndef load_starlette_permissive_cors_5699_16(payload_5699_16, policy_5699_16):\n if HANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5699_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5699_16)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_5699_16.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_5699_16\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_79409005_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_starlette_permissive_cors_5699_16)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-2891f1de0b1d6ac3","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2226_19 = \"defensive\"\n\ndef process_command_injection_2226_19(subject_2226_19, target_2226_19):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2226_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_2226_19} {target_2226_19}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2226_19 = \"defensive\"\n\ndef process_command_injection_2226_19(subject_2226_19, target_2226_19):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2226_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_2226_19, target_2226_19], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_2891f1de_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_2226_19)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-c4932b7f5d2b5a0a","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7564_22 = \"defensive\"\n\ndef apply_dynamic_code_injection_7564_22(payload_7564_22):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7564_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(payload_7564_22, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7564_22 = \"defensive\"\n\ndef apply_dynamic_code_injection_7564_22(payload_7564_22):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_7564_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_7564_22) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_7564_22)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_c4932b7f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_7564_22)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-35ac913d80a89c39","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_1072_11 = \"defensive\"\n\ndef load_csv_formula_injection_1072_11(request_1072_11):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_1072_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_1072_11)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_1072_11 = \"defensive\"\n\ndef load_csv_formula_injection_1072_11(request_1072_11):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_1072_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_1072_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_35ac913d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_1072_11)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-6d1b917f74429739","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_6356_3 = \"defensive\"\n\ndef handle_csv_formula_injection_6356_3(request_6356_3):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_6356_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in request_6356_3)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_6356_3 = \"defensive\"\n\ndef handle_csv_formula_injection_6356_3(request_6356_3):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_6356_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_6356_3)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_6d1b917f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_6356_3)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-60f4b97a2274d4f0","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4783_17 = \"defensive\"\n\ndef handle_requests_tls_verification_4783_17(subject_4783_17):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4783_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_4783_17, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4783_17 = \"defensive\"\n\ndef handle_requests_tls_verification_4783_17(subject_4783_17):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_4783_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_4783_17, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_60f4b97a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_4783_17)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a4651e8cb44f5ca9","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_5741_29 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_5741_29(payload_5741_29, context_5741_29):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_5741_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_5741_29.execute(statement, {\"account_id\": context_5741_29}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_5741_29 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_5741_29(payload_5741_29, context_5741_29):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_5741_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_5741_29.execute(statement, {\"account_id\": context_5741_29}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_a4651e8c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_5741_29)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-a0037518599671cf","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_2865_10 = \"defensive\"\n\ndef resolve_flask_open_redirect_2865_10(subject_2865_10):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_2865_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(subject_2865_10)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_2865_10 = \"defensive\"\n\ndef resolve_flask_open_redirect_2865_10(subject_2865_10):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_2865_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_2865_10)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_2865_10)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_a0037518_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_2865_10)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-8db21fc0a8644e2b","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_9741_17 = \"defensive\"\n\ndef resolve_flask_jinja_xss_9741_17(value_9741_17):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_9741_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_9741_17)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_9741_17 = \"defensive\"\n\ndef resolve_flask_jinja_xss_9741_17(value_9741_17):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_9741_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_9741_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_8db21fc0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_9741_17)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-6736a1c4a37019ba","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5877_22 = \"defensive\"\n\ndef process_starlette_permissive_cors_5877_22(subject_5877_22, policy_5877_22):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5877_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5877_22.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_5877_22\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5877_22 = \"defensive\"\n\ndef process_starlette_permissive_cors_5877_22(subject_5877_22, policy_5877_22):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_5877_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_5877_22)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_5877_22.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_5877_22\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_6736a1c4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_5877_22)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-c011b16f50cda831","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_8328_18 = \"defensive\"\n\ndef handle_sensitive_data_exposure_8328_18(payload_8328_18, scope_8328_18, allowed_8328_18):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_8328_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8328_18.info(\"login user=%s password=%s\", scope_8328_18, allowed_8328_18)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_8328_18 = \"defensive\"\n\ndef handle_sensitive_data_exposure_8328_18(payload_8328_18, scope_8328_18, allowed_8328_18):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_8328_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8328_18.info(\"login user=%s\", scope_8328_18)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_c011b16f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_8328_18)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-e3d91f6bd6d494bd","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3455_20 = \"defensive\"\n\ndef process_mass_assignment_3455_20(request_3455_20, target_3455_20):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3455_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_3455_20.items() if key in allowed_fields}\n request_3455_20.update(safe)\n return request_3455_20\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3455_20 = \"defensive\"\n\ndef process_mass_assignment_3455_20(request_3455_20, target_3455_20):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3455_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_3455_20.items() if key in allowed_fields}\n request_3455_20.update(safe)\n return request_3455_20\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_e3d91f6b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_3455_20)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-4ec00dbc35dad192","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_4044_19 = \"defensive\"\n\ndef process_sensitive_data_exposure_4044_19(payload_4044_19, target_4044_19, owner_4044_19):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_4044_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4044_19.info(\"login user=%s password=%s\", target_4044_19, owner_4044_19)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_4044_19 = \"defensive\"\n\ndef process_sensitive_data_exposure_4044_19(payload_4044_19, target_4044_19, owner_4044_19):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_4044_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4044_19.info(\"login user=%s\", target_4044_19)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_4ec00dbc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_4044_19)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-9dc7faf43d24d86b","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9583_3 = \"defensive\"\n\ndef handle_plaintext_password_storage_9583_3(subject_9583_3, policy_9583_3, allowed_9583_3):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9583_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_9583_3).write_text(policy_9583_3, encoding=\"utf-8\")\n return Path(subject_9583_3)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9583_3 = \"defensive\"\n\ndef handle_plaintext_password_storage_9583_3(subject_9583_3, policy_9583_3, allowed_9583_3):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9583_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_9583_3) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_9583_3.encode(\"utf-8\"), allowed_9583_3, 240_000).hex()\n Path(subject_9583_3).write_text(verifier, encoding=\"ascii\")\n return Path(subject_9583_3)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_9dc7faf4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_9583_3)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-822160885e8b65da","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_3589_10 = \"defensive\"\n\ndef handle_ssrf_3589_10(value_3589_10, context_3589_10):\n if HANDLER_KIND_HANDLE_SSRF_3589_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_3589_10, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_3589_10 = \"defensive\"\n\ndef handle_ssrf_3589_10(value_3589_10, context_3589_10):\n if HANDLER_KIND_HANDLE_SSRF_3589_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_3589_10)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_3589_10):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_3589_10, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_82216088_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_3589_10)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-12f731004248da72","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7742_15 = \"defensive\"\n\ndef handle_starlette_permissive_cors_7742_15(payload_7742_15, scope_7742_15):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7742_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7742_15.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return payload_7742_15\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7742_15 = \"defensive\"\n\ndef handle_starlette_permissive_cors_7742_15(payload_7742_15, scope_7742_15):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_7742_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_7742_15)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_7742_15.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_7742_15\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_12f73100_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_starlette_permissive_cors_7742_15)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-aaee91eb95e93dbe","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_4419_26 = \"defensive\"\n\ndef apply_dynamic_code_injection_4419_26(subject_4419_26):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_4419_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4419_26) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_4419_26)\n","fixed_code":"import ast\n\nHANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_4419_26 = \"defensive\"\n\ndef apply_dynamic_code_injection_4419_26(subject_4419_26):\n if HANDLER_KIND_APPLY_DYNAMIC_CODE_INJECTION_4419_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4419_26) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_4419_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_aaee91eb_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_dynamic_code_injection_4419_26)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-ac497eaee7a4d350","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5270_5 = \"defensive\"\n\ndef resolve_http_response_splitting_5270_5(request_5270_5, target_5270_5):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5270_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_5270_5 or \"\\n\" in target_5270_5:\n raise ValueError(\"invalid header value\")\n request_5270_5.headers[\"X-Next\"] = target_5270_5\n return request_5270_5\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5270_5 = \"defensive\"\n\ndef resolve_http_response_splitting_5270_5(request_5270_5, target_5270_5):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_5270_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_5270_5 or \"\\n\" in target_5270_5:\n raise ValueError(\"invalid header value\")\n request_5270_5.headers[\"X-Next\"] = target_5270_5\n return request_5270_5\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_ac497eae_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_5270_5)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-145cff890fc6cfcc","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2105_16 = \"defensive\"\n\ndef process_log_injection_2105_16(payload_2105_16, policy_2105_16):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2105_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2105_16.warning(\"audit=%s\", policy_2105_16)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_2105_16 = \"defensive\"\n\ndef process_log_injection_2105_16(payload_2105_16, policy_2105_16):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_2105_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_2105_16).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_2105_16.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_145cff89_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_2105_16)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-07f2e38bd0fc2fda","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_2613_5 = \"defensive\"\n\ndef process_sensitive_data_exposure_2613_5(payload_2613_5, target_2613_5, options_2613_5):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_2613_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2613_5.info(\"login user=%s\", target_2613_5)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_2613_5 = \"defensive\"\n\ndef process_sensitive_data_exposure_2613_5(payload_2613_5, target_2613_5, options_2613_5):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_2613_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2613_5.info(\"login user=%s\", target_2613_5)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_07f2e38b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_2613_5)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-ac4ef461a9d52115","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_9345_26 = \"defensive\"\n\ndef apply_cleartext_http_transport_9345_26(payload_9345_26):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_9345_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_9345_26, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_9345_26 = \"defensive\"\n\ndef apply_cleartext_http_transport_9345_26(payload_9345_26):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_9345_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_9345_26, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_ac4ef461_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_9345_26)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-c5638c57b956c62f","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_8202_16 = \"defensive\"\n\ndef resolve_sql_injection_8202_16(request_8202_16, policy_8202_16):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_8202_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {policy_8202_16}\"\n return request_8202_16.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_8202_16 = \"defensive\"\n\ndef resolve_sql_injection_8202_16(request_8202_16, policy_8202_16):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_8202_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_8202_16.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (policy_8202_16,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_c5638c57_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_8202_16)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-b702a43a1bd47e43","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4065_4 = \"defensive\"\n\ndef load_mass_assignment_4065_4(request_4065_4, policy_4065_4):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4065_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_4065_4.items():\n setattr(request_4065_4, key, value)\n return request_4065_4\n","fixed_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4065_4 = \"defensive\"\n\ndef load_mass_assignment_4065_4(request_4065_4, policy_4065_4):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_4065_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_4065_4.items() if key in allowed_fields}\n request_4065_4.update(safe)\n return request_4065_4\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_b702a43a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_mass_assignment_4065_4)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-6cf5bc7facc83973","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_2498_6 = \"defensive\"\n\ndef resolve_regex_dos_2498_6(payload_2498_6, scope_2498_6):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_2498_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_2498_6, scope_2498_6) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_2498_6 = \"defensive\"\n\ndef resolve_regex_dos_2498_6(payload_2498_6, scope_2498_6):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_2498_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_2498_6) > 256 or len(scope_2498_6) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_2498_6), scope_2498_6) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_6cf5bc7f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_regex_dos_2498_6)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-edbaf0e1f910c474","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_8433_17 = \"defensive\"\n\ndef resolve_resource_consumption_8433_17(value_8433_17, policy_8433_17):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_8433_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_8433_17), 1), 1_048_576)\n data = value_8433_17.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_8433_17 = \"defensive\"\n\ndef resolve_resource_consumption_8433_17(value_8433_17, policy_8433_17):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_8433_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_8433_17), 1), 1_048_576)\n data = value_8433_17.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_edbaf0e1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_8433_17)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-077ebc740a73fde4","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5346_22 = \"defensive\"\n\ndef handle_requests_tls_verification_5346_22(value_5346_22):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5346_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_5346_22, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5346_22 = \"defensive\"\n\ndef handle_requests_tls_verification_5346_22(value_5346_22):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5346_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_5346_22, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_077ebc74_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_5346_22)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-47cf6276ffff60f5","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_6604_26 = \"defensive\"\n\ndef handle_sql_injection_6604_26(request_6604_26, scope_6604_26):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_6604_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_6604_26.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (scope_6604_26,)).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_6604_26 = \"defensive\"\n\ndef handle_sql_injection_6604_26(request_6604_26, scope_6604_26):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_6604_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_6604_26.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (scope_6604_26,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_47cf6276_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_6604_26)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-8eec92b677966b74","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7042_3 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7042_3(subject_7042_3, policy_7042_3):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7042_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7042_3.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_7042_3\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7042_3 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_7042_3(subject_7042_3, policy_7042_3):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_7042_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_7042_3)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_7042_3.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_7042_3\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_8eec92b6_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_7042_3)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-bdb451ef80606bcb","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_4958_17 = \"defensive\"\n\ndef resolve_insecure_temp_file_4958_17(subject_4958_17, scope_4958_17):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_4958_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_4958_17)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_4958_17 = \"defensive\"\n\ndef resolve_insecure_temp_file_4958_17(subject_4958_17, scope_4958_17):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_4958_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_4958_17)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_bdb451ef_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_4958_17)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-f655a9bbdfc4a153","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5463_2 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5463_2(value_5463_2):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5463_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5463_2.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5463_2 = \"defensive\"\n\ndef resolve_unsafe_deserialization_5463_2(value_5463_2):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_5463_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_5463_2.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_f655a9bb_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_5463_2)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-a46b50e7399aca67","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_1863_12 = \"defensive\"\n\ndef resolve_ldap_filter_injection_1863_12(request_1863_12, context_1863_12):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_1863_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_1863_12})\"\n return request_1863_12.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_1863_12 = \"defensive\"\n\ndef resolve_ldap_filter_injection_1863_12(request_1863_12, context_1863_12):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_1863_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_1863_12)\n query = f\"(uid={escaped})\"\n return request_1863_12.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_a46b50e7_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_1863_12)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-1cfe7689065f596c","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7121_7 = \"defensive\"\n\ndef process_lxml_xpath_injection_7121_7(request_7121_7, target_7121_7):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7121_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{target_7121_7}']\"\n return request_7121_7.xpath(xpath)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7121_7 = \"defensive\"\n\ndef process_lxml_xpath_injection_7121_7(request_7121_7, target_7121_7):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_7121_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7121_7.xpath(\"//user[@name=$account]\", account=target_7121_7)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_1cfe7689_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_7121_7)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-c18eb4b40b43fd4d","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_2588_21 = \"defensive\"\n\ndef load_path_traversal_2588_21(payload_2588_21, target_2588_21):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_2588_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_2588_21) / target_2588_21).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_2588_21 = \"defensive\"\n\ndef load_path_traversal_2588_21(payload_2588_21, target_2588_21):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_2588_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_2588_21).resolve()\n candidate = (root / target_2588_21).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_c18eb4b4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_path_traversal_2588_21)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-8d14c92d5517cb74","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_2617_2 = \"defensive\"\n\ndef apply_plaintext_password_storage_2617_2(value_2617_2, scope_2617_2, owner_2617_2):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_2617_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_2617_2) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_2617_2.encode(\"utf-8\"), owner_2617_2, 240_000).hex()\n Path(value_2617_2).write_text(verifier, encoding=\"ascii\")\n return Path(value_2617_2)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_2617_2 = \"defensive\"\n\ndef apply_plaintext_password_storage_2617_2(value_2617_2, scope_2617_2, owner_2617_2):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_2617_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_2617_2) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_2617_2.encode(\"utf-8\"), owner_2617_2, 240_000).hex()\n Path(value_2617_2).write_text(verifier, encoding=\"ascii\")\n return Path(value_2617_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_8d14c92d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_plaintext_password_storage_2617_2)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-071a5ab1e22abef0","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4600_0 = \"defensive\"\n\ndef process_flask_session_fixation_4600_0(value_4600_0, context_4600_0):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4600_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4600_0[\"user_id\"] = context_4600_0.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4600_0 = \"defensive\"\n\ndef process_flask_session_fixation_4600_0(value_4600_0, context_4600_0):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_4600_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4600_0.clear()\n value_4600_0[\"user_id\"] = context_4600_0.id\n value_4600_0[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_071a5ab1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_4600_0)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-cb3007b816be905e","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6504_0 = \"defensive\"\n\ndef apply_missing_authorization_6504_0(request_6504_0, target_6504_0):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6504_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n target_6504_0.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6504_0 = \"defensive\"\n\ndef apply_missing_authorization_6504_0(request_6504_0, target_6504_0):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6504_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_6504_0.id != target_6504_0.owner_id:\n raise PermissionError(\"record ownership required\")\n target_6504_0.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_cb3007b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_6504_0)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-f7ca1f6004f65c87","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1458_0 = \"defensive\"\n\ndef handle_regex_dos_1458_0(subject_1458_0, policy_1458_0):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1458_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_1458_0, policy_1458_0) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_1458_0 = \"defensive\"\n\ndef handle_regex_dos_1458_0(subject_1458_0, policy_1458_0):\n if HANDLER_KIND_HANDLE_REGEX_DOS_1458_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1458_0) > 256 or len(policy_1458_0) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1458_0), policy_1458_0) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_f7ca1f60_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_1458_0)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-fbfc70f7ad308d5e","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1077_5 = \"defensive\"\n\ndef handle_lxml_xpath_injection_1077_5(request_1077_5, scope_1077_5):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1077_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1077_5.xpath(\"//user[@name=$account]\", account=scope_1077_5)\n","fixed_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1077_5 = \"defensive\"\n\ndef handle_lxml_xpath_injection_1077_5(request_1077_5, scope_1077_5):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1077_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1077_5.xpath(\"//user[@name=$account]\", account=scope_1077_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_fbfc70f7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_xpath_injection_1077_5)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-2cec92661cbb2272","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1951_7 = \"defensive\"\n\ndef process_starlette_permissive_cors_1951_7(request_1951_7, scope_1951_7):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1951_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1951_7.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return request_1951_7\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1951_7 = \"defensive\"\n\ndef process_starlette_permissive_cors_1951_7(request_1951_7, scope_1951_7):\n if HANDLER_KIND_PROCESS_STARLETTE_PERMISSIVE_CORS_1951_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_1951_7)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_1951_7.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_1951_7\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_2cec9266_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_starlette_permissive_cors_1951_7)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-b3f894e4ec34d82a","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4138_27 = \"defensive\"\n\ndef process_mass_assignment_4138_27(request_4138_27, target_4138_27):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4138_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in target_4138_27.items():\n setattr(request_4138_27, key, value)\n return request_4138_27\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4138_27 = \"defensive\"\n\ndef process_mass_assignment_4138_27(request_4138_27, target_4138_27):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_4138_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_4138_27.items() if key in allowed_fields}\n request_4138_27.update(safe)\n return request_4138_27\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_b3f894e4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_4138_27)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-6141e4df4191cf49","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_2499_23 = \"defensive\"\n\ndef apply_http_response_splitting_2499_23(payload_2499_23, policy_2499_23):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_2499_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_2499_23 or \"\\n\" in policy_2499_23:\n raise ValueError(\"invalid header value\")\n payload_2499_23.headers[\"X-Next\"] = policy_2499_23\n return payload_2499_23\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_2499_23 = \"defensive\"\n\ndef apply_http_response_splitting_2499_23(payload_2499_23, policy_2499_23):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_2499_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_2499_23 or \"\\n\" in policy_2499_23:\n raise ValueError(\"invalid header value\")\n payload_2499_23.headers[\"X-Next\"] = policy_2499_23\n return payload_2499_23\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_6141e4df_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_2499_23)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-36dbdb2d2a7117fe","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_6287_16 = \"defensive\"\n\ndef apply_command_injection_6287_16(value_6287_16, policy_6287_16):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_6287_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {value_6287_16} {policy_6287_16}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_6287_16 = \"defensive\"\n\ndef apply_command_injection_6287_16(value_6287_16, policy_6287_16):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_6287_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", value_6287_16, policy_6287_16], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_36dbdb2d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_6287_16)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-8067756d69f03f7a","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_9060_27 = \"defensive\"\n\ndef handle_ssrf_9060_27(payload_9060_27, scope_9060_27):\n if HANDLER_KIND_HANDLE_SSRF_9060_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_9060_27, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_9060_27 = \"defensive\"\n\ndef handle_ssrf_9060_27(payload_9060_27, scope_9060_27):\n if HANDLER_KIND_HANDLE_SSRF_9060_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9060_27)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_9060_27):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_9060_27, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_8067756d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_9060_27)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-ce94a317c1d2b37f","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7552_13 = \"defensive\"\n\ndef load_cleartext_http_transport_7552_13(value_7552_13):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7552_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_7552_13, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7552_13 = \"defensive\"\n\ndef load_cleartext_http_transport_7552_13(value_7552_13):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7552_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_7552_13, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_ce94a317_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_7552_13)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-8c19a77378d9c4c6","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_8798_19 = \"defensive\"\n\ndef apply_http_response_splitting_8798_19(payload_8798_19, target_8798_19):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_8798_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8798_19.headers[\"X-Next\"] = target_8798_19\n return payload_8798_19\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_8798_19 = \"defensive\"\n\ndef apply_http_response_splitting_8798_19(payload_8798_19, target_8798_19):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_8798_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_8798_19 or \"\\n\" in target_8798_19:\n raise ValueError(\"invalid header value\")\n payload_8798_19.headers[\"X-Next\"] = target_8798_19\n return payload_8798_19\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_8c19a773_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_8798_19)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-68e51a7efce68c81","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_5250_9 = \"defensive\"\n\ndef load_hardcoded_credentials_5250_9(value_5250_9):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_5250_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000009\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_5250_9)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_5250_9 = \"defensive\"\n\ndef load_hardcoded_credentials_5250_9(value_5250_9):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_5250_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_5250_9)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_68e51a7e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_5250_9)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-a32ef3ccde222388","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3680_18 = \"defensive\"\n\ndef handle_flask_open_redirect_3680_18(value_3680_18):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3680_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_3680_18)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3680_18 = \"defensive\"\n\ndef handle_flask_open_redirect_3680_18(value_3680_18):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3680_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_3680_18)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_3680_18)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_a32ef3cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_3680_18)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-2a281bf83bb6336f","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_3727_10 = \"defensive\"\n\ndef resolve_django_error_details_3727_10(subject_3727_10, policy_3727_10):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_3727_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_3727_10()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_3727_10 = \"defensive\"\n\ndef resolve_django_error_details_3727_10(subject_3727_10, policy_3727_10):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_3727_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_3727_10()\n except Exception:\n subject_3727_10.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_2a281bf8_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_3727_10)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-655176ee96af1c36","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9069_25 = \"defensive\"\n\ndef apply_insecure_file_permissions_9069_25(payload_9069_25, scope_9069_25):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9069_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9069_25).write_text(scope_9069_25, encoding=\"utf-8\")\n os.chmod(payload_9069_25, 0o777)\n return Path(payload_9069_25)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9069_25 = \"defensive\"\n\ndef apply_insecure_file_permissions_9069_25(payload_9069_25, scope_9069_25):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_9069_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9069_25).write_text(scope_9069_25, encoding=\"utf-8\")\n os.chmod(payload_9069_25, 0o600)\n return Path(payload_9069_25)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_655176ee_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_9069_25)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-96bfb62524ee9d4b","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_7079_28 = \"defensive\"\n\ndef process_csv_formula_injection_7079_28(payload_7079_28):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_7079_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_7079_28)\n","fixed_code":"HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_7079_28 = \"defensive\"\n\ndef process_csv_formula_injection_7079_28(payload_7079_28):\n if HANDLER_KIND_PROCESS_CSV_FORMULA_INJECTION_7079_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7079_28)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_96bfb625_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_csv_formula_injection_7079_28)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-1904a97d7e37d91f","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_7624_14 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_7624_14(request_7624_14, policy_7624_14):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_7624_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_7624_14.execute(statement, {\"account_id\": policy_7624_14}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_7624_14 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_7624_14(request_7624_14, policy_7624_14):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_7624_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_7624_14.execute(statement, {\"account_id\": policy_7624_14}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_1904a97d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sqlalchemy_text_injection_7624_14)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-2e8dacb7aeedff1c","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_9805_19 = \"defensive\"\n\ndef resolve_ldap_filter_injection_9805_19(payload_9805_19, context_9805_19):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_9805_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_9805_19})\"\n return payload_9805_19.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_9805_19 = \"defensive\"\n\ndef resolve_ldap_filter_injection_9805_19(payload_9805_19, context_9805_19):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_9805_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_9805_19)\n query = f\"(uid={escaped})\"\n return payload_9805_19.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_2e8dacb7_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_9805_19)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-54484901c39534a4","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_5587_28 = \"defensive\"\n\ndef process_sql_injection_5587_28(payload_5587_28, context_5587_28):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_5587_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {context_5587_28}\"\n return payload_5587_28.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_5587_28 = \"defensive\"\n\ndef process_sql_injection_5587_28(payload_5587_28, context_5587_28):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_5587_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_5587_28.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (context_5587_28,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_54484901_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_5587_28)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-e8d97a4509bb68e1","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5870_14 = \"defensive\"\n\ndef load_cleartext_http_transport_5870_14(request_5870_14):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5870_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=request_5870_14, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5870_14 = \"defensive\"\n\ndef load_cleartext_http_transport_5870_14(request_5870_14):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_5870_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=request_5870_14, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_e8d97a45_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_5870_14)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-6e9a11d51884cdf9","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5652_20 = \"defensive\"\n\ndef load_starlette_permissive_cors_5652_20(request_5652_20, scope_5652_20):\n if HANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5652_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_5652_20)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_5652_20.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_5652_20\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5652_20 = \"defensive\"\n\ndef load_starlette_permissive_cors_5652_20(request_5652_20, scope_5652_20):\n if HANDLER_KIND_LOAD_STARLETTE_PERMISSIVE_CORS_5652_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_5652_20)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_5652_20.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_5652_20\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_6e9a11d5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_starlette_permissive_cors_5652_20)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9ffc2442196c2845","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_3181_13 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_3181_13(value_3181_13, policy_3181_13):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_3181_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_3181_13}\")\n return value_3181_13.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_3181_13 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_3181_13(value_3181_13, policy_3181_13):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_3181_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_3181_13.execute(statement, {\"account_id\": policy_3181_13}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_9ffc2442_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_3181_13)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-e7f752833e4ad7eb","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_2374_24 = \"defensive\"\n\ndef resolve_mass_assignment_2374_24(request_2374_24, policy_2374_24):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_2374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_2374_24.items():\n setattr(request_2374_24, key, value)\n return request_2374_24\n","fixed_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_2374_24 = \"defensive\"\n\ndef resolve_mass_assignment_2374_24(request_2374_24, policy_2374_24):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_2374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_2374_24.items() if key in allowed_fields}\n request_2374_24.update(safe)\n return request_2374_24\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_e7f75283_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_mass_assignment_2374_24)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-8ac0431588f2f1a2","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3308_2 = \"defensive\"\n\ndef apply_starlette_permissive_cors_3308_2(value_3308_2, target_3308_2):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3308_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_3308_2)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3308_2.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3308_2\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3308_2 = \"defensive\"\n\ndef apply_starlette_permissive_cors_3308_2(value_3308_2, target_3308_2):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3308_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_3308_2)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3308_2.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3308_2\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_8ac04315_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_3308_2)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-8d77befd7368b27d","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_5236_10 = \"defensive\"\n\ndef handle_path_traversal_5236_10(value_5236_10, scope_5236_10):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_5236_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_5236_10) / scope_5236_10).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_5236_10 = \"defensive\"\n\ndef handle_path_traversal_5236_10(value_5236_10, scope_5236_10):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_5236_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_5236_10).resolve()\n candidate = (root / scope_5236_10).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_8d77befd_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_5236_10)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-a18e951559c8ceb0","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_8841_1 = \"defensive\"\n\ndef resolve_missing_authorization_8841_1(request_8841_1, scope_8841_1):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_8841_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n scope_8841_1.delete()\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_8841_1 = \"defensive\"\n\ndef resolve_missing_authorization_8841_1(request_8841_1, scope_8841_1):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_8841_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_8841_1.id != scope_8841_1.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_8841_1.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_a18e9515_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_missing_authorization_8841_1)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-832162aab03bcabf","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_4719_21 = \"defensive\"\n\ndef load_plaintext_password_storage_4719_21(request_4719_21, target_4719_21, owner_4719_21):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_4719_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_4719_21).write_text(target_4719_21, encoding=\"utf-8\")\n return Path(request_4719_21)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_4719_21 = \"defensive\"\n\ndef load_plaintext_password_storage_4719_21(request_4719_21, target_4719_21, owner_4719_21):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_4719_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_4719_21) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_4719_21.encode(\"utf-8\"), owner_4719_21, 240_000).hex()\n Path(request_4719_21).write_text(verifier, encoding=\"ascii\")\n return Path(request_4719_21)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_832162aa_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_4719_21)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-55be6fa54cfb317e","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_3497_26 = \"defensive\"\n\ndef apply_insecure_random_token_3497_26(payload_3497_26):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_3497_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_3497_26)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_3497_26 = \"defensive\"\n\ndef apply_insecure_random_token_3497_26(payload_3497_26):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_3497_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_3497_26)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_55be6fa5_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_3497_26)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-9d94e83e46048ee2","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7481_11 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_7481_11(subject_7481_11, scope_7481_11, limit_7481_11):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7481_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7481_11.info(\"login user=%s\", scope_7481_11)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7481_11 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_7481_11(subject_7481_11, scope_7481_11, limit_7481_11):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_7481_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7481_11.info(\"login user=%s\", scope_7481_11)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_9d94e83e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sensitive_data_exposure_7481_11)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-d4b6dfe45acb758a","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1373_10 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1373_10(value_1373_10, context_1373_10):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1373_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_1373_10.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1373_10 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1373_10(value_1373_10, context_1373_10):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1373_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_1373_10 is None or not value_1373_10.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_1373_10.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_d4b6dfe4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_1373_10)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-ca0e48e3d9c76c44","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_6768_28 = \"defensive\"\n\ndef apply_flask_jinja_xss_6768_28(request_6768_28):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_6768_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(request_6768_28)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_APPLY_FLASK_JINJA_XSS_6768_28 = \"defensive\"\n\ndef apply_flask_jinja_xss_6768_28(request_6768_28):\n if HANDLER_KIND_APPLY_FLASK_JINJA_XSS_6768_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(request_6768_28)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_ca0e48e3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_jinja_xss_6768_28)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-eae01e0c63e5708a","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9380_12 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_9380_12(payload_9380_12):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9380_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(payload_9380_12, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9380_12 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_9380_12(payload_9380_12):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_9380_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_9380_12)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_eae01e0c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyyaml_unsafe_load_9380_12)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-18ba026334b63001","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3220_26 = \"defensive\"\n\ndef apply_http_response_splitting_3220_26(subject_3220_26, scope_3220_26):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3220_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_3220_26 or \"\\n\" in scope_3220_26:\n raise ValueError(\"invalid header value\")\n subject_3220_26.headers[\"X-Next\"] = scope_3220_26\n return subject_3220_26\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3220_26 = \"defensive\"\n\ndef apply_http_response_splitting_3220_26(subject_3220_26, scope_3220_26):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3220_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_3220_26 or \"\\n\" in scope_3220_26:\n raise ValueError(\"invalid header value\")\n subject_3220_26.headers[\"X-Next\"] = scope_3220_26\n return subject_3220_26\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_18ba0263_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_3220_26)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-3054185f4b36484d","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_9932_6 = \"defensive\"\n\ndef apply_flask_session_fixation_9932_6(value_9932_6, policy_9932_6):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_9932_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9932_6[\"user_id\"] = policy_9932_6.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_9932_6 = \"defensive\"\n\ndef apply_flask_session_fixation_9932_6(value_9932_6, policy_9932_6):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_9932_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_9932_6.clear()\n value_9932_6[\"user_id\"] = policy_9932_6.id\n value_9932_6[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_3054185f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_9932_6)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-e85b780b80458d9c","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_3669_1 = \"defensive\"\n\ndef process_lxml_external_entity_3669_1(subject_3669_1):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_3669_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(subject_3669_1)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_3669_1 = \"defensive\"\n\ndef process_lxml_external_entity_3669_1(subject_3669_1):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_3669_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_3669_1, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_e85b780b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_external_entity_3669_1)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-724e6d952e1a022e","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_SSRF_2528_18 = \"defensive\"\n\ndef process_ssrf_2528_18(payload_2528_18, context_2528_18):\n if HANDLER_KIND_PROCESS_SSRF_2528_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_2528_18, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_2528_18 = \"defensive\"\n\ndef process_ssrf_2528_18(payload_2528_18, context_2528_18):\n if HANDLER_KIND_PROCESS_SSRF_2528_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_2528_18)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_2528_18):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_2528_18, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_724e6d95_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ssrf_2528_18)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-972c35c8e6bd273a","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_8866_9 = \"defensive\"\n\ndef process_sql_injection_8866_9(value_8866_9, context_8866_9):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_8866_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {context_8866_9}\"\n return value_8866_9.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_8866_9 = \"defensive\"\n\ndef process_sql_injection_8866_9(value_8866_9, context_8866_9):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_8866_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_8866_9.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (context_8866_9,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_972c35c8_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_8866_9)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-46559fca5d0df30a","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_3754_16 = \"defensive\"\n\ndef resolve_path_traversal_3754_16(subject_3754_16, scope_3754_16):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_3754_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(subject_3754_16) / scope_3754_16).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_3754_16 = \"defensive\"\n\ndef resolve_path_traversal_3754_16(subject_3754_16, scope_3754_16):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_3754_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_3754_16).resolve()\n candidate = (root / scope_3754_16).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_46559fca_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_path_traversal_3754_16)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a25a89d84a9c88da","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3056_5 = \"defensive\"\n\ndef process_httpx_client_ssrf_3056_5(value_3056_5, context_3056_5, owner_3056_5):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3056_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_3056_5)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3056_5):\n raise ValueError(\"destination is not allowed\")\n return value_3056_5.get(context_3056_5, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3056_5 = \"defensive\"\n\ndef process_httpx_client_ssrf_3056_5(value_3056_5, context_3056_5, owner_3056_5):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3056_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_3056_5)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3056_5):\n raise ValueError(\"destination is not allowed\")\n return value_3056_5.get(context_3056_5, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_a25a89d8_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_3056_5)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-aec5037df200bdbd","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":false,"vulnerable_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_6002_20 = \"defensive\"\n\ndef resolve_flask_jinja_xss_6002_20(value_6002_20):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_6002_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_6002_20)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_6002_20 = \"defensive\"\n\ndef resolve_flask_jinja_xss_6002_20(value_6002_20):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_6002_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_6002_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_jinja_xss_aec5037d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_6002_20)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-9f885407b02f0dfe","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4858_0 = \"defensive\"\n\ndef apply_resource_consumption_4858_0(request_4858_0, scope_4858_0):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4858_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4858_0.read(int(scope_4858_0))\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4858_0 = \"defensive\"\n\ndef apply_resource_consumption_4858_0(request_4858_0, scope_4858_0):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4858_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_4858_0), 1), 1_048_576)\n data = request_4858_0.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_9f885407_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_4858_0)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-74dab032d8ae5a85","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_8626_3 = \"defensive\"\n\ndef handle_insecure_file_permissions_8626_3(payload_8626_3, context_8626_3):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_8626_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_8626_3).write_text(context_8626_3, encoding=\"utf-8\")\n os.chmod(payload_8626_3, 0o777)\n return Path(payload_8626_3)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_8626_3 = \"defensive\"\n\ndef handle_insecure_file_permissions_8626_3(payload_8626_3, context_8626_3):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_8626_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_8626_3).write_text(context_8626_3, encoding=\"utf-8\")\n os.chmod(payload_8626_3, 0o600)\n return Path(payload_8626_3)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_74dab032_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_8626_3)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-007dacbb5ee2f6c4","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_7747_12 = \"defensive\"\n\ndef resolve_hardcoded_credentials_7747_12(value_7747_12):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_7747_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000012\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_7747_12)}\n","fixed_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_7747_12 = \"defensive\"\n\ndef resolve_hardcoded_credentials_7747_12(value_7747_12):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_7747_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_7747_12)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_007dacbb_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_hardcoded_credentials_7747_12)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-2fe0ca5a4d0391e9","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2928_1 = \"defensive\"\n\ndef load_django_safe_string_xss_2928_1(value_2928_1):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2928_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{value_2928_1}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2928_1 = \"defensive\"\n\ndef load_django_safe_string_xss_2928_1(value_2928_1):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_2928_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_2928_1)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_2fe0ca5a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_2928_1)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-445f391e35cd0857","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_3688_3 = \"defensive\"\n\ndef apply_path_traversal_3688_3(payload_3688_3, target_3688_3):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_3688_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_3688_3) / target_3688_3).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_3688_3 = \"defensive\"\n\ndef apply_path_traversal_3688_3(payload_3688_3, target_3688_3):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_3688_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_3688_3).resolve()\n candidate = (root / target_3688_3).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_445f391e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_3688_3)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-00084451a1f407f5","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6069_14 = \"defensive\"\n\ndef handle_plaintext_password_storage_6069_14(payload_6069_14, scope_6069_14, limit_6069_14):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6069_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_6069_14) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_6069_14.encode(\"utf-8\"), limit_6069_14, 240_000).hex()\n Path(payload_6069_14).write_text(verifier, encoding=\"ascii\")\n return Path(payload_6069_14)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6069_14 = \"defensive\"\n\ndef handle_plaintext_password_storage_6069_14(payload_6069_14, scope_6069_14, limit_6069_14):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_6069_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_6069_14) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_6069_14.encode(\"utf-8\"), limit_6069_14, 240_000).hex()\n Path(payload_6069_14).write_text(verifier, encoding=\"ascii\")\n return Path(payload_6069_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_00084451_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_6069_14)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-4afe3282f2864e2c","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_3449_15 = \"defensive\"\n\ndef load_hardcoded_credentials_3449_15(subject_3449_15):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_3449_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000015\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_3449_15)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_3449_15 = \"defensive\"\n\ndef load_hardcoded_credentials_3449_15(subject_3449_15):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_3449_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_3449_15)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_4afe3282_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_3449_15)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-a18df0561406a6ff","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_6475_26 = \"defensive\"\n\ndef handle_flask_open_redirect_6475_26(payload_6475_26):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_6475_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_6475_26)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_6475_26)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_6475_26 = \"defensive\"\n\ndef handle_flask_open_redirect_6475_26(payload_6475_26):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_6475_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_6475_26)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_6475_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_a18df056_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_6475_26)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-9b5b1d6a5121ba0b","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_7691_8 = \"defensive\"\n\ndef apply_command_injection_7691_8(payload_7691_8, scope_7691_8):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_7691_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_7691_8, scope_7691_8], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_7691_8 = \"defensive\"\n\ndef apply_command_injection_7691_8(payload_7691_8, scope_7691_8):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_7691_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_7691_8, scope_7691_8], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_9b5b1d6a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_7691_8)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-23bb445b0c457b52","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7865_2 = \"defensive\"\n\ndef apply_insecure_random_token_7865_2(request_7865_2):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7865_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_7865_2)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7865_2 = \"defensive\"\n\ndef apply_insecure_random_token_7865_2(request_7865_2):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_7865_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_7865_2)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_23bb445b_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_7865_2)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-f1afbf47cfb242a1","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_4851_17 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_4851_17(subject_4851_17, policy_4851_17):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_4851_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_4851_17.execute(statement, {\"account_id\": policy_4851_17}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_4851_17 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_4851_17(subject_4851_17, policy_4851_17):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_4851_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_4851_17.execute(statement, {\"account_id\": policy_4851_17}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_f1afbf47_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sqlalchemy_text_injection_4851_17)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-baf3920fe3dcecde","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_2878_16 = \"defensive\"\n\ndef handle_insecure_file_permissions_2878_16(payload_2878_16, scope_2878_16):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_2878_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_2878_16).write_text(scope_2878_16, encoding=\"utf-8\")\n os.chmod(payload_2878_16, 0o777)\n return Path(payload_2878_16)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_2878_16 = \"defensive\"\n\ndef handle_insecure_file_permissions_2878_16(payload_2878_16, scope_2878_16):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_2878_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_2878_16).write_text(scope_2878_16, encoding=\"utf-8\")\n os.chmod(payload_2878_16, 0o600)\n return Path(payload_2878_16)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_baf3920f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_2878_16)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-23d4ab4e519d5e5f","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_6147_5 = \"defensive\"\n\ndef load_hardcoded_credentials_6147_5(request_6147_5):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_6147_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_6147_5)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_6147_5 = \"defensive\"\n\ndef load_hardcoded_credentials_6147_5(request_6147_5):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_6147_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_6147_5)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_23d4ab4e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_6147_5)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-20b7eec0e04da668","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_5385_29 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_5385_29(payload_5385_29, context_5385_29, allowed_5385_29):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_5385_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5385_29.info(\"login user=%s\", context_5385_29)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_5385_29 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_5385_29(payload_5385_29, context_5385_29, allowed_5385_29):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_5385_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5385_29.info(\"login user=%s\", context_5385_29)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_20b7eec0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sensitive_data_exposure_5385_29)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-db7d4d5eb8e815d0","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_7309_9 = \"defensive\"\n\ndef handle_ssrf_7309_9(subject_7309_9, policy_7309_9):\n if HANDLER_KIND_HANDLE_SSRF_7309_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_7309_9, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_7309_9 = \"defensive\"\n\ndef handle_ssrf_7309_9(subject_7309_9, policy_7309_9):\n if HANDLER_KIND_HANDLE_SSRF_7309_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_7309_9)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_7309_9):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_7309_9, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_db7d4d5e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_7309_9)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-d382ea8ba3ed9f99","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_5904_10 = \"defensive\"\n\ndef load_mass_assignment_5904_10(payload_5904_10, policy_5904_10):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_5904_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_5904_10.items():\n setattr(payload_5904_10, key, value)\n return payload_5904_10\n","fixed_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_5904_10 = \"defensive\"\n\ndef load_mass_assignment_5904_10(payload_5904_10, policy_5904_10):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_5904_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_5904_10.items() if key in allowed_fields}\n payload_5904_10.update(safe)\n return payload_5904_10\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_d382ea8b_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_mass_assignment_5904_10)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-4db266b811fccce3","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_3548_2 = \"defensive\"\n\ndef handle_django_safe_string_xss_3548_2(value_3548_2):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_3548_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_3548_2)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_3548_2 = \"defensive\"\n\ndef handle_django_safe_string_xss_3548_2(value_3548_2):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_3548_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_3548_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_4db266b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_3548_2)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-db35b37c617c189d","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3598_10 = \"defensive\"\n\ndef process_plaintext_password_storage_3598_10(subject_3598_10, policy_3598_10, options_3598_10):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3598_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_3598_10).write_text(policy_3598_10, encoding=\"utf-8\")\n return Path(subject_3598_10)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3598_10 = \"defensive\"\n\ndef process_plaintext_password_storage_3598_10(subject_3598_10, policy_3598_10, options_3598_10):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3598_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_3598_10) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_3598_10.encode(\"utf-8\"), options_3598_10, 240_000).hex()\n Path(subject_3598_10).write_text(verifier, encoding=\"ascii\")\n return Path(subject_3598_10)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_db35b37c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_3598_10)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-20a10ed5d3e7139d","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_4897_16 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_4897_16(value_4897_16, context_4897_16):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_4897_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_4897_16.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_4897_16 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_4897_16(value_4897_16, context_4897_16):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_4897_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_4897_16 is None or not value_4897_16.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_4897_16.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_20a10ed5_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_missing_authentication_4897_16)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-cfced42a958659ab","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_2987_23 = \"defensive\"\n\ndef apply_sqlalchemy_text_injection_2987_23(subject_2987_23, scope_2987_23):\n if HANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_2987_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_2987_23.execute(statement, {\"account_id\": scope_2987_23}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_2987_23 = \"defensive\"\n\ndef apply_sqlalchemy_text_injection_2987_23(subject_2987_23, scope_2987_23):\n if HANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_2987_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_2987_23.execute(statement, {\"account_id\": scope_2987_23}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_cfced42a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sqlalchemy_text_injection_2987_23)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-5b42f04eee18d314","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7214_2 = \"defensive\"\n\ndef handle_ldap_filter_injection_7214_2(value_7214_2, scope_7214_2):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7214_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_7214_2)\n query = f\"(uid={escaped})\"\n return value_7214_2.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7214_2 = \"defensive\"\n\ndef handle_ldap_filter_injection_7214_2(value_7214_2, scope_7214_2):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7214_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_7214_2)\n query = f\"(uid={escaped})\"\n return value_7214_2.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_5b42f04e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_7214_2)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-c53c7277f3e86d6f","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_3949_15 = \"defensive\"\n\ndef load_lxml_xpath_injection_3949_15(payload_3949_15, target_3949_15):\n if HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_3949_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{target_3949_15}']\"\n return payload_3949_15.xpath(xpath)\n","fixed_code":"HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_3949_15 = \"defensive\"\n\ndef load_lxml_xpath_injection_3949_15(payload_3949_15, target_3949_15):\n if HANDLER_KIND_LOAD_LXML_XPATH_INJECTION_3949_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_3949_15.xpath(\"//user[@name=$account]\", account=target_3949_15)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_c53c7277_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_xpath_injection_3949_15)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-2dc0bb30f58d1d52","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_1840_18 = \"defensive\"\n\ndef apply_unsafe_deserialization_1840_18(request_1840_18):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_1840_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(request_1840_18)\n","fixed_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_1840_18 = \"defensive\"\n\ndef apply_unsafe_deserialization_1840_18(request_1840_18):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_1840_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_1840_18.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_2dc0bb30_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_unsafe_deserialization_1840_18)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-38180f47796f2132","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7836_4 = \"defensive\"\n\ndef apply_httpx_client_ssrf_7836_4(payload_7836_4, context_7836_4, owner_7836_4):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7836_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_7836_4.get(context_7836_4, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7836_4 = \"defensive\"\n\ndef apply_httpx_client_ssrf_7836_4(payload_7836_4, context_7836_4, owner_7836_4):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7836_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_7836_4)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_7836_4):\n raise ValueError(\"destination is not allowed\")\n return payload_7836_4.get(context_7836_4, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_38180f47_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_7836_4)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-54ba11f0ee3b0ba5","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_6285_1 = \"defensive\"\n\ndef resolve_requests_tls_verification_6285_1(value_6285_1):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_6285_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_6285_1, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_6285_1 = \"defensive\"\n\ndef resolve_requests_tls_verification_6285_1(value_6285_1):\n if HANDLER_KIND_RESOLVE_REQUESTS_TLS_VERIFICATION_6285_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_6285_1, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_54ba11f0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_requests_tls_verification_6285_1)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-af9e040b93e1ddca","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_4980_9 = \"defensive\"\n\ndef resolve_unsafe_deserialization_4980_9(request_4980_9):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_4980_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(request_4980_9)\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_4980_9 = \"defensive\"\n\ndef resolve_unsafe_deserialization_4980_9(request_4980_9):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_4980_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_4980_9.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_af9e040b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_4980_9)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-d9bc8a942be75419","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2374_24 = \"defensive\"\n\ndef process_command_injection_2374_24(subject_2374_24, context_2374_24):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_2374_24} {context_2374_24}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2374_24 = \"defensive\"\n\ndef process_command_injection_2374_24(subject_2374_24, context_2374_24):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2374_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_2374_24, context_2374_24], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_d9bc8a94_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_2374_24)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-e4008e55b3df53a7","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8517_15 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8517_15(request_8517_15):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8517_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_8517_15, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8517_15 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8517_15(request_8517_15):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8517_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_8517_15)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_e4008e55_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_8517_15)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-afab8e6eaa06f3d7","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1977_11 = \"defensive\"\n\ndef process_lxml_xpath_injection_1977_11(request_1977_11, target_1977_11):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1977_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1977_11.xpath(\"//user[@name=$account]\", account=target_1977_11)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1977_11 = \"defensive\"\n\ndef process_lxml_xpath_injection_1977_11(request_1977_11, target_1977_11):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1977_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1977_11.xpath(\"//user[@name=$account]\", account=target_1977_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_afab8e6e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_1977_11)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-10ab0544bf9bae9b","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_7850_5 = \"defensive\"\n\ndef resolve_command_injection_7850_5(subject_7850_5, scope_7850_5):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_7850_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_7850_5, scope_7850_5], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_7850_5 = \"defensive\"\n\ndef resolve_command_injection_7850_5(subject_7850_5, scope_7850_5):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_7850_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_7850_5, scope_7850_5], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_10ab0544_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_7850_5)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-8fd125ac2170c40d","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8589_18 = \"defensive\"\n\ndef handle_django_safe_string_xss_8589_18(payload_8589_18):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8589_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_8589_18}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8589_18 = \"defensive\"\n\ndef handle_django_safe_string_xss_8589_18(payload_8589_18):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8589_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_8589_18)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_8fd125ac_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_8589_18)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a7a75aa6f17381e4","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_7644_3 = \"defensive\"\n\ndef handle_ssrf_7644_3(value_7644_3, context_7644_3):\n if HANDLER_KIND_HANDLE_SSRF_7644_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_7644_3, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_7644_3 = \"defensive\"\n\ndef handle_ssrf_7644_3(value_7644_3, context_7644_3):\n if HANDLER_KIND_HANDLE_SSRF_7644_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_7644_3)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_7644_3):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_7644_3, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_a7a75aa6_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_7644_3)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-2f7247c9997e67ca","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8347_16 = \"defensive\"\n\ndef resolve_csv_formula_injection_8347_16(request_8347_16):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8347_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in request_8347_16)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8347_16 = \"defensive\"\n\ndef resolve_csv_formula_injection_8347_16(request_8347_16):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8347_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_8347_16)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_2f7247c9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_8347_16)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-bc1f4a1b8d543d6f","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7099_11 = \"defensive\"\n\ndef handle_ldap_filter_injection_7099_11(request_7099_11, target_7099_11):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7099_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_7099_11)\n query = f\"(uid={escaped})\"\n return request_7099_11.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7099_11 = \"defensive\"\n\ndef handle_ldap_filter_injection_7099_11(request_7099_11, target_7099_11):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_7099_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_7099_11)\n query = f\"(uid={escaped})\"\n return request_7099_11.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_bc1f4a1b_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_7099_11)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-9bf995714befc8e7","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6130_5 = \"defensive\"\n\ndef load_resource_consumption_6130_5(request_6130_5, context_6130_5):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6130_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_6130_5), 1), 1_048_576)\n data = request_6130_5.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6130_5 = \"defensive\"\n\ndef load_resource_consumption_6130_5(request_6130_5, context_6130_5):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_6130_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_6130_5), 1), 1_048_576)\n data = request_6130_5.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_9bf99571_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_resource_consumption_6130_5)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-dba641adfe76a592","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_5528_14 = \"defensive\"\n\ndef handle_log_injection_5528_14(request_5528_14, policy_5528_14):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_5528_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_5528_14).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_5528_14.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_LOG_INJECTION_5528_14 = \"defensive\"\n\ndef handle_log_injection_5528_14(request_5528_14, policy_5528_14):\n if HANDLER_KIND_HANDLE_LOG_INJECTION_5528_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_5528_14).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_5528_14.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_dba641ad_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_log_injection_5528_14)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-a87c403a21a96b20","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_4505_29 = \"defensive\"\n\ndef load_fastapi_upload_validation_4505_29(payload_4505_29):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_4505_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_4505_29.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_4505_29.size is None or payload_4505_29.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_4505_29.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_4505_29 = \"defensive\"\n\ndef load_fastapi_upload_validation_4505_29(payload_4505_29):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_4505_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_4505_29.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_4505_29.size is None or payload_4505_29.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_4505_29.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_a87c403a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_upload_validation_4505_29)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-3e404180ad96d1e3","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2948_11 = \"defensive\"\n\ndef process_dynamic_code_injection_2948_11(request_2948_11):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2948_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_2948_11) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_2948_11)\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2948_11 = \"defensive\"\n\ndef process_dynamic_code_injection_2948_11(request_2948_11):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2948_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_2948_11) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_2948_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_3e404180_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_2948_11)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-393bcb6e32719e8b","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_3138_23 = \"defensive\"\n\ndef handle_requests_tls_verification_3138_23(request_3138_23):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_3138_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_3138_23, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_3138_23 = \"defensive\"\n\ndef handle_requests_tls_verification_3138_23(request_3138_23):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_3138_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_3138_23, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_393bcb6e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_3138_23)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-89d468dbcec29eb7","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3345_4 = \"defensive\"\n\ndef load_flask_csrf_validation_3345_4(request_3345_4, target_3345_4):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3345_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_3345_4.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3345_4 = \"defensive\"\n\ndef load_flask_csrf_validation_3345_4(request_3345_4, target_3345_4):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3345_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_3345_4.headers.get(\"X-CSRF-Token\", \"\")\n expected = target_3345_4.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_3345_4.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_89d468db_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_csrf_validation_3345_4)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-0738a1052507b099","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_SSRF_8153_6 = \"defensive\"\n\ndef load_ssrf_8153_6(value_8153_6, target_8153_6):\n if HANDLER_KIND_LOAD_SSRF_8153_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_8153_6, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_8153_6 = \"defensive\"\n\ndef load_ssrf_8153_6(value_8153_6, target_8153_6):\n if HANDLER_KIND_LOAD_SSRF_8153_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_8153_6)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_8153_6):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_8153_6, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_0738a105_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_8153_6)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-e1e55e0ec6421ede","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_7742_14 = \"defensive\"\n\ndef resolve_http_response_splitting_7742_14(payload_7742_14, context_7742_14):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_7742_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7742_14 or \"\\n\" in context_7742_14:\n raise ValueError(\"invalid header value\")\n payload_7742_14.headers[\"X-Next\"] = context_7742_14\n return payload_7742_14\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_7742_14 = \"defensive\"\n\ndef resolve_http_response_splitting_7742_14(payload_7742_14, context_7742_14):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_7742_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7742_14 or \"\\n\" in context_7742_14:\n raise ValueError(\"invalid header value\")\n payload_7742_14.headers[\"X-Next\"] = context_7742_14\n return payload_7742_14\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_e1e55e0e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_7742_14)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-d52254ef7ca4bb11","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8650_17 = \"defensive\"\n\ndef resolve_csv_formula_injection_8650_17(request_8650_17):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8650_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_8650_17)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8650_17 = \"defensive\"\n\ndef resolve_csv_formula_injection_8650_17(request_8650_17):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_8650_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in request_8650_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_d52254ef_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_8650_17)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-eef43e85bfdc0c4a","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9522_8 = \"defensive\"\n\ndef handle_lxml_external_entity_9522_8(value_9522_8):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9522_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_9522_8, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9522_8 = \"defensive\"\n\ndef handle_lxml_external_entity_9522_8(value_9522_8):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_9522_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_9522_8, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_eef43e85_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_9522_8)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-f0bf8768a30c84a9","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8577_8 = \"defensive\"\n\ndef handle_tarfile_path_traversal_8577_8(subject_8577_8, context_8577_8):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8577_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8577_8.extractall(context_8577_8, filter=\"data\")\n return context_8577_8\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8577_8 = \"defensive\"\n\ndef handle_tarfile_path_traversal_8577_8(subject_8577_8, context_8577_8):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8577_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8577_8.extractall(context_8577_8, filter=\"data\")\n return context_8577_8\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_f0bf8768_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_8577_8)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-7036cdd04b203dd5","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_9476_12 = \"defensive\"\n\ndef apply_flask_open_redirect_9476_12(payload_9476_12):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_9476_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(payload_9476_12)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_9476_12 = \"defensive\"\n\ndef apply_flask_open_redirect_9476_12(payload_9476_12):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_9476_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9476_12)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_9476_12)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_7036cdd0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_open_redirect_9476_12)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-0ed253948f23bfb2","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_2745_10 = \"defensive\"\n\ndef resolve_dynamic_code_injection_2745_10(subject_2745_10):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_2745_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_2745_10, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_2745_10 = \"defensive\"\n\ndef resolve_dynamic_code_injection_2745_10(subject_2745_10):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_2745_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_2745_10) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_2745_10)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_0ed25394_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_dynamic_code_injection_2745_10)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-80a051bfe7117b3f","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_7058_23 = \"defensive\"\n\ndef handle_zip_decompression_bomb_7058_23(payload_7058_23, target_7058_23):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_7058_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_7058_23.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_7058_23.extractall(target_7058_23)\n return target_7058_23\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_7058_23 = \"defensive\"\n\ndef handle_zip_decompression_bomb_7058_23(payload_7058_23, target_7058_23):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_7058_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_7058_23.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_7058_23.extractall(target_7058_23)\n return target_7058_23\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_80a051bf_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_7058_23)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-614a9b97f592dc40","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_4787_7 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_4787_7(payload_4787_7):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_4787_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_4787_7.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_4787_7 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_4787_7(payload_4787_7):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_4787_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_4787_7.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_4787_7.size is None or payload_4787_7.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_4787_7.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_614a9b97_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_4787_7)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-a8dd24e5918a7e51","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_7012_6 = \"defensive\"\n\ndef apply_plaintext_password_storage_7012_6(value_7012_6, policy_7012_6, options_7012_6):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_7012_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_7012_6).write_text(policy_7012_6, encoding=\"utf-8\")\n return Path(value_7012_6)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_7012_6 = \"defensive\"\n\ndef apply_plaintext_password_storage_7012_6(value_7012_6, policy_7012_6, options_7012_6):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_7012_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_7012_6) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_7012_6.encode(\"utf-8\"), options_7012_6, 240_000).hex()\n Path(value_7012_6).write_text(verifier, encoding=\"ascii\")\n return Path(value_7012_6)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_a8dd24e5_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_plaintext_password_storage_7012_6)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-1826efd689f1379d","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3888_10 = \"defensive\"\n\ndef apply_http_response_splitting_3888_10(subject_3888_10, policy_3888_10):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3888_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_3888_10.headers[\"X-Next\"] = policy_3888_10\n return subject_3888_10\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3888_10 = \"defensive\"\n\ndef apply_http_response_splitting_3888_10(subject_3888_10, policy_3888_10):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_3888_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_3888_10 or \"\\n\" in policy_3888_10:\n raise ValueError(\"invalid header value\")\n subject_3888_10.headers[\"X-Next\"] = policy_3888_10\n return subject_3888_10\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_1826efd6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_3888_10)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-eee9c1fdf98ce750","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_1030_11 = \"defensive\"\n\ndef handle_plaintext_password_storage_1030_11(payload_1030_11, scope_1030_11, limit_1030_11):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_1030_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_1030_11) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_1030_11.encode(\"utf-8\"), limit_1030_11, 240_000).hex()\n Path(payload_1030_11).write_text(verifier, encoding=\"ascii\")\n return Path(payload_1030_11)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_1030_11 = \"defensive\"\n\ndef handle_plaintext_password_storage_1030_11(payload_1030_11, scope_1030_11, limit_1030_11):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_1030_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_1030_11) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_1030_11.encode(\"utf-8\"), limit_1030_11, 240_000).hex()\n Path(payload_1030_11).write_text(verifier, encoding=\"ascii\")\n return Path(payload_1030_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_eee9c1fd_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_1030_11)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-c33e5a9ff2943b8f","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8820_14 = \"defensive\"\n\ndef handle_unsafe_deserialization_8820_14(value_8820_14):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8820_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_8820_14.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8820_14 = \"defensive\"\n\ndef handle_unsafe_deserialization_8820_14(value_8820_14):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_8820_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_8820_14.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_c33e5a9f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_8820_14)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-78fca866c480ad75","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8562_3 = \"defensive\"\n\ndef load_sql_injection_8562_3(value_8562_3, target_8562_3):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8562_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {target_8562_3}\"\n return value_8562_3.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8562_3 = \"defensive\"\n\ndef load_sql_injection_8562_3(value_8562_3, target_8562_3):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8562_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_8562_3.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (target_8562_3,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_78fca866_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sql_injection_8562_3)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-7904993d8f32327c","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1181_6 = \"defensive\"\n\ndef handle_lxml_xpath_injection_1181_6(request_1181_6, scope_1181_6):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1181_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_1181_6}']\"\n return request_1181_6.xpath(xpath)\n","fixed_code":"HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1181_6 = \"defensive\"\n\ndef handle_lxml_xpath_injection_1181_6(request_1181_6, scope_1181_6):\n if HANDLER_KIND_HANDLE_LXML_XPATH_INJECTION_1181_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1181_6.xpath(\"//user[@name=$account]\", account=scope_1181_6)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_7904993d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_xpath_injection_1181_6)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-1a57f7a699bb727a","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5754_6 = \"defensive\"\n\ndef load_sensitive_data_exposure_5754_6(payload_5754_6, target_5754_6, allowed_5754_6):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5754_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5754_6.info(\"login user=%s password=%s\", target_5754_6, allowed_5754_6)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5754_6 = \"defensive\"\n\ndef load_sensitive_data_exposure_5754_6(payload_5754_6, target_5754_6, allowed_5754_6):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5754_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5754_6.info(\"login user=%s\", target_5754_6)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_1a57f7a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_5754_6)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-3fbbaf1035726a05","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_5329_14 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_5329_14(request_5329_14, target_5329_14):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_5329_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_5329_14)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_5329_14.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_5329_14\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_5329_14 = \"defensive\"\n\ndef resolve_starlette_permissive_cors_5329_14(request_5329_14, target_5329_14):\n if HANDLER_KIND_RESOLVE_STARLETTE_PERMISSIVE_CORS_5329_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_5329_14)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_5329_14.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_5329_14\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_3fbbaf10_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_starlette_permissive_cors_5329_14)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-e83f23c218e7aecf","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9079_29 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9079_29(request_9079_29):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9079_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9079_29)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9079_29 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9079_29(request_9079_29):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9079_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9079_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_e83f23c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_9079_29)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-ff1482f983c519e6","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_4443_20 = \"defensive\"\n\ndef apply_lxml_external_entity_4443_20(value_4443_20):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_4443_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_4443_20, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_4443_20 = \"defensive\"\n\ndef apply_lxml_external_entity_4443_20(value_4443_20):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_4443_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_4443_20, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_ff1482f9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_external_entity_4443_20)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-eacbcc73fafd35fc","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_9745_17 = \"defensive\"\n\ndef handle_ssrf_9745_17(payload_9745_17, context_9745_17):\n if HANDLER_KIND_HANDLE_SSRF_9745_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9745_17)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_9745_17):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_9745_17, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_9745_17 = \"defensive\"\n\ndef handle_ssrf_9745_17(payload_9745_17, context_9745_17):\n if HANDLER_KIND_HANDLE_SSRF_9745_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_9745_17)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_9745_17):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_9745_17, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_eacbcc73_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_9745_17)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-6850a0d04be9f990","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2762_22 = \"defensive\"\n\ndef handle_lxml_external_entity_2762_22(subject_2762_22):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2762_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(subject_2762_22)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2762_22 = \"defensive\"\n\ndef handle_lxml_external_entity_2762_22(subject_2762_22):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2762_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_2762_22, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_6850a0d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_2762_22)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-454f2aed91c3f2cf","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5636_28 = \"defensive\"\n\ndef process_django_error_details_5636_28(value_5636_28, target_5636_28):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5636_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_5636_28()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5636_28 = \"defensive\"\n\ndef process_django_error_details_5636_28(value_5636_28, target_5636_28):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_5636_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_5636_28()\n except Exception:\n value_5636_28.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_454f2aed_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_error_details_5636_28)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-9203288f0620d9f9","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_4398_3 = \"defensive\"\n\ndef load_command_injection_4398_3(request_4398_3, target_4398_3):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_4398_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {request_4398_3} {target_4398_3}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_4398_3 = \"defensive\"\n\ndef load_command_injection_4398_3(request_4398_3, target_4398_3):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_4398_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_4398_3, target_4398_3], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_9203288f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_command_injection_4398_3)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-02c34935c965b5dc","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4131_20 = \"defensive\"\n\ndef apply_requests_tls_verification_4131_20(value_4131_20):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4131_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_4131_20, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4131_20 = \"defensive\"\n\ndef apply_requests_tls_verification_4131_20(value_4131_20):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4131_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_4131_20, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_02c34935_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_4131_20)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-8f40917eb1ed13f7","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_4830_21 = \"defensive\"\n\ndef load_missing_authorization_4830_21(subject_4830_21, context_4830_21):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_4830_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_4830_21.delete()\n return True\n","fixed_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_4830_21 = \"defensive\"\n\ndef load_missing_authorization_4830_21(subject_4830_21, context_4830_21):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_4830_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_4830_21.id != context_4830_21.owner_id:\n raise PermissionError(\"record ownership required\")\n context_4830_21.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_8f40917e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_missing_authorization_4830_21)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-b1c6c15ea9ad2403","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_7013_13 = \"defensive\"\n\ndef load_sensitive_data_exposure_7013_13(payload_7013_13, scope_7013_13, options_7013_13):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_7013_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7013_13.info(\"login user=%s password=%s\", scope_7013_13, options_7013_13)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_7013_13 = \"defensive\"\n\ndef load_sensitive_data_exposure_7013_13(payload_7013_13, scope_7013_13, options_7013_13):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_7013_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7013_13.info(\"login user=%s\", scope_7013_13)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_b1c6c15e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_7013_13)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-afdae3ac62e4829a","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_5609_5 = \"defensive\"\n\ndef handle_unsafe_deserialization_5609_5(payload_5609_5):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_5609_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_5609_5.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_5609_5 = \"defensive\"\n\ndef handle_unsafe_deserialization_5609_5(payload_5609_5):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_5609_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_5609_5.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_afdae3ac_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_5609_5)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-ef54c963d1959524","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_1634_0 = \"defensive\"\n\ndef process_lxml_external_entity_1634_0(payload_1634_0):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_1634_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_1634_0)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_1634_0 = \"defensive\"\n\ndef process_lxml_external_entity_1634_0(payload_1634_0):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_1634_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_1634_0, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_ef54c963_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_external_entity_1634_0)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-4520d61c8cf6b063","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_4439_17 = \"defensive\"\n\ndef handle_lxml_external_entity_4439_17(request_4439_17):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_4439_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_4439_17, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_4439_17 = \"defensive\"\n\ndef handle_lxml_external_entity_4439_17(request_4439_17):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_4439_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_4439_17, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_4520d61c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_4439_17)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-4cd2ed034feae874","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_7331_24 = \"defensive\"\n\ndef process_unsafe_deserialization_7331_24(payload_7331_24):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_7331_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(payload_7331_24)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_7331_24 = \"defensive\"\n\ndef process_unsafe_deserialization_7331_24(payload_7331_24):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_7331_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_7331_24.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_4cd2ed03_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_7331_24)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-5fd3cb35ac16c7e5","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3453_27 = \"defensive\"\n\ndef load_flask_csrf_validation_3453_27(subject_3453_27, policy_3453_27):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3453_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3453_27.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3453_27 = \"defensive\"\n\ndef load_flask_csrf_validation_3453_27(subject_3453_27, policy_3453_27):\n if HANDLER_KIND_LOAD_FLASK_CSRF_VALIDATION_3453_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_3453_27.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_3453_27.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_3453_27.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_5fd3cb35_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_csrf_validation_3453_27)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-8d8378516b43abcf","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_CSV_FORMULA_INJECTION_7453_23 = \"defensive\"\n\ndef apply_csv_formula_injection_7453_23(payload_7453_23):\n if HANDLER_KIND_APPLY_CSV_FORMULA_INJECTION_7453_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7453_23)\n","fixed_code":"HANDLER_KIND_APPLY_CSV_FORMULA_INJECTION_7453_23 = \"defensive\"\n\ndef apply_csv_formula_injection_7453_23(payload_7453_23):\n if HANDLER_KIND_APPLY_CSV_FORMULA_INJECTION_7453_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7453_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_8d837851_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_csv_formula_injection_7453_23)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-90f5bbaad595fdd9","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5726_23 = \"defensive\"\n\ndef process_dynamic_code_injection_5726_23(subject_5726_23):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5726_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5726_23) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_5726_23)\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5726_23 = \"defensive\"\n\ndef process_dynamic_code_injection_5726_23(subject_5726_23):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_5726_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_5726_23) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_5726_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_90f5bbaa_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_5726_23)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-f2454c10787eb77a","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_5691_2 = \"defensive\"\n\ndef apply_ssrf_5691_2(payload_5691_2, target_5691_2):\n if HANDLER_KIND_APPLY_SSRF_5691_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_5691_2)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_5691_2):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_5691_2, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_5691_2 = \"defensive\"\n\ndef apply_ssrf_5691_2(payload_5691_2, target_5691_2):\n if HANDLER_KIND_APPLY_SSRF_5691_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_5691_2)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_5691_2):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_5691_2, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_f2454c10_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_5691_2)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-bf5e48da09c508fc","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2282_26 = \"defensive\"\n\ndef handle_regex_dos_2282_26(payload_2282_26, context_2282_26):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2282_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_2282_26) > 256 or len(context_2282_26) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_2282_26), context_2282_26) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2282_26 = \"defensive\"\n\ndef handle_regex_dos_2282_26(payload_2282_26, context_2282_26):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2282_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_2282_26) > 256 or len(context_2282_26) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_2282_26), context_2282_26) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_bf5e48da_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_2282_26)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-34d10243b00b79a2","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_8767_10 = \"defensive\"\n\ndef process_flask_session_fixation_8767_10(payload_8767_10, target_8767_10):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_8767_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8767_10[\"user_id\"] = target_8767_10.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_8767_10 = \"defensive\"\n\ndef process_flask_session_fixation_8767_10(payload_8767_10, target_8767_10):\n if HANDLER_KIND_PROCESS_FLASK_SESSION_FIXATION_8767_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8767_10.clear()\n payload_8767_10[\"user_id\"] = target_8767_10.id\n payload_8767_10[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_34d10243_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_session_fixation_8767_10)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-6f280a3eb1027918","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_4327_20 = \"defensive\"\n\ndef process_sql_injection_4327_20(subject_4327_20, policy_4327_20):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_4327_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_4327_20.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_4327_20,)).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_4327_20 = \"defensive\"\n\ndef process_sql_injection_4327_20(subject_4327_20, policy_4327_20):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_4327_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_4327_20.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_4327_20,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_6f280a3e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_4327_20)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-45af71fc6c586660","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_8782_7 = \"defensive\"\n\ndef apply_mass_assignment_8782_7(subject_8782_7, scope_8782_7):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_8782_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in scope_8782_7.items():\n setattr(subject_8782_7, key, value)\n return subject_8782_7\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_8782_7 = \"defensive\"\n\ndef apply_mass_assignment_8782_7(subject_8782_7, scope_8782_7):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_8782_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_8782_7.items() if key in allowed_fields}\n subject_8782_7.update(safe)\n return subject_8782_7\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_45af71fc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_8782_7)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-ffa8564dac48527c","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_7914_6 = \"defensive\"\n\ndef resolve_unsafe_deserialization_7914_6(payload_7914_6):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_7914_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(payload_7914_6)\n","fixed_code":"import json\n\nHANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_7914_6 = \"defensive\"\n\ndef resolve_unsafe_deserialization_7914_6(payload_7914_6):\n if HANDLER_KIND_RESOLVE_UNSAFE_DESERIALIZATION_7914_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_7914_6.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_ffa8564d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_unsafe_deserialization_7914_6)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-f48e9ac25ee1d58c","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_5733_18 = \"defensive\"\n\ndef process_insecure_file_permissions_5733_18(value_5733_18, policy_5733_18):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_5733_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_5733_18).write_text(policy_5733_18, encoding=\"utf-8\")\n os.chmod(value_5733_18, 0o777)\n return Path(value_5733_18)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_5733_18 = \"defensive\"\n\ndef process_insecure_file_permissions_5733_18(value_5733_18, policy_5733_18):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_5733_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_5733_18).write_text(policy_5733_18, encoding=\"utf-8\")\n os.chmod(value_5733_18, 0o600)\n return Path(value_5733_18)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_f48e9ac2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_5733_18)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-56b0ba63ab43d198","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_9862_20 = \"defensive\"\n\ndef handle_resource_consumption_9862_20(value_9862_20, target_9862_20):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_9862_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_9862_20), 1), 1_048_576)\n data = value_9862_20.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_9862_20 = \"defensive\"\n\ndef handle_resource_consumption_9862_20(value_9862_20, target_9862_20):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_9862_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_9862_20), 1), 1_048_576)\n data = value_9862_20.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_56b0ba63_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_9862_20)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-10b4178e39499677","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6383_20 = \"defensive\"\n\ndef apply_missing_authorization_6383_20(subject_6383_20, policy_6383_20):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6383_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_6383_20.id != policy_6383_20.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_6383_20.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6383_20 = \"defensive\"\n\ndef apply_missing_authorization_6383_20(subject_6383_20, policy_6383_20):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_6383_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_6383_20.id != policy_6383_20.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_6383_20.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_10b4178e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_6383_20)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-1e87dfd0b17735f4","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1046_0 = \"defensive\"\n\ndef load_httpx_client_ssrf_1046_0(subject_1046_0, policy_1046_0, options_1046_0):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1046_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_1046_0.get(policy_1046_0, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1046_0 = \"defensive\"\n\ndef load_httpx_client_ssrf_1046_0(subject_1046_0, policy_1046_0, options_1046_0):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_1046_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_1046_0)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_1046_0):\n raise ValueError(\"destination is not allowed\")\n return subject_1046_0.get(policy_1046_0, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_1e87dfd0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_1046_0)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-9f1073f99b4585cb","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_8842_2 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_8842_2(payload_8842_2, target_8842_2):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_8842_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8842_2.extractall(target_8842_2, filter=\"data\")\n return target_8842_2\n","fixed_code":"HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_8842_2 = \"defensive\"\n\ndef resolve_tarfile_path_traversal_8842_2(payload_8842_2, target_8842_2):\n if HANDLER_KIND_RESOLVE_TARFILE_PATH_TRAVERSAL_8842_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8842_2.extractall(target_8842_2, filter=\"data\")\n return target_8842_2\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_9f1073f9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_tarfile_path_traversal_8842_2)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-378cb857cdf2a4ec","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_6960_21 = \"defensive\"\n\ndef load_cleartext_http_transport_6960_21(value_6960_21):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_6960_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=value_6960_21, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_6960_21 = \"defensive\"\n\ndef load_cleartext_http_transport_6960_21(value_6960_21):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_6960_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=value_6960_21, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_378cb857_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_6960_21)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-88c00f0b44a6717c","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6038_6 = \"defensive\"\n\ndef apply_resource_consumption_6038_6(value_6038_6, context_6038_6):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6038_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_6038_6.read(int(context_6038_6))\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6038_6 = \"defensive\"\n\ndef apply_resource_consumption_6038_6(value_6038_6, context_6038_6):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_6038_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_6038_6), 1), 1_048_576)\n data = value_6038_6.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_88c00f0b_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_6038_6)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-11cca3cca416394a","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_7235_9 = \"defensive\"\n\ndef load_ldap_filter_injection_7235_9(subject_7235_9, context_7235_9):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_7235_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_7235_9})\"\n return subject_7235_9.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_7235_9 = \"defensive\"\n\ndef load_ldap_filter_injection_7235_9(subject_7235_9, context_7235_9):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_7235_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_7235_9)\n query = f\"(uid={escaped})\"\n return subject_7235_9.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_11cca3cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ldap_filter_injection_7235_9)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-91b7033cb064aaf0","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_5310_13 = \"defensive\"\n\ndef process_fastapi_upload_validation_5310_13(value_5310_13):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_5310_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_5310_13.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_5310_13 = \"defensive\"\n\ndef process_fastapi_upload_validation_5310_13(value_5310_13):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_5310_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_5310_13.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_5310_13.size is None or value_5310_13.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_5310_13.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_91b7033c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_5310_13)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-983187b54671814e","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9936_17 = \"defensive\"\n\ndef resolve_cleartext_http_transport_9936_17(subject_9936_17):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9936_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_9936_17, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9936_17 = \"defensive\"\n\ndef resolve_cleartext_http_transport_9936_17(subject_9936_17):\n if HANDLER_KIND_RESOLVE_CLEARTEXT_HTTP_TRANSPORT_9936_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_9936_17, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_983187b5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_cleartext_http_transport_9936_17)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-4479f2163ad3ef2a","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4052_22 = \"defensive\"\n\ndef process_zip_decompression_bomb_4052_22(subject_4052_22, target_4052_22):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4052_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4052_22.extractall(target_4052_22)\n return target_4052_22\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4052_22 = \"defensive\"\n\ndef process_zip_decompression_bomb_4052_22(subject_4052_22, target_4052_22):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4052_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_4052_22.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_4052_22.extractall(target_4052_22)\n return target_4052_22\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_4479f216_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_4052_22)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-6a5268cf79c7f58d","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_2176_23 = \"defensive\"\n\ndef process_resource_consumption_2176_23(subject_2176_23, target_2176_23):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_2176_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_2176_23), 1), 1_048_576)\n data = subject_2176_23.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_2176_23 = \"defensive\"\n\ndef process_resource_consumption_2176_23(subject_2176_23, target_2176_23):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_2176_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_2176_23), 1), 1_048_576)\n data = subject_2176_23.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_6a5268cf_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_resource_consumption_2176_23)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-89a3b93a51848570","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_9118_9 = \"defensive\"\n\ndef resolve_flask_csrf_validation_9118_9(subject_9118_9, scope_9118_9):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_9118_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9118_9.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_9118_9 = \"defensive\"\n\ndef resolve_flask_csrf_validation_9118_9(subject_9118_9, scope_9118_9):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_9118_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_9118_9.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_9118_9.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_9118_9.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_89a3b93a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_csrf_validation_9118_9)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-2ba03fdead5d74d7","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_7774_13 = \"defensive\"\n\ndef apply_starlette_permissive_cors_7774_13(payload_7774_13, context_7774_13):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_7774_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7774_13.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return payload_7774_13\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_7774_13 = \"defensive\"\n\ndef apply_starlette_permissive_cors_7774_13(payload_7774_13, context_7774_13):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_7774_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_7774_13)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_7774_13.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_7774_13\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_2ba03fde_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_7774_13)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-84842ab6a2f0a7ae","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_5720_5 = \"defensive\"\n\ndef load_path_traversal_5720_5(value_5720_5, policy_5720_5):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_5720_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_5720_5).resolve()\n candidate = (root / policy_5720_5).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PATH_TRAVERSAL_5720_5 = \"defensive\"\n\ndef load_path_traversal_5720_5(value_5720_5, policy_5720_5):\n if HANDLER_KIND_LOAD_PATH_TRAVERSAL_5720_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_5720_5).resolve()\n candidate = (root / policy_5720_5).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_84842ab6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_path_traversal_5720_5)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-9102a3a09053f3a9","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8152_16 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8152_16(subject_8152_16, scope_8152_16, owner_8152_16):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8152_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8152_16.info(\"login user=%s password=%s\", scope_8152_16, owner_8152_16)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8152_16 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8152_16(subject_8152_16, scope_8152_16, owner_8152_16):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8152_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_8152_16.info(\"login user=%s\", scope_8152_16)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_9102a3a0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sensitive_data_exposure_8152_16)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-2cc2a790a7231d25","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_9645_26 = \"defensive\"\n\ndef process_flask_csrf_validation_9645_26(subject_9645_26, context_9645_26):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_9645_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_9645_26.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_9645_26.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_9645_26.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_9645_26 = \"defensive\"\n\ndef process_flask_csrf_validation_9645_26(subject_9645_26, context_9645_26):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_9645_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = subject_9645_26.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_9645_26.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return subject_9645_26.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_2cc2a790_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_9645_26)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-97a5c5b2ed227009","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7932_17 = \"defensive\"\n\ndef apply_httpx_client_ssrf_7932_17(request_7932_17, context_7932_17, options_7932_17):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7932_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_7932_17)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_7932_17):\n raise ValueError(\"destination is not allowed\")\n return request_7932_17.get(context_7932_17, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7932_17 = \"defensive\"\n\ndef apply_httpx_client_ssrf_7932_17(request_7932_17, context_7932_17, options_7932_17):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_7932_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_7932_17)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_7932_17):\n raise ValueError(\"destination is not allowed\")\n return request_7932_17.get(context_7932_17, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_97a5c5b2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_7932_17)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-26d52f8eff74a49c","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_6507_1 = \"defensive\"\n\ndef handle_starlette_permissive_cors_6507_1(request_6507_1, context_6507_1):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_6507_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6507_1.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return request_6507_1\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_6507_1 = \"defensive\"\n\ndef handle_starlette_permissive_cors_6507_1(request_6507_1, context_6507_1):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_6507_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_6507_1)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_6507_1.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_6507_1\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_26d52f8e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_starlette_permissive_cors_6507_1)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-98e628340afc7c87","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_3917_17 = \"defensive\"\n\ndef load_insecure_random_token_3917_17(request_3917_17):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_3917_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_3917_17)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_3917_17 = \"defensive\"\n\ndef load_insecure_random_token_3917_17(request_3917_17):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_3917_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_3917_17)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_98e62834_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_random_token_3917_17)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a67515ab8dc6958a","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2521_3 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_2521_3(request_2521_3, policy_2521_3):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2521_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {policy_2521_3}\")\n return request_2521_3.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2521_3 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_2521_3(request_2521_3, policy_2521_3):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2521_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_2521_3.execute(statement, {\"account_id\": policy_2521_3}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_a67515ab_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_2521_3)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-f6c390100534d7d9","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7376_2 = \"defensive\"\n\ndef load_http_response_splitting_7376_2(subject_7376_2, context_7376_2):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7376_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7376_2 or \"\\n\" in context_7376_2:\n raise ValueError(\"invalid header value\")\n subject_7376_2.headers[\"X-Next\"] = context_7376_2\n return subject_7376_2\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7376_2 = \"defensive\"\n\ndef load_http_response_splitting_7376_2(subject_7376_2, context_7376_2):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_7376_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7376_2 or \"\\n\" in context_7376_2:\n raise ValueError(\"invalid header value\")\n subject_7376_2.headers[\"X-Next\"] = context_7376_2\n return subject_7376_2\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_f6c39010_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_7376_2)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-02de6b2448f2d21a","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_7919_19 = \"defensive\"\n\ndef handle_resource_consumption_7919_19(subject_7919_19, target_7919_19):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_7919_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7919_19.read(int(target_7919_19))\n","fixed_code":"HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_7919_19 = \"defensive\"\n\ndef handle_resource_consumption_7919_19(subject_7919_19, target_7919_19):\n if HANDLER_KIND_HANDLE_RESOURCE_CONSUMPTION_7919_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_7919_19), 1), 1_048_576)\n data = subject_7919_19.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_02de6b24_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_resource_consumption_7919_19)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-f1706844f26ebedd","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7563_1 = \"defensive\"\n\ndef apply_cleartext_http_transport_7563_1(payload_7563_1):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7563_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_7563_1, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7563_1 = \"defensive\"\n\ndef apply_cleartext_http_transport_7563_1(payload_7563_1):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_7563_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_7563_1, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_f1706844_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_7563_1)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-9121fad515cce48a","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3139_3 = \"defensive\"\n\ndef apply_httpx_client_ssrf_3139_3(subject_3139_3, target_3139_3, allowed_3139_3):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3139_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3139_3.get(target_3139_3, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3139_3 = \"defensive\"\n\ndef apply_httpx_client_ssrf_3139_3(subject_3139_3, target_3139_3, allowed_3139_3):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3139_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_3139_3)\n if parsed.scheme != \"https\" or parsed.hostname not in set(allowed_3139_3):\n raise ValueError(\"destination is not allowed\")\n return subject_3139_3.get(target_3139_3, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_9121fad5_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_3139_3)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-d498eda09be6d0b0","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_3220_27 = \"defensive\"\n\ndef handle_lxml_external_entity_3220_27(payload_3220_27):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_3220_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_3220_27)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_3220_27 = \"defensive\"\n\ndef handle_lxml_external_entity_3220_27(payload_3220_27):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_3220_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_3220_27, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_d498eda0_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_3220_27)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-d975f7d3791fabbf","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_1581_12 = \"defensive\"\n\ndef load_cleartext_http_transport_1581_12(payload_1581_12):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_1581_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_1581_12, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_1581_12 = \"defensive\"\n\ndef load_cleartext_http_transport_1581_12(payload_1581_12):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_1581_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_1581_12, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_d975f7d3_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_1581_12)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-9ba72824b9a8be18","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_1692_15 = \"defensive\"\n\ndef handle_command_injection_1692_15(subject_1692_15, scope_1692_15):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_1692_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {subject_1692_15} {scope_1692_15}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_1692_15 = \"defensive\"\n\ndef handle_command_injection_1692_15(subject_1692_15, scope_1692_15):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_1692_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", subject_1692_15, scope_1692_15], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_9ba72824_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_1692_15)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-73eea7a50b774a68","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2017_0 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_2017_0(value_2017_0):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2017_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_2017_0.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2017_0 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_2017_0(value_2017_0):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_2017_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_2017_0.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_2017_0.size is None or value_2017_0.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_2017_0.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_73eea7a5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_2017_0)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-32f551e54861bd18","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1364_3 = \"defensive\"\n\ndef process_log_injection_1364_3(request_1364_3, policy_1364_3):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1364_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1364_3.warning(\"audit=%s\", policy_1364_3)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1364_3 = \"defensive\"\n\ndef process_log_injection_1364_3(request_1364_3, policy_1364_3):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1364_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_1364_3).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_1364_3.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_32f551e5_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_1364_3)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-03fff5294b60c44e","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_8812_24 = \"defensive\"\n\ndef resolve_flask_jinja_xss_8812_24(value_8812_24):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_8812_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_8812_24)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_8812_24 = \"defensive\"\n\ndef resolve_flask_jinja_xss_8812_24(value_8812_24):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_8812_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_8812_24)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_03fff529_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_8812_24)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-691d8d659d5f5e5c","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_1458_9 = \"defensive\"\n\ndef process_cleartext_http_transport_1458_9(payload_1458_9):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_1458_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_1458_9, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_1458_9 = \"defensive\"\n\ndef process_cleartext_http_transport_1458_9(payload_1458_9):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_1458_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_1458_9, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_691d8d65_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_cleartext_http_transport_1458_9)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-8295d0135a8472c8","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_2366_6 = \"defensive\"\n\ndef handle_insecure_temp_file_2366_6(subject_2366_6, target_2366_6):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_2366_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{subject_2366_6}.txt\")\n path.write_text(target_2366_6, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_2366_6 = \"defensive\"\n\ndef handle_insecure_temp_file_2366_6(subject_2366_6, target_2366_6):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_2366_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(target_2366_6)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_8295d013_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_temp_file_2366_6)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-6e076dfc021aacbf","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3360_22 = \"defensive\"\n\ndef process_mass_assignment_3360_22(request_3360_22, policy_3360_22):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3360_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_3360_22.items():\n setattr(request_3360_22, key, value)\n return request_3360_22\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3360_22 = \"defensive\"\n\ndef process_mass_assignment_3360_22(request_3360_22, policy_3360_22):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_3360_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_3360_22.items() if key in allowed_fields}\n request_3360_22.update(safe)\n return request_3360_22\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_6e076dfc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_3360_22)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-a42bbbbca0a1427c","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_1805_10 = \"defensive\"\n\ndef apply_lxml_xpath_injection_1805_10(value_1805_10, scope_1805_10):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_1805_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_1805_10}']\"\n return value_1805_10.xpath(xpath)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_1805_10 = \"defensive\"\n\ndef apply_lxml_xpath_injection_1805_10(value_1805_10, scope_1805_10):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_1805_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_1805_10.xpath(\"//user[@name=$account]\", account=scope_1805_10)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_a42bbbbc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_1805_10)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-c899e6003d73f540","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2594_1 = \"defensive\"\n\ndef handle_regex_dos_2594_1(request_2594_1, policy_2594_1):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2594_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(request_2594_1, policy_2594_1) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2594_1 = \"defensive\"\n\ndef handle_regex_dos_2594_1(request_2594_1, policy_2594_1):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2594_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_2594_1) > 256 or len(policy_2594_1) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(request_2594_1), policy_2594_1) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_c899e600_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_2594_1)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-fe1975a312d97a9d","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2030_12 = \"defensive\"\n\ndef handle_regex_dos_2030_12(value_2030_12, target_2030_12):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2030_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(value_2030_12, target_2030_12) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_2030_12 = \"defensive\"\n\ndef handle_regex_dos_2030_12(value_2030_12, target_2030_12):\n if HANDLER_KIND_HANDLE_REGEX_DOS_2030_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_2030_12) > 256 or len(target_2030_12) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_2030_12), target_2030_12) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_fe1975a3_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_2030_12)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-aab7ee312bf8f7d2","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5273_19 = \"defensive\"\n\ndef handle_dynamic_code_injection_5273_19(value_5273_19):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5273_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(value_5273_19, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5273_19 = \"defensive\"\n\ndef handle_dynamic_code_injection_5273_19(value_5273_19):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_5273_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_5273_19) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(value_5273_19)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_aab7ee31_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_5273_19)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-b1e0343a79c8f14f","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9019_1 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9019_1(subject_9019_1):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9019_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(subject_9019_1, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9019_1 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9019_1(subject_9019_1):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9019_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_9019_1)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_b1e0343a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_9019_1)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-31f92d74360952dd","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3459_5 = \"defensive\"\n\ndef load_zip_decompression_bomb_3459_5(value_3459_5, context_3459_5):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3459_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_3459_5.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_3459_5.extractall(context_3459_5)\n return context_3459_5\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3459_5 = \"defensive\"\n\ndef load_zip_decompression_bomb_3459_5(value_3459_5, context_3459_5):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_3459_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_3459_5.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_3459_5.extractall(context_3459_5)\n return context_3459_5\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_31f92d74_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_3459_5)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-2776fb8de63b2aef","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6583_9 = \"defensive\"\n\ndef handle_insecure_random_token_6583_9(request_6583_9):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6583_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_6583_9)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6583_9 = \"defensive\"\n\ndef handle_insecure_random_token_6583_9(request_6583_9):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6583_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_6583_9)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_2776fb8d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_random_token_6583_9)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-0beaf084df5b2622","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2716_3 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_2716_3(request_2716_3):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2716_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_2716_3, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2716_3 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_2716_3(request_2716_3):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_2716_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_2716_3)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_0beaf084_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_2716_3)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-3d8abd3c3c881942","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_4975_14 = \"defensive\"\n\ndef process_resource_consumption_4975_14(subject_4975_14, policy_4975_14):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_4975_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4975_14), 1), 1_048_576)\n data = subject_4975_14.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_4975_14 = \"defensive\"\n\ndef process_resource_consumption_4975_14(subject_4975_14, policy_4975_14):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_4975_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4975_14), 1), 1_048_576)\n data = subject_4975_14.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_3d8abd3c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_resource_consumption_4975_14)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-b27ebf61bd961684","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7041_0 = \"defensive\"\n\ndef process_flask_csrf_validation_7041_0(payload_7041_0, scope_7041_0):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7041_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_7041_0.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7041_0 = \"defensive\"\n\ndef process_flask_csrf_validation_7041_0(payload_7041_0, scope_7041_0):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_7041_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_7041_0.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_7041_0.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_7041_0.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_b27ebf61_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_7041_0)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-9bad3bf05fedf5fd","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_2543_16 = \"defensive\"\n\ndef process_django_safe_string_xss_2543_16(payload_2543_16):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_2543_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_2543_16}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_2543_16 = \"defensive\"\n\ndef process_django_safe_string_xss_2543_16(payload_2543_16):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_2543_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_2543_16)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_9bad3bf0_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_safe_string_xss_2543_16)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-d34426a92a334587","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_2344_10 = \"defensive\"\n\ndef process_sql_injection_2344_10(request_2344_10, target_2344_10):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_2344_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {target_2344_10}\"\n return request_2344_10.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_2344_10 = \"defensive\"\n\ndef process_sql_injection_2344_10(request_2344_10, target_2344_10):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_2344_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2344_10.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (target_2344_10,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_d34426a9_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_2344_10)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-07fd1662570e7702","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_8247_17 = \"defensive\"\n\ndef process_zip_decompression_bomb_8247_17(request_8247_17, policy_8247_17):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_8247_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_8247_17.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_8247_17.extractall(policy_8247_17)\n return policy_8247_17\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_8247_17 = \"defensive\"\n\ndef process_zip_decompression_bomb_8247_17(request_8247_17, policy_8247_17):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_8247_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_8247_17.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_8247_17.extractall(policy_8247_17)\n return policy_8247_17\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_07fd1662_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_8247_17)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-64288bd8cae68c75","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6637_25 = \"defensive\"\n\ndef apply_requests_tls_verification_6637_25(payload_6637_25):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6637_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6637_25, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6637_25 = \"defensive\"\n\ndef apply_requests_tls_verification_6637_25(payload_6637_25):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6637_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6637_25, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_64288bd8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_6637_25)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-ee81ec5aadd0b648","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7549_28 = \"defensive\"\n\ndef handle_weak_cryptography_7549_28(payload_7549_28, policy_7549_28):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7549_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_7549_28.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7549_28 = \"defensive\"\n\ndef handle_weak_cryptography_7549_28(payload_7549_28, policy_7549_28):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7549_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_7549_28.encode(\"utf-8\"), policy_7549_28, 230000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_ee81ec5a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_7549_28)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-9b090e70ded6462b","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_9763_25 = \"defensive\"\n\ndef load_resource_consumption_9763_25(request_9763_25, scope_9763_25):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_9763_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_9763_25.read(int(scope_9763_25))\n","fixed_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_9763_25 = \"defensive\"\n\ndef load_resource_consumption_9763_25(request_9763_25, scope_9763_25):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_9763_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(scope_9763_25), 1), 1_048_576)\n data = request_9763_25.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_9b090e70_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_resource_consumption_9763_25)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-40d054d001774c84","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2148_6 = \"defensive\"\n\ndef load_httpx_client_ssrf_2148_6(request_2148_6, scope_2148_6, owner_2148_6):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2148_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2148_6.get(scope_2148_6, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2148_6 = \"defensive\"\n\ndef load_httpx_client_ssrf_2148_6(request_2148_6, scope_2148_6, owner_2148_6):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2148_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_2148_6)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_2148_6):\n raise ValueError(\"destination is not allowed\")\n return request_2148_6.get(scope_2148_6, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_40d054d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_2148_6)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-15f1957e34bd61b1","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_9082_20 = \"defensive\"\n\ndef apply_unsafe_deserialization_9082_20(payload_9082_20):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_9082_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_9082_20.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_9082_20 = \"defensive\"\n\ndef apply_unsafe_deserialization_9082_20(payload_9082_20):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_9082_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(payload_9082_20.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_15f1957e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_unsafe_deserialization_9082_20)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-e43dcd4f33b1decc","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_5561_19 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_5561_19(request_5561_19, scope_5561_19):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_5561_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return scope_5561_19.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_5561_19 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_5561_19(request_5561_19, scope_5561_19):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_5561_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_5561_19 is None or not request_5561_19.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_5561_19.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_e43dcd4f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_missing_authentication_5561_19)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-d8a08f05589e73bf","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_1663_10 = \"defensive\"\n\ndef load_django_safe_string_xss_1663_10(value_1663_10):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_1663_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{value_1663_10}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_1663_10 = \"defensive\"\n\ndef load_django_safe_string_xss_1663_10(value_1663_10):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_1663_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_1663_10)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_d8a08f05_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_1663_10)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-0290a40089402ad9","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_2522_6 = \"defensive\"\n\ndef resolve_http_response_splitting_2522_6(payload_2522_6, target_2522_6):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_2522_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2522_6.headers[\"X-Next\"] = target_2522_6\n return payload_2522_6\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_2522_6 = \"defensive\"\n\ndef resolve_http_response_splitting_2522_6(payload_2522_6, target_2522_6):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_2522_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_2522_6 or \"\\n\" in target_2522_6:\n raise ValueError(\"invalid header value\")\n payload_2522_6.headers[\"X-Next\"] = target_2522_6\n return payload_2522_6\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_0290a400_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_2522_6)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9a56185d5426f938","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_7509_2 = \"defensive\"\n\ndef handle_sql_injection_7509_2(payload_7509_2, target_7509_2):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_7509_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_7509_2.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_7509_2,)).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_7509_2 = \"defensive\"\n\ndef handle_sql_injection_7509_2(payload_7509_2, target_7509_2):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_7509_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_7509_2.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_7509_2,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_9a56185d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_7509_2)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-786cddeaec761332","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_3154_5 = \"defensive\"\n\ndef handle_starlette_permissive_cors_3154_5(value_3154_5, policy_3154_5):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_3154_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_3154_5)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3154_5.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3154_5\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_3154_5 = \"defensive\"\n\ndef handle_starlette_permissive_cors_3154_5(value_3154_5, policy_3154_5):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_3154_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_3154_5)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_3154_5.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_3154_5\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_786cddea_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_starlette_permissive_cors_3154_5)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-895012f3a3f57b11","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6805_9 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_6805_9(request_6805_9):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6805_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_6805_9, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6805_9 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_6805_9(request_6805_9):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6805_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_6805_9)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_895012f3_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyyaml_unsafe_load_6805_9)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-027ca2e2c77fe349","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_4096_12 = \"defensive\"\n\ndef apply_insecure_temp_file_4096_12(request_4096_12, context_4096_12):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_4096_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{request_4096_12}.txt\")\n path.write_text(context_4096_12, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_4096_12 = \"defensive\"\n\ndef apply_insecure_temp_file_4096_12(request_4096_12, context_4096_12):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_4096_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_4096_12)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_027ca2e2_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_4096_12)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-ff3c6079a0319ba9","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1569_10 = \"defensive\"\n\ndef load_insecure_file_permissions_1569_10(payload_1569_10, context_1569_10):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1569_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1569_10).write_text(context_1569_10, encoding=\"utf-8\")\n os.chmod(payload_1569_10, 0o777)\n return Path(payload_1569_10)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1569_10 = \"defensive\"\n\ndef load_insecure_file_permissions_1569_10(payload_1569_10, context_1569_10):\n if HANDLER_KIND_LOAD_INSECURE_FILE_PERMISSIONS_1569_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_1569_10).write_text(context_1569_10, encoding=\"utf-8\")\n os.chmod(payload_1569_10, 0o600)\n return Path(payload_1569_10)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_ff3c6079_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_file_permissions_1569_10)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-715bf5bcb13b2949","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_1939_23 = \"defensive\"\n\ndef process_httpx_client_ssrf_1939_23(request_1939_23, target_1939_23, allowed_1939_23):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_1939_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_1939_23)\n if parsed.scheme != \"https\" or parsed.hostname not in set(allowed_1939_23):\n raise ValueError(\"destination is not allowed\")\n return request_1939_23.get(target_1939_23, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_1939_23 = \"defensive\"\n\ndef process_httpx_client_ssrf_1939_23(request_1939_23, target_1939_23, allowed_1939_23):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_1939_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_1939_23)\n if parsed.scheme != \"https\" or parsed.hostname not in set(allowed_1939_23):\n raise ValueError(\"destination is not allowed\")\n return request_1939_23.get(target_1939_23, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_715bf5bc_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_1939_23)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-8c6003b727368df6","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_7143_11 = \"defensive\"\n\ndef resolve_path_traversal_7143_11(value_7143_11, scope_7143_11):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_7143_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_7143_11).resolve()\n candidate = (root / scope_7143_11).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_7143_11 = \"defensive\"\n\ndef resolve_path_traversal_7143_11(value_7143_11, scope_7143_11):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_7143_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_7143_11).resolve()\n candidate = (root / scope_7143_11).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_8c6003b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_path_traversal_7143_11)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-358cf7ad461e8fcf","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5952_17 = \"defensive\"\n\ndef apply_missing_authorization_5952_17(subject_5952_17, context_5952_17):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5952_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_5952_17.id != context_5952_17.owner_id:\n raise PermissionError(\"record ownership required\")\n context_5952_17.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5952_17 = \"defensive\"\n\ndef apply_missing_authorization_5952_17(subject_5952_17, context_5952_17):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5952_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_5952_17.id != context_5952_17.owner_id:\n raise PermissionError(\"record ownership required\")\n context_5952_17.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_358cf7ad_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_5952_17)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-4381a593a2f19ccc","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2875_15 = \"defensive\"\n\ndef handle_sensitive_data_exposure_2875_15(subject_2875_15, scope_2875_15, allowed_2875_15):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2875_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2875_15.info(\"login user=%s password=%s\", scope_2875_15, allowed_2875_15)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2875_15 = \"defensive\"\n\ndef handle_sensitive_data_exposure_2875_15(subject_2875_15, scope_2875_15, allowed_2875_15):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2875_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_2875_15.info(\"login user=%s\", scope_2875_15)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_4381a593_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_2875_15)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-a19b8344c64a0fd4","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_7920_22 = \"defensive\"\n\ndef apply_sql_injection_7920_22(value_7920_22, scope_7920_22):\n if HANDLER_KIND_APPLY_SQL_INJECTION_7920_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {scope_7920_22}\"\n return value_7920_22.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_7920_22 = \"defensive\"\n\ndef apply_sql_injection_7920_22(value_7920_22, scope_7920_22):\n if HANDLER_KIND_APPLY_SQL_INJECTION_7920_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7920_22.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (scope_7920_22,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_a19b8344_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_7920_22)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-b0cbc6213378f78d","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8510_16 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8510_16(value_8510_16):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8510_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(value_8510_16, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8510_16 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8510_16(value_8510_16):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8510_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(value_8510_16)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_b0cbc621_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_8510_16)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-981f10283c35d406","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3082_2 = \"defensive\"\n\ndef apply_httpx_client_ssrf_3082_2(value_3082_2, context_3082_2, owner_3082_2):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3082_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_3082_2)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3082_2):\n raise ValueError(\"destination is not allowed\")\n return value_3082_2.get(context_3082_2, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3082_2 = \"defensive\"\n\ndef apply_httpx_client_ssrf_3082_2(value_3082_2, context_3082_2, owner_3082_2):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_3082_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_3082_2)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3082_2):\n raise ValueError(\"destination is not allowed\")\n return value_3082_2.get(context_3082_2, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_981f1028_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_3082_2)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-986e493d17cfedf2","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_4792_11 = \"defensive\"\n\ndef process_cleartext_http_transport_4792_11(subject_4792_11):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_4792_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_4792_11, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_4792_11 = \"defensive\"\n\ndef process_cleartext_http_transport_4792_11(subject_4792_11):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_4792_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_4792_11, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_986e493d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_cleartext_http_transport_4792_11)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-cb6cca3b5b92026e","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9387_28 = \"defensive\"\n\ndef apply_requests_tls_verification_9387_28(value_9387_28):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9387_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_9387_28, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9387_28 = \"defensive\"\n\ndef apply_requests_tls_verification_9387_28(value_9387_28):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_9387_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_9387_28, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_cb6cca3b_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_9387_28)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-f06d1511ce25838f","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6799_22 = \"defensive\"\n\ndef handle_missing_authorization_6799_22(request_6799_22, target_6799_22):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6799_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n target_6799_22.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6799_22 = \"defensive\"\n\ndef handle_missing_authorization_6799_22(request_6799_22, target_6799_22):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_6799_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_6799_22.id != target_6799_22.owner_id:\n raise PermissionError(\"record ownership required\")\n target_6799_22.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_f06d1511_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_6799_22)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-d0b6195b8dbeda31","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_6461_11 = \"defensive\"\n\ndef resolve_weak_cryptography_6461_11(value_6461_11, target_6461_11):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_6461_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_6461_11.encode(\"utf-8\"), target_6461_11, 210000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_6461_11 = \"defensive\"\n\ndef resolve_weak_cryptography_6461_11(value_6461_11, target_6461_11):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_6461_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_6461_11.encode(\"utf-8\"), target_6461_11, 210000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_d0b6195b_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_6461_11)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-3af853b75a6cb42c","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9840_14 = \"defensive\"\n\ndef load_django_error_details_9840_14(request_9840_14, context_9840_14):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9840_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_9840_14()\n except Exception:\n request_9840_14.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9840_14 = \"defensive\"\n\ndef load_django_error_details_9840_14(request_9840_14, context_9840_14):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_9840_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_9840_14()\n except Exception:\n request_9840_14.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_3af853b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_9840_14)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-362f0bae24494ea1","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_4446_20 = \"defensive\"\n\ndef process_ldap_filter_injection_4446_20(payload_4446_20, policy_4446_20):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_4446_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_4446_20)\n query = f\"(uid={escaped})\"\n return payload_4446_20.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_4446_20 = \"defensive\"\n\ndef process_ldap_filter_injection_4446_20(payload_4446_20, policy_4446_20):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_4446_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_4446_20)\n query = f\"(uid={escaped})\"\n return payload_4446_20.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_362f0bae_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ldap_filter_injection_4446_20)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-f436481a8bfcb7ad","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_3247_22 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_3247_22(request_3247_22, target_3247_22):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_3247_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {target_3247_22}\")\n return request_3247_22.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_3247_22 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_3247_22(request_3247_22, target_3247_22):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_3247_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_3247_22.execute(statement, {\"account_id\": target_3247_22}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_f436481a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sqlalchemy_text_injection_3247_22)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-f74fa9494661d670","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2403_26 = \"defensive\"\n\ndef resolve_django_error_details_2403_26(request_2403_26, policy_2403_26):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2403_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2403_26()\n except Exception:\n request_2403_26.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2403_26 = \"defensive\"\n\ndef resolve_django_error_details_2403_26(request_2403_26, policy_2403_26):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2403_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2403_26()\n except Exception:\n request_2403_26.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_f74fa949_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_2403_26)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-9c91666b29d33cf3","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_6376_17 = \"defensive\"\n\ndef process_dynamic_code_injection_6376_17(request_6376_17):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_6376_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_6376_17) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_6376_17)\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_6376_17 = \"defensive\"\n\ndef process_dynamic_code_injection_6376_17(request_6376_17):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_6376_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_6376_17) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_6376_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_9c91666b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_6376_17)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-da2d524e33a149a1","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_4663_19 = \"defensive\"\n\ndef resolve_django_safe_string_xss_4663_19(payload_4663_19):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_4663_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_4663_19}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_4663_19 = \"defensive\"\n\ndef resolve_django_safe_string_xss_4663_19(payload_4663_19):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_4663_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_4663_19)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_da2d524e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_4663_19)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-7081e596b3837e6a","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3263_16 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3263_16(request_3263_16, target_3263_16):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3263_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{target_3263_16}']\"\n return request_3263_16.xpath(xpath)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3263_16 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3263_16(request_3263_16, target_3263_16):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3263_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_3263_16.xpath(\"//user[@name=$account]\", account=target_3263_16)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_7081e596_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_3263_16)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-33891a0f00a13858","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_1076_7 = \"defensive\"\n\ndef apply_path_traversal_1076_7(payload_1076_7, policy_1076_7):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_1076_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_1076_7) / policy_1076_7).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_1076_7 = \"defensive\"\n\ndef apply_path_traversal_1076_7(payload_1076_7, policy_1076_7):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_1076_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_1076_7).resolve()\n candidate = (root / policy_1076_7).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_33891a0f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_1076_7)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-0c89529f48c564b6","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9133_16 = \"defensive\"\n\ndef handle_flask_csrf_validation_9133_16(value_9133_16, scope_9133_16):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9133_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9133_16.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9133_16 = \"defensive\"\n\ndef handle_flask_csrf_validation_9133_16(value_9133_16, scope_9133_16):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9133_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_9133_16.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_9133_16.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_9133_16.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_0c89529f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_9133_16)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-a6d1c3136e7c9c29","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7409_5 = \"defensive\"\n\ndef handle_weak_cryptography_7409_5(payload_7409_5, context_7409_5):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7409_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_7409_5.encode(\"utf-8\"), context_7409_5, 200000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7409_5 = \"defensive\"\n\ndef handle_weak_cryptography_7409_5(payload_7409_5, context_7409_5):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7409_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_7409_5.encode(\"utf-8\"), context_7409_5, 200000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_a6d1c313_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_7409_5)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-1b03bb496d7a4ed6","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_1542_6 = \"defensive\"\n\ndef resolve_command_injection_1542_6(payload_1542_6, target_1542_6):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_1542_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_1542_6} {target_1542_6}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_RESOLVE_COMMAND_INJECTION_1542_6 = \"defensive\"\n\ndef resolve_command_injection_1542_6(payload_1542_6, target_1542_6):\n if HANDLER_KIND_RESOLVE_COMMAND_INJECTION_1542_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_1542_6, target_1542_6], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_1b03bb49_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_command_injection_1542_6)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-de923a9991a5eb3e","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5405_22 = \"defensive\"\n\ndef handle_http_response_splitting_5405_22(subject_5405_22, target_5405_22):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5405_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5405_22.headers[\"X-Next\"] = target_5405_22\n return subject_5405_22\n","fixed_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5405_22 = \"defensive\"\n\ndef handle_http_response_splitting_5405_22(subject_5405_22, target_5405_22):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5405_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_5405_22 or \"\\n\" in target_5405_22:\n raise ValueError(\"invalid header value\")\n subject_5405_22.headers[\"X-Next\"] = target_5405_22\n return subject_5405_22\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_de923a99_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_http_response_splitting_5405_22)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-642e87d8ca4da162","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_2102_22 = \"defensive\"\n\ndef resolve_regex_dos_2102_22(subject_2102_22, policy_2102_22):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_2102_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_2102_22, policy_2102_22) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_RESOLVE_REGEX_DOS_2102_22 = \"defensive\"\n\ndef resolve_regex_dos_2102_22(subject_2102_22, policy_2102_22):\n if HANDLER_KIND_RESOLVE_REGEX_DOS_2102_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_2102_22) > 256 or len(policy_2102_22) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_2102_22), policy_2102_22) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_642e87d8_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_regex_dos_2102_22)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-2fa82287f9386ea8","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_1585_24 = \"defensive\"\n\ndef apply_cleartext_http_transport_1585_24(payload_1585_24):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_1585_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_1585_24, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_1585_24 = \"defensive\"\n\ndef apply_cleartext_http_transport_1585_24(payload_1585_24):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_1585_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_1585_24, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_2fa82287_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_1585_24)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-09f15f939abdfff3","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_6249_16 = \"defensive\"\n\ndef load_flask_jinja_xss_6249_16(payload_6249_16):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_6249_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(payload_6249_16)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_6249_16 = \"defensive\"\n\ndef load_flask_jinja_xss_6249_16(payload_6249_16):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_6249_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_6249_16)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_09f15f93_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_jinja_xss_6249_16)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-ac64c46f1d0c85a8","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_4963_15 = \"defensive\"\n\ndef process_tarfile_path_traversal_4963_15(subject_4963_15, policy_4963_15):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_4963_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4963_15.extractall(policy_4963_15)\n return policy_4963_15\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_4963_15 = \"defensive\"\n\ndef process_tarfile_path_traversal_4963_15(subject_4963_15, policy_4963_15):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_4963_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_4963_15.extractall(policy_4963_15, filter=\"data\")\n return policy_4963_15\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_ac64c46f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_4963_15)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-a11368cbc8518872","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_2768_9 = \"defensive\"\n\ndef process_fastapi_upload_validation_2768_9(value_2768_9):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_2768_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_2768_9.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_2768_9 = \"defensive\"\n\ndef process_fastapi_upload_validation_2768_9(value_2768_9):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_2768_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_2768_9.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_2768_9.size is None or value_2768_9.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_2768_9.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_a11368cb_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_2768_9)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-031b02b253f4c195","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_8815_17 = \"defensive\"\n\ndef load_django_safe_string_xss_8815_17(payload_8815_17):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_8815_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_8815_17)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_8815_17 = \"defensive\"\n\ndef load_django_safe_string_xss_8815_17(payload_8815_17):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_8815_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_8815_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_031b02b2_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_8815_17)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-38413d994cc24309","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4936_12 = \"defensive\"\n\ndef handle_insecure_random_token_4936_12(subject_4936_12):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4936_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_4936_12)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4936_12 = \"defensive\"\n\ndef handle_insecure_random_token_4936_12(subject_4936_12):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_4936_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_4936_12)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_38413d99_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_random_token_4936_12)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-216585c01e3512a7","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_4221_5 = \"defensive\"\n\ndef load_regex_dos_4221_5(subject_4221_5, policy_4221_5):\n if HANDLER_KIND_LOAD_REGEX_DOS_4221_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4221_5) > 256 or len(policy_4221_5) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_4221_5), policy_4221_5) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_4221_5 = \"defensive\"\n\ndef load_regex_dos_4221_5(subject_4221_5, policy_4221_5):\n if HANDLER_KIND_LOAD_REGEX_DOS_4221_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4221_5) > 256 or len(policy_4221_5) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_4221_5), policy_4221_5) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_216585c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_regex_dos_4221_5)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-fc4cdbcf1191ed49","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_1969_21 = \"defensive\"\n\ndef process_resource_consumption_1969_21(value_1969_21, policy_1969_21):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_1969_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_1969_21.read(int(policy_1969_21))\n","fixed_code":"HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_1969_21 = \"defensive\"\n\ndef process_resource_consumption_1969_21(value_1969_21, policy_1969_21):\n if HANDLER_KIND_PROCESS_RESOURCE_CONSUMPTION_1969_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_1969_21), 1), 1_048_576)\n data = value_1969_21.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_fc4cdbcf_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_resource_consumption_1969_21)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-cfa48529802031d7","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1131_18 = \"defensive\"\n\ndef process_lxml_xpath_injection_1131_18(payload_1131_18, scope_1131_18):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1131_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_1131_18}']\"\n return payload_1131_18.xpath(xpath)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1131_18 = \"defensive\"\n\ndef process_lxml_xpath_injection_1131_18(payload_1131_18, scope_1131_18):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_1131_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_1131_18.xpath(\"//user[@name=$account]\", account=scope_1131_18)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_cfa48529_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_1131_18)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-01a9ae8554789885","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_4207_21 = \"defensive\"\n\ndef handle_regex_dos_4207_21(payload_4207_21, scope_4207_21):\n if HANDLER_KIND_HANDLE_REGEX_DOS_4207_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(payload_4207_21, scope_4207_21) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_HANDLE_REGEX_DOS_4207_21 = \"defensive\"\n\ndef handle_regex_dos_4207_21(payload_4207_21, scope_4207_21):\n if HANDLER_KIND_HANDLE_REGEX_DOS_4207_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_4207_21) > 256 or len(scope_4207_21) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(payload_4207_21), scope_4207_21) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_01a9ae85_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_regex_dos_4207_21)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-b3ec38c2f95540c6","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3567_9 = \"defensive\"\n\ndef process_insecure_file_permissions_3567_9(request_3567_9, policy_3567_9):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3567_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_3567_9).write_text(policy_3567_9, encoding=\"utf-8\")\n os.chmod(request_3567_9, 0o777)\n return Path(request_3567_9)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3567_9 = \"defensive\"\n\ndef process_insecure_file_permissions_3567_9(request_3567_9, policy_3567_9):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_3567_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_3567_9).write_text(policy_3567_9, encoding=\"utf-8\")\n os.chmod(request_3567_9, 0o600)\n return Path(request_3567_9)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_b3ec38c2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_3567_9)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-7c09d24be2520e18","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_6157_10 = \"defensive\"\n\ndef load_csv_formula_injection_6157_10(payload_6157_10):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_6157_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in payload_6157_10)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_6157_10 = \"defensive\"\n\ndef load_csv_formula_injection_6157_10(payload_6157_10):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_6157_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_6157_10)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_7c09d24b_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_6157_10)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-f05b18cc63ca6a5f","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8545_5 = \"defensive\"\n\ndef load_mass_assignment_8545_5(subject_8545_5, scope_8545_5):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8545_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_8545_5.items() if key in allowed_fields}\n subject_8545_5.update(safe)\n return subject_8545_5\n","fixed_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8545_5 = \"defensive\"\n\ndef load_mass_assignment_8545_5(subject_8545_5, scope_8545_5):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8545_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_8545_5.items() if key in allowed_fields}\n subject_8545_5.update(safe)\n return subject_8545_5\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_f05b18cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_mass_assignment_8545_5)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-94aae3dc350b76c8","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_2514_25 = \"defensive\"\n\ndef handle_command_injection_2514_25(request_2514_25, context_2514_25):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_2514_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {request_2514_25} {context_2514_25}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_2514_25 = \"defensive\"\n\ndef handle_command_injection_2514_25(request_2514_25, context_2514_25):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_2514_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_2514_25, context_2514_25], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_94aae3dc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_2514_25)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-d3bd929296c4e5b2","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_8097_17 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_8097_17(subject_8097_17, target_8097_17, limit_8097_17):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_8097_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_8097_17, target_8097_17, algorithms=[\"HS256\"], audience=limit_8097_17)\n","fixed_code":"import jwt\n\nHANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_8097_17 = \"defensive\"\n\ndef handle_pyjwt_signature_bypass_8097_17(subject_8097_17, target_8097_17, limit_8097_17):\n if HANDLER_KIND_HANDLE_PYJWT_SIGNATURE_BYPASS_8097_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_8097_17, target_8097_17, algorithms=[\"HS256\"], audience=limit_8097_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_d3bd9292_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyjwt_signature_bypass_8097_17)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-ecb5e6d068c7fe46","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_1644_7 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_1644_7(value_1644_7, target_1644_7, options_1644_7):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_1644_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_1644_7, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_1644_7 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_1644_7(value_1644_7, target_1644_7, options_1644_7):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_1644_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_1644_7, target_1644_7, algorithms=[\"HS256\"], audience=options_1644_7)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_ecb5e6d0_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_1644_7)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-d7db7e34cd8a4f19","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_1673_7 = \"defensive\"\n\ndef apply_regex_dos_1673_7(subject_1673_7, target_1673_7):\n if HANDLER_KIND_APPLY_REGEX_DOS_1673_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_1673_7, target_1673_7) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_1673_7 = \"defensive\"\n\ndef apply_regex_dos_1673_7(subject_1673_7, target_1673_7):\n if HANDLER_KIND_APPLY_REGEX_DOS_1673_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1673_7) > 256 or len(target_1673_7) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1673_7), target_1673_7) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_d7db7e34_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_regex_dos_1673_7)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9e50c499d2a7dfe9","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_7287_0 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_7287_0(payload_7287_0, context_7287_0):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_7287_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_7287_0}\")\n return payload_7287_0.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_7287_0 = \"defensive\"\n\ndef handle_sqlalchemy_text_injection_7287_0(payload_7287_0, context_7287_0):\n if HANDLER_KIND_HANDLE_SQLALCHEMY_TEXT_INJECTION_7287_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_7287_0.execute(statement, {\"account_id\": context_7287_0}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_9e50c499_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sqlalchemy_text_injection_7287_0)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-4a0cbb720a22d2de","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_7801_28 = \"defensive\"\n\ndef apply_mass_assignment_7801_28(subject_7801_28, policy_7801_28):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_7801_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_7801_28.items():\n setattr(subject_7801_28, key, value)\n return subject_7801_28\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_7801_28 = \"defensive\"\n\ndef apply_mass_assignment_7801_28(subject_7801_28, policy_7801_28):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_7801_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_7801_28.items() if key in allowed_fields}\n subject_7801_28.update(safe)\n return subject_7801_28\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_4a0cbb72_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_7801_28)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-4a822e13b2042870","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_2496_14 = \"defensive\"\n\ndef handle_missing_authorization_2496_14(payload_2496_14, scope_2496_14):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_2496_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_2496_14.id != scope_2496_14.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_2496_14.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_2496_14 = \"defensive\"\n\ndef handle_missing_authorization_2496_14(payload_2496_14, scope_2496_14):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_2496_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_2496_14.id != scope_2496_14.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_2496_14.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_4a822e13_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_2496_14)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-4ba976e9f4022b50","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_4875_5 = \"defensive\"\n\ndef apply_insecure_random_token_4875_5(value_4875_5):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_4875_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_4875_5)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_4875_5 = \"defensive\"\n\ndef apply_insecure_random_token_4875_5(value_4875_5):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_4875_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_4875_5)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_4ba976e9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_4875_5)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-fcc946524b1c83f1","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4614_13 = \"defensive\"\n\ndef load_lxml_external_entity_4614_13(request_4614_13):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4614_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(request_4614_13)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4614_13 = \"defensive\"\n\ndef load_lxml_external_entity_4614_13(request_4614_13):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_4614_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(request_4614_13, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_fcc94652_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_external_entity_4614_13)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-9eb709b889fdf7d5","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2421_28 = \"defensive\"\n\ndef load_plaintext_password_storage_2421_28(subject_2421_28, context_2421_28, allowed_2421_28):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2421_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(subject_2421_28).write_text(context_2421_28, encoding=\"utf-8\")\n return Path(subject_2421_28)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2421_28 = \"defensive\"\n\ndef load_plaintext_password_storage_2421_28(subject_2421_28, context_2421_28, allowed_2421_28):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_2421_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_2421_28) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", context_2421_28.encode(\"utf-8\"), allowed_2421_28, 240_000).hex()\n Path(subject_2421_28).write_text(verifier, encoding=\"ascii\")\n return Path(subject_2421_28)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_9eb709b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_2421_28)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-2bcd8490660d0d42","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5727_6 = \"defensive\"\n\ndef apply_django_safe_string_xss_5727_6(subject_5727_6):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5727_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{subject_5727_6}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5727_6 = \"defensive\"\n\ndef apply_django_safe_string_xss_5727_6(subject_5727_6):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5727_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_5727_6)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_2bcd8490_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_5727_6)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-f99dbd91af159fb9","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_2221_15 = \"defensive\"\n\ndef handle_insecure_random_token_2221_15(payload_2221_15):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_2221_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(payload_2221_15)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_2221_15 = \"defensive\"\n\ndef handle_insecure_random_token_2221_15(payload_2221_15):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_2221_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_2221_15)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_f99dbd91_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_random_token_2221_15)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-b765911426b91416","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_4455_25 = \"defensive\"\n\ndef resolve_missing_authorization_4455_25(payload_4455_25, context_4455_25):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_4455_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_4455_25.delete()\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_4455_25 = \"defensive\"\n\ndef resolve_missing_authorization_4455_25(payload_4455_25, context_4455_25):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_4455_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_4455_25.id != context_4455_25.owner_id:\n raise PermissionError(\"record ownership required\")\n context_4455_25.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_b7659114_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_missing_authorization_4455_25)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-6041fc4037e1702c","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9576_7 = \"defensive\"\n\ndef handle_insecure_file_permissions_9576_7(payload_9576_7, scope_9576_7):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9576_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9576_7).write_text(scope_9576_7, encoding=\"utf-8\")\n os.chmod(payload_9576_7, 0o777)\n return Path(payload_9576_7)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9576_7 = \"defensive\"\n\ndef handle_insecure_file_permissions_9576_7(payload_9576_7, scope_9576_7):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9576_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9576_7).write_text(scope_9576_7, encoding=\"utf-8\")\n os.chmod(payload_9576_7, 0o600)\n return Path(payload_9576_7)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_6041fc40_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_9576_7)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-e90acc51a5984740","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_2414_16 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_2414_16(value_2414_16, context_2414_16):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_2414_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_2414_16}\")\n return value_2414_16.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_2414_16 = \"defensive\"\n\ndef process_sqlalchemy_text_injection_2414_16(value_2414_16, context_2414_16):\n if HANDLER_KIND_PROCESS_SQLALCHEMY_TEXT_INJECTION_2414_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_2414_16.execute(statement, {\"account_id\": context_2414_16}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_e90acc51_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sqlalchemy_text_injection_2414_16)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-b7e5fe4c42fc8895","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_5900_19 = \"defensive\"\n\ndef process_missing_authorization_5900_19(request_5900_19, context_5900_19):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_5900_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_5900_19.delete()\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_5900_19 = \"defensive\"\n\ndef process_missing_authorization_5900_19(request_5900_19, context_5900_19):\n if HANDLER_KIND_PROCESS_MISSING_AUTHORIZATION_5900_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_5900_19.id != context_5900_19.owner_id:\n raise PermissionError(\"record ownership required\")\n context_5900_19.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_b7e5fe4c_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_missing_authorization_5900_19)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-3c94fded06ae1722","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9327_22 = \"defensive\"\n\ndef resolve_insecure_random_token_9327_22(subject_9327_22):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9327_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_9327_22)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9327_22 = \"defensive\"\n\ndef resolve_insecure_random_token_9327_22(subject_9327_22):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_9327_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_9327_22)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_3c94fded_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_random_token_9327_22)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-474989db4986a733","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8607_27 = \"defensive\"\n\ndef handle_django_safe_string_xss_8607_27(request_8607_27):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8607_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{request_8607_27}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8607_27 = \"defensive\"\n\ndef handle_django_safe_string_xss_8607_27(request_8607_27):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_8607_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_8607_27)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_474989db_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_8607_27)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-f6a2767445f22e59","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LOG_INJECTION_5779_21 = \"defensive\"\n\ndef load_log_injection_5779_21(payload_5779_21, scope_5779_21):\n if HANDLER_KIND_LOAD_LOG_INJECTION_5779_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5779_21.warning(\"audit=%s\", scope_5779_21)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_LOG_INJECTION_5779_21 = \"defensive\"\n\ndef load_log_injection_5779_21(payload_5779_21, scope_5779_21):\n if HANDLER_KIND_LOAD_LOG_INJECTION_5779_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_5779_21).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_5779_21.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_f6a27674_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_log_injection_5779_21)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-38e2fb3c24e269c0","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2194_12 = \"defensive\"\n\ndef resolve_flask_csrf_validation_2194_12(payload_2194_12, scope_2194_12):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2194_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_2194_12.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2194_12 = \"defensive\"\n\ndef resolve_flask_csrf_validation_2194_12(payload_2194_12, scope_2194_12):\n if HANDLER_KIND_RESOLVE_FLASK_CSRF_VALIDATION_2194_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_2194_12.headers.get(\"X-CSRF-Token\", \"\")\n expected = scope_2194_12.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_2194_12.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_38e2fb3c_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_csrf_validation_2194_12)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-d0e4595b2b1eac3a","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_9699_3 = \"defensive\"\n\ndef process_hardcoded_credentials_9699_3(payload_9699_3):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_9699_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000003\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_9699_3)}\n","fixed_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_9699_3 = \"defensive\"\n\ndef process_hardcoded_credentials_9699_3(payload_9699_3):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_9699_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_9699_3)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_d0e4595b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_hardcoded_credentials_9699_3)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-c707329276fffaa4","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_3124_13 = \"defensive\"\n\ndef resolve_ldap_filter_injection_3124_13(subject_3124_13, context_3124_13):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_3124_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_3124_13})\"\n return subject_3124_13.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_3124_13 = \"defensive\"\n\ndef resolve_ldap_filter_injection_3124_13(subject_3124_13, context_3124_13):\n if HANDLER_KIND_RESOLVE_LDAP_FILTER_INJECTION_3124_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_3124_13)\n query = f\"(uid={escaped})\"\n return subject_3124_13.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_c7073292_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ldap_filter_injection_3124_13)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-ce009676e8fa5448","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_7542_24 = \"defensive\"\n\ndef apply_missing_authorization_7542_24(subject_7542_24, policy_7542_24):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_7542_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n policy_7542_24.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_7542_24 = \"defensive\"\n\ndef apply_missing_authorization_7542_24(subject_7542_24, policy_7542_24):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_7542_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_7542_24.id != policy_7542_24.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_7542_24.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_ce009676_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_7542_24)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-c2f86ec44394e46e","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1856_14 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1856_14(payload_1856_14):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1856_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_1856_14)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1856_14 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1856_14(payload_1856_14):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1856_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_1856_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_c2f86ec4_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_1856_14)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-83da2f18126cc2ba","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_9861_11 = \"defensive\"\n\ndef handle_fastapi_upload_validation_9861_11(subject_9861_11):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_9861_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_9861_11.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_9861_11.size is None or subject_9861_11.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_9861_11.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_9861_11 = \"defensive\"\n\ndef handle_fastapi_upload_validation_9861_11(subject_9861_11):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_9861_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_9861_11.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_9861_11.size is None or subject_9861_11.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_9861_11.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_83da2f18_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_9861_11)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-3257d81217ec4b77","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3254_19 = \"defensive\"\n\ndef resolve_csv_formula_injection_3254_19(value_3254_19):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3254_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in value_3254_19)\n","fixed_code":"HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3254_19 = \"defensive\"\n\ndef resolve_csv_formula_injection_3254_19(value_3254_19):\n if HANDLER_KIND_RESOLVE_CSV_FORMULA_INJECTION_3254_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_3254_19)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_3257d812_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_csv_formula_injection_3254_19)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-8495d6cb4e71636d","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2974_0 = \"defensive\"\n\ndef apply_starlette_permissive_cors_2974_0(payload_2974_0, policy_2974_0):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2974_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2974_0.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return payload_2974_0\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2974_0 = \"defensive\"\n\ndef apply_starlette_permissive_cors_2974_0(payload_2974_0, policy_2974_0):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2974_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_2974_0)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_2974_0.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_2974_0\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_8495d6cb_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_2974_0)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-5993523fb4d0bd75","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4920_3 = \"defensive\"\n\ndef apply_django_safe_string_xss_4920_3(payload_4920_3):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4920_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_4920_3}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4920_3 = \"defensive\"\n\ndef apply_django_safe_string_xss_4920_3(payload_4920_3):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_4920_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_4920_3)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_5993523f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_4920_3)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-18307997d37ac6db","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_2491_22 = \"defensive\"\n\ndef resolve_insecure_temp_file_2491_22(payload_2491_22, scope_2491_22):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_2491_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_2491_22}.txt\")\n path.write_text(scope_2491_22, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_2491_22 = \"defensive\"\n\ndef resolve_insecure_temp_file_2491_22(payload_2491_22, scope_2491_22):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_2491_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_2491_22)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_18307997_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_2491_22)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-38f8c148c6992821","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":false,"vulnerable_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_4610_11 = \"defensive\"\n\ndef process_flask_csrf_validation_4610_11(request_4610_11, context_4610_11):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_4610_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_4610_11.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_4610_11.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_4610_11.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_4610_11 = \"defensive\"\n\ndef process_flask_csrf_validation_4610_11(request_4610_11, context_4610_11):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_4610_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_4610_11.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_4610_11.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_4610_11.form[\"amount\"]\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-352: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_csrf_validation_38f8c148_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_4610_11)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-b9b764fcf5fcb738","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_7561_4 = \"defensive\"\n\ndef apply_flask_session_fixation_7561_4(request_7561_4, target_7561_4):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_7561_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_7561_4[\"user_id\"] = target_7561_4.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_7561_4 = \"defensive\"\n\ndef apply_flask_session_fixation_7561_4(request_7561_4, target_7561_4):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_7561_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_7561_4.clear()\n request_7561_4[\"user_id\"] = target_7561_4.id\n request_7561_4[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_b9b764fc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_7561_4)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-5467771626223e60","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_3219_5 = \"defensive\"\n\ndef load_django_safe_string_xss_3219_5(payload_3219_5):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_3219_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_3219_5)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_3219_5 = \"defensive\"\n\ndef load_django_safe_string_xss_3219_5(payload_3219_5):\n if HANDLER_KIND_LOAD_DJANGO_SAFE_STRING_XSS_3219_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_3219_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_54677716_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_safe_string_xss_3219_5)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-daefb911226b294c","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_8386_20 = \"defensive\"\n\ndef handle_plaintext_password_storage_8386_20(subject_8386_20, policy_8386_20, allowed_8386_20):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_8386_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_8386_20) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_8386_20.encode(\"utf-8\"), allowed_8386_20, 240_000).hex()\n Path(subject_8386_20).write_text(verifier, encoding=\"ascii\")\n return Path(subject_8386_20)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_8386_20 = \"defensive\"\n\ndef handle_plaintext_password_storage_8386_20(subject_8386_20, policy_8386_20, allowed_8386_20):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_8386_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_8386_20) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_8386_20.encode(\"utf-8\"), allowed_8386_20, 240_000).hex()\n Path(subject_8386_20).write_text(verifier, encoding=\"ascii\")\n return Path(subject_8386_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_daefb911_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_8386_20)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-928a9eb9cada675f","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7630_4 = \"defensive\"\n\ndef handle_insecure_temp_file_7630_4(payload_7630_4, policy_7630_4):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7630_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_7630_4}.txt\")\n path.write_text(policy_7630_4, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7630_4 = \"defensive\"\n\ndef handle_insecure_temp_file_7630_4(payload_7630_4, policy_7630_4):\n if HANDLER_KIND_HANDLE_INSECURE_TEMP_FILE_7630_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_7630_4)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_928a9eb9_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_temp_file_7630_4)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-7e57532a54db38ec","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6764_28 = \"defensive\"\n\ndef load_flask_open_redirect_6764_28(payload_6764_28):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6764_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(payload_6764_28)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6764_28 = \"defensive\"\n\ndef load_flask_open_redirect_6764_28(payload_6764_28):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6764_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_6764_28)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_6764_28)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_7e57532a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_open_redirect_6764_28)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-916cede974796ec8","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8034_3 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8034_3(payload_8034_3, target_8034_3, options_8034_3):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8034_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8034_3.info(\"login user=%s password=%s\", target_8034_3, options_8034_3)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8034_3 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8034_3(payload_8034_3, target_8034_3, options_8034_3):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8034_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8034_3.info(\"login user=%s\", target_8034_3)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_916cede9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sensitive_data_exposure_8034_3)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-19f371d8072e8813","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_5178_22 = \"defensive\"\n\ndef handle_ssrf_5178_22(value_5178_22, scope_5178_22):\n if HANDLER_KIND_HANDLE_SSRF_5178_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(value_5178_22, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_5178_22 = \"defensive\"\n\ndef handle_ssrf_5178_22(value_5178_22, scope_5178_22):\n if HANDLER_KIND_HANDLE_SSRF_5178_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_5178_22)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_5178_22):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_5178_22, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_19f371d8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_5178_22)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-39c63b99f0ff2492","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6117_15 = \"defensive\"\n\ndef apply_http_response_splitting_6117_15(request_6117_15, scope_6117_15):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6117_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_6117_15.headers[\"X-Next\"] = scope_6117_15\n return request_6117_15\n","fixed_code":"HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6117_15 = \"defensive\"\n\ndef apply_http_response_splitting_6117_15(request_6117_15, scope_6117_15):\n if HANDLER_KIND_APPLY_HTTP_RESPONSE_SPLITTING_6117_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_6117_15 or \"\\n\" in scope_6117_15:\n raise ValueError(\"invalid header value\")\n request_6117_15.headers[\"X-Next\"] = scope_6117_15\n return request_6117_15\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_39c63b99_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_http_response_splitting_6117_15)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-e5bdf5572a685a0c","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_3622_23 = \"defensive\"\n\ndef process_fastapi_missing_authentication_3622_23(value_3622_23, context_3622_23):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_3622_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3622_23 is None or not value_3622_23.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_3622_23.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_3622_23 = \"defensive\"\n\ndef process_fastapi_missing_authentication_3622_23(value_3622_23, context_3622_23):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_3622_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_3622_23 is None or not value_3622_23.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_3622_23.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_e5bdf557_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_3622_23)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-921d9415bd9f5835","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_6119_9 = \"defensive\"\n\ndef load_lxml_external_entity_6119_9(subject_6119_9):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_6119_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(subject_6119_9)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_6119_9 = \"defensive\"\n\ndef load_lxml_external_entity_6119_9(subject_6119_9):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_6119_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(subject_6119_9, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_921d9415_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_external_entity_6119_9)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-0418ec5a8821e6ea","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_8699_24 = \"defensive\"\n\ndef process_lxml_external_entity_8699_24(value_8699_24):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_8699_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_8699_24)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_8699_24 = \"defensive\"\n\ndef process_lxml_external_entity_8699_24(value_8699_24):\n if HANDLER_KIND_PROCESS_LXML_EXTERNAL_ENTITY_8699_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_8699_24, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_0418ec5a_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_external_entity_8699_24)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-3832aa9df771248a","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_4117_11 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_4117_11(value_4117_11, target_4117_11, allowed_4117_11):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_4117_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_4117_11, target_4117_11, algorithms=[\"HS256\"], audience=allowed_4117_11)\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_4117_11 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_4117_11(value_4117_11, target_4117_11, allowed_4117_11):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_4117_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_4117_11, target_4117_11, algorithms=[\"HS256\"], audience=allowed_4117_11)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_3832aa9d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_4117_11)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-2a95df21bf5301e0","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":false,"vulnerable_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_1782_20 = \"defensive\"\n\ndef process_regex_dos_1782_20(subject_1782_20, scope_1782_20):\n if HANDLER_KIND_PROCESS_REGEX_DOS_1782_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1782_20) > 256 or len(scope_1782_20) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1782_20), scope_1782_20) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_PROCESS_REGEX_DOS_1782_20 = \"defensive\"\n\ndef process_regex_dos_1782_20(subject_1782_20, scope_1782_20):\n if HANDLER_KIND_PROCESS_REGEX_DOS_1782_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_1782_20) > 256 or len(scope_1782_20) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_1782_20), scope_1782_20) is not None\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1333: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_regex_dos_2a95df21_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_regex_dos_1782_20)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-b6c0eb9fe87e84d2","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6648_6 = \"defensive\"\n\ndef apply_flask_open_redirect_6648_6(subject_6648_6):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6648_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(subject_6648_6)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6648_6 = \"defensive\"\n\ndef apply_flask_open_redirect_6648_6(subject_6648_6):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_6648_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_6648_6)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_6648_6)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_b6c0eb9f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_open_redirect_6648_6)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-461d19a7a66d5e0d","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6875_27 = \"defensive\"\n\ndef handle_unsafe_deserialization_6875_27(value_6875_27):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6875_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_6875_27)\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6875_27 = \"defensive\"\n\ndef handle_unsafe_deserialization_6875_27(value_6875_27):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6875_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_6875_27.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_461d19a7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_6875_27)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-e8c491bee6fdc30b","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1828_4 = \"defensive\"\n\ndef handle_flask_open_redirect_1828_4(value_1828_4):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1828_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(value_1828_4)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1828_4 = \"defensive\"\n\ndef handle_flask_open_redirect_1828_4(value_1828_4):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_1828_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_1828_4)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_1828_4)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_e8c491be_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_1828_4)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-ac890fe76ca3a576","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_1988_24 = \"defensive\"\n\ndef apply_starlette_permissive_cors_1988_24(value_1988_24, context_1988_24):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_1988_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_1988_24.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return value_1988_24\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_1988_24 = \"defensive\"\n\ndef apply_starlette_permissive_cors_1988_24(value_1988_24, context_1988_24):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_1988_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(context_1988_24)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n value_1988_24.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return value_1988_24\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_ac890fe7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_1988_24)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-6d9a149cfe8030c0","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2928_28 = \"defensive\"\n\ndef handle_flask_csrf_validation_2928_28(value_2928_28, context_2928_28):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2928_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_2928_28.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2928_28 = \"defensive\"\n\ndef handle_flask_csrf_validation_2928_28(value_2928_28, context_2928_28):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_2928_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_2928_28.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_2928_28.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_2928_28.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_6d9a149c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_2928_28)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-359ec4a4b8af0e40","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_2196_19 = \"defensive\"\n\ndef handle_requests_tls_verification_2196_19(request_2196_19):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_2196_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_2196_19, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_2196_19 = \"defensive\"\n\ndef handle_requests_tls_verification_2196_19(request_2196_19):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_2196_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_2196_19, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_359ec4a4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_2196_19)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-be0245cc1b5b8801","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5890_16 = \"defensive\"\n\ndef handle_requests_tls_verification_5890_16(payload_5890_16):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5890_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_5890_16, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5890_16 = \"defensive\"\n\ndef handle_requests_tls_verification_5890_16(payload_5890_16):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_5890_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_5890_16, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_be0245cc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_5890_16)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-342d98bdac80a0ab","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3776_24 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3776_24(subject_3776_24, scope_3776_24):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3776_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{scope_3776_24}']\"\n return subject_3776_24.xpath(xpath)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3776_24 = \"defensive\"\n\ndef apply_lxml_xpath_injection_3776_24(subject_3776_24, scope_3776_24):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_3776_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3776_24.xpath(\"//user[@name=$account]\", account=scope_3776_24)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_342d98bd_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_3776_24)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-e281e26714133323","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2308_28 = \"defensive\"\n\ndef handle_sensitive_data_exposure_2308_28(request_2308_28, policy_2308_28, limit_2308_28):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2308_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2308_28.info(\"login user=%s password=%s\", policy_2308_28, limit_2308_28)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2308_28 = \"defensive\"\n\ndef handle_sensitive_data_exposure_2308_28(request_2308_28, policy_2308_28, limit_2308_28):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_2308_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2308_28.info(\"login user=%s\", policy_2308_28)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_e281e267_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_2308_28)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-9dca32905938fefe","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_2768_23 = \"defensive\"\n\ndef handle_weak_cryptography_2768_23(request_2768_23, target_2768_23):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_2768_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", request_2768_23.encode(\"utf-8\"), target_2768_23, 230000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_2768_23 = \"defensive\"\n\ndef handle_weak_cryptography_2768_23(request_2768_23, target_2768_23):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_2768_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", request_2768_23.encode(\"utf-8\"), target_2768_23, 230000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_9dca3290_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_2768_23)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-81abf2e8a314f63c","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8867_0 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8867_0(payload_8867_0, policy_8867_0, allowed_8867_0):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8867_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8867_0.info(\"login user=%s password=%s\", policy_8867_0, allowed_8867_0)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8867_0 = \"defensive\"\n\ndef apply_sensitive_data_exposure_8867_0(payload_8867_0, policy_8867_0, allowed_8867_0):\n if HANDLER_KIND_APPLY_SENSITIVE_DATA_EXPOSURE_8867_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_8867_0.info(\"login user=%s\", policy_8867_0)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_81abf2e8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sensitive_data_exposure_8867_0)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-2d396497ad44e014","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_2226_12 = \"defensive\"\n\ndef handle_plaintext_password_storage_2226_12(request_2226_12, policy_2226_12, allowed_2226_12):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_2226_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_2226_12).write_text(policy_2226_12, encoding=\"utf-8\")\n return Path(request_2226_12)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_2226_12 = \"defensive\"\n\ndef handle_plaintext_password_storage_2226_12(request_2226_12, policy_2226_12, allowed_2226_12):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_2226_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(allowed_2226_12) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_2226_12.encode(\"utf-8\"), allowed_2226_12, 240_000).hex()\n Path(request_2226_12).write_text(verifier, encoding=\"ascii\")\n return Path(request_2226_12)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_2d396497_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_2226_12)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-7cc7d785efe22c63","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7927_29 = \"defensive\"\n\ndef handle_csv_formula_injection_7927_29(payload_7927_29):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7927_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7927_29)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7927_29 = \"defensive\"\n\ndef handle_csv_formula_injection_7927_29(payload_7927_29):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_7927_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in payload_7927_29)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_7cc7d785_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_7927_29)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-f25f0084f01eac6a","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_2113_24 = \"defensive\"\n\ndef handle_sql_injection_2113_24(request_2113_24, context_2113_24):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_2113_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {context_2113_24}\"\n return request_2113_24.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_HANDLE_SQL_INJECTION_2113_24 = \"defensive\"\n\ndef handle_sql_injection_2113_24(request_2113_24, context_2113_24):\n if HANDLER_KIND_HANDLE_SQL_INJECTION_2113_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2113_24.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (context_2113_24,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_f25f0084_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sql_injection_2113_24)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-49e856794646845e","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_9558_14 = \"defensive\"\n\ndef process_sql_injection_9558_14(subject_9558_14, target_9558_14):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_9558_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9558_14.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9558_14,)).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_9558_14 = \"defensive\"\n\ndef process_sql_injection_9558_14(subject_9558_14, target_9558_14):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_9558_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9558_14.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_9558_14,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_49e85679_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_9558_14)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-b86c416ee22f2df2","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4983_25 = \"defensive\"\n\ndef process_unsafe_deserialization_4983_25(subject_4983_25):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4983_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(subject_4983_25)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4983_25 = \"defensive\"\n\ndef process_unsafe_deserialization_4983_25(subject_4983_25):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_4983_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_4983_25.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_b86c416e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_4983_25)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-d43b5a04897367de","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_6404_2 = \"defensive\"\n\ndef process_cleartext_http_transport_6404_2(subject_6404_2):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_6404_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_6404_2, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_6404_2 = \"defensive\"\n\ndef process_cleartext_http_transport_6404_2(subject_6404_2):\n if HANDLER_KIND_PROCESS_CLEARTEXT_HTTP_TRANSPORT_6404_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_6404_2, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_d43b5a04_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_cleartext_http_transport_6404_2)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-44c6ce58f32fd924","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":false,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2120_17 = \"defensive\"\n\ndef apply_starlette_permissive_cors_2120_17(request_2120_17, target_2120_17):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2120_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_2120_17)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_2120_17.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_2120_17\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2120_17 = \"defensive\"\n\ndef apply_starlette_permissive_cors_2120_17(request_2120_17, target_2120_17):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_2120_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(target_2120_17)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n request_2120_17.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return request_2120_17\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-942: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_starlette_permissive_cors_44c6ce58_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_2120_17)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-01aeb063171e08d7","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_5232_13 = \"defensive\"\n\ndef handle_mass_assignment_5232_13(payload_5232_13, target_5232_13):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_5232_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in target_5232_13.items():\n setattr(payload_5232_13, key, value)\n return payload_5232_13\n","fixed_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_5232_13 = \"defensive\"\n\ndef handle_mass_assignment_5232_13(payload_5232_13, target_5232_13):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_5232_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_5232_13.items() if key in allowed_fields}\n payload_5232_13.update(safe)\n return payload_5232_13\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_01aeb063_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_mass_assignment_5232_13)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-f4614ad33193fa3e","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7350_25 = \"defensive\"\n\ndef apply_hardcoded_credentials_7350_25(subject_7350_25):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7350_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000025\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_7350_25)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7350_25 = \"defensive\"\n\ndef apply_hardcoded_credentials_7350_25(subject_7350_25):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_7350_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_7350_25)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_f4614ad3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_7350_25)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-2cf99ca4afaf6244","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_6679_18 = \"defensive\"\n\ndef process_insecure_random_token_6679_18(request_6679_18):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_6679_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_6679_18)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_6679_18 = \"defensive\"\n\ndef process_insecure_random_token_6679_18(request_6679_18):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_6679_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_6679_18)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_2cf99ca4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_random_token_6679_18)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-e17575815349ef76","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2935_19 = \"defensive\"\n\ndef apply_flask_session_fixation_2935_19(value_2935_19, context_2935_19):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2935_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2935_19[\"user_id\"] = context_2935_19.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2935_19 = \"defensive\"\n\ndef apply_flask_session_fixation_2935_19(value_2935_19, context_2935_19):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_2935_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2935_19.clear()\n value_2935_19[\"user_id\"] = context_2935_19.id\n value_2935_19[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_e1757581_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_2935_19)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-af4bfcfa34bbbd72","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2873_24 = \"defensive\"\n\ndef apply_flask_csrf_validation_2873_24(value_2873_24, policy_2873_24):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2873_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_2873_24.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2873_24 = \"defensive\"\n\ndef apply_flask_csrf_validation_2873_24(value_2873_24, policy_2873_24):\n if HANDLER_KIND_APPLY_FLASK_CSRF_VALIDATION_2873_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = value_2873_24.headers.get(\"X-CSRF-Token\", \"\")\n expected = policy_2873_24.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return value_2873_24.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_af4bfcfa_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_csrf_validation_2873_24)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-347f12db4e77d843","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_9929_21 = \"defensive\"\n\ndef apply_command_injection_9929_21(payload_9929_21, policy_9929_21):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_9929_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {payload_9929_21} {policy_9929_21}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_APPLY_COMMAND_INJECTION_9929_21 = \"defensive\"\n\ndef apply_command_injection_9929_21(payload_9929_21, policy_9929_21):\n if HANDLER_KIND_APPLY_COMMAND_INJECTION_9929_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_9929_21, policy_9929_21], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_347f12db_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_command_injection_9929_21)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-3b5f7ce86aac4747","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_9351_12 = \"defensive\"\n\ndef load_http_response_splitting_9351_12(payload_9351_12, target_9351_12):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_9351_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9351_12.headers[\"X-Next\"] = target_9351_12\n return payload_9351_12\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_9351_12 = \"defensive\"\n\ndef load_http_response_splitting_9351_12(payload_9351_12, target_9351_12):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_9351_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_9351_12 or \"\\n\" in target_9351_12:\n raise ValueError(\"invalid header value\")\n payload_9351_12.headers[\"X-Next\"] = target_9351_12\n return payload_9351_12\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_3b5f7ce8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_9351_12)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-e8ab7eccae0cc759","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_5832_29 = \"defensive\"\n\ndef resolve_insecure_random_token_5832_29(payload_5832_29):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_5832_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_5832_29)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_5832_29 = \"defensive\"\n\ndef resolve_insecure_random_token_5832_29(payload_5832_29):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_5832_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_5832_29)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_e8ab7ecc_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_random_token_5832_29)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-7968b393a843f37b","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_3482_1 = \"defensive\"\n\ndef load_insecure_temp_file_3482_1(value_3482_1, context_3482_1):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_3482_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{value_3482_1}.txt\")\n path.write_text(context_3482_1, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_LOAD_INSECURE_TEMP_FILE_3482_1 = \"defensive\"\n\ndef load_insecure_temp_file_3482_1(value_3482_1, context_3482_1):\n if HANDLER_KIND_LOAD_INSECURE_TEMP_FILE_3482_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3482_1)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_7968b393_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_temp_file_3482_1)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-815f2808a60a7549","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6123_28 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_6123_28(request_6123_28, scope_6123_28):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6123_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {scope_6123_28}\")\n return request_6123_28.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6123_28 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_6123_28(request_6123_28, scope_6123_28):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_6123_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_6123_28.execute(statement, {\"account_id\": scope_6123_28}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_815f2808_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_6123_28)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-3da1699426ba81c5","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1707_15 = \"defensive\"\n\ndef resolve_missing_authorization_1707_15(request_1707_15, scope_1707_15):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1707_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n scope_1707_15.delete()\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1707_15 = \"defensive\"\n\ndef resolve_missing_authorization_1707_15(request_1707_15, scope_1707_15):\n if HANDLER_KIND_RESOLVE_MISSING_AUTHORIZATION_1707_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_1707_15.id != scope_1707_15.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1707_15.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_3da16994_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_missing_authorization_1707_15)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-4e4c808356ac1f1c","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8572_14 = \"defensive\"\n\ndef resolve_mass_assignment_8572_14(request_8572_14, scope_8572_14):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8572_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_8572_14.items() if key in allowed_fields}\n request_8572_14.update(safe)\n return request_8572_14\n","fixed_code":"HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8572_14 = \"defensive\"\n\ndef resolve_mass_assignment_8572_14(request_8572_14, scope_8572_14):\n if HANDLER_KIND_RESOLVE_MASS_ASSIGNMENT_8572_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in scope_8572_14.items() if key in allowed_fields}\n request_8572_14.update(safe)\n return request_8572_14\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_4e4c8083_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_mass_assignment_8572_14)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-2f9ac368c589c036","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_SSRF_5343_19 = \"defensive\"\n\ndef apply_ssrf_5343_19(request_5343_19, policy_5343_19):\n if HANDLER_KIND_APPLY_SSRF_5343_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_5343_19, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_5343_19 = \"defensive\"\n\ndef apply_ssrf_5343_19(request_5343_19, policy_5343_19):\n if HANDLER_KIND_APPLY_SSRF_5343_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_5343_19)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_5343_19):\n raise ValueError(\"destination is not allowed\")\n return requests.get(request_5343_19, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_2f9ac368_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_5343_19)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-b9c9a9e507cc9355","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_3324_14 = \"defensive\"\n\ndef load_csv_formula_injection_3324_14(value_3324_14):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_3324_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_3324_14)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_3324_14 = \"defensive\"\n\ndef load_csv_formula_injection_3324_14(value_3324_14):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_3324_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in value_3324_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_b9c9a9e5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_3324_14)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-d73991ca2506c0c0","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_6362_1 = \"defensive\"\n\ndef resolve_sql_injection_6362_1(value_6362_1, target_6362_1):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_6362_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {target_6362_1}\"\n return value_6362_1.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_6362_1 = \"defensive\"\n\ndef resolve_sql_injection_6362_1(value_6362_1, target_6362_1):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_6362_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_6362_1.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (target_6362_1,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_d73991ca_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_6362_1)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-4e8704125650ba4f","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_5248_24 = \"defensive\"\n\ndef load_csv_formula_injection_5248_24(subject_5248_24):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_5248_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return \",\".join(str(value) for value in subject_5248_24)\n","fixed_code":"HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_5248_24 = \"defensive\"\n\ndef load_csv_formula_injection_5248_24(subject_5248_24):\n if HANDLER_KIND_LOAD_CSV_FORMULA_INJECTION_5248_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_5248_24)\n","vulnerable_lines":[6],"explanation":"Spreadsheet control characters at the start of a cell can be interpreted as formulas.","patch_summary":"Prefix formula-like cells so spreadsheet software treats them as text.","safe_test":"def test_csv_formula_injection_4e870412_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_csv_formula_injection_5248_24)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-7fd0c5c7b285b2dd","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7488_23 = \"defensive\"\n\ndef handle_flask_open_redirect_7488_23(payload_7488_23):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7488_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_7488_23)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_7488_23)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7488_23 = \"defensive\"\n\ndef handle_flask_open_redirect_7488_23(payload_7488_23):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_7488_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_7488_23)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_7488_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_7fd0c5c7_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_7488_23)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-fe07213f47027a66","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_7352_2 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_7352_2(value_7352_2, policy_7352_2):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_7352_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_7352_2 is None or not value_7352_2.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_7352_2.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_7352_2 = \"defensive\"\n\ndef apply_fastapi_missing_authentication_7352_2(value_7352_2, policy_7352_2):\n if HANDLER_KIND_APPLY_FASTAPI_MISSING_AUTHENTICATION_7352_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_7352_2 is None or not value_7352_2.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_7352_2.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_fe07213f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_missing_authentication_7352_2)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-7862a770792a3fbf","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_8737_13 = \"defensive\"\n\ndef load_http_response_splitting_8737_13(request_8737_13, scope_8737_13):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_8737_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_8737_13.headers[\"X-Next\"] = scope_8737_13\n return request_8737_13\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_8737_13 = \"defensive\"\n\ndef load_http_response_splitting_8737_13(request_8737_13, scope_8737_13):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_8737_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_8737_13 or \"\\n\" in scope_8737_13:\n raise ValueError(\"invalid header value\")\n request_8737_13.headers[\"X-Next\"] = scope_8737_13\n return request_8737_13\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_7862a770_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_8737_13)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-6beeb8d3bcdfb64a","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6876_2 = \"defensive\"\n\ndef load_flask_open_redirect_6876_2(value_6876_2):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6876_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_6876_2)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_6876_2)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6876_2 = \"defensive\"\n\ndef load_flask_open_redirect_6876_2(value_6876_2):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_6876_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_6876_2)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(value_6876_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_6beeb8d3_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_open_redirect_6876_2)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-0f5cead60d64d7ad","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1438_1 = \"defensive\"\n\ndef load_django_error_details_1438_1(value_1438_1, policy_1438_1):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1438_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_1438_1()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1438_1 = \"defensive\"\n\ndef load_django_error_details_1438_1(value_1438_1, policy_1438_1):\n if HANDLER_KIND_LOAD_DJANGO_ERROR_DETAILS_1438_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_1438_1()\n except Exception:\n value_1438_1.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_0f5cead6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_django_error_details_1438_1)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-dc9305a6a21a3b57","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_8149_24 = \"defensive\"\n\ndef process_insecure_random_token_8149_24(request_8149_24):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_8149_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(request_8149_24)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_8149_24 = \"defensive\"\n\ndef process_insecure_random_token_8149_24(request_8149_24):\n if HANDLER_KIND_PROCESS_INSECURE_RANDOM_TOKEN_8149_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(request_8149_24)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_dc9305a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_random_token_8149_24)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-36cfae6dac618c39","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_1390_13 = \"defensive\"\n\ndef process_path_traversal_1390_13(payload_1390_13, policy_1390_13):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_1390_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_1390_13) / policy_1390_13).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_1390_13 = \"defensive\"\n\ndef process_path_traversal_1390_13(payload_1390_13, policy_1390_13):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_1390_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_1390_13).resolve()\n candidate = (root / policy_1390_13).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_36cfae6d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_1390_13)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-8a7672f281754a44","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_7042_14 = \"defensive\"\n\ndef process_insecure_file_permissions_7042_14(value_7042_14, context_7042_14):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_7042_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_7042_14).write_text(context_7042_14, encoding=\"utf-8\")\n os.chmod(value_7042_14, 0o600)\n return Path(value_7042_14)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_7042_14 = \"defensive\"\n\ndef process_insecure_file_permissions_7042_14(value_7042_14, context_7042_14):\n if HANDLER_KIND_PROCESS_INSECURE_FILE_PERMISSIONS_7042_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_7042_14).write_text(context_7042_14, encoding=\"utf-8\")\n os.chmod(value_7042_14, 0o600)\n return Path(value_7042_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_8a7672f2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_file_permissions_7042_14)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-2d14548739e7d185","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4858_2 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_4858_2(request_4858_2, policy_4858_2, limit_4858_2):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4858_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_4858_2, policy_4858_2, algorithms=[\"HS256\"], audience=limit_4858_2)\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4858_2 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_4858_2(request_4858_2, policy_4858_2, limit_4858_2):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_4858_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_4858_2, policy_4858_2, algorithms=[\"HS256\"], audience=limit_4858_2)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_2d145487_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_4858_2)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-c5e74c3478e85a06","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_9793_19 = \"defensive\"\n\ndef process_lxml_xpath_injection_9793_19(subject_9793_19, context_9793_19):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_9793_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n xpath = f\"//user[@name='{context_9793_19}']\"\n return subject_9793_19.xpath(xpath)\n","fixed_code":"HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_9793_19 = \"defensive\"\n\ndef process_lxml_xpath_injection_9793_19(subject_9793_19, context_9793_19):\n if HANDLER_KIND_PROCESS_LXML_XPATH_INJECTION_9793_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9793_19.xpath(\"//user[@name=$account]\", account=context_9793_19)\n","vulnerable_lines":[6,7],"explanation":"Untrusted text is interpolated into an XPath expression.","patch_summary":"Bind the value as an XPath variable instead of constructing expression text.","safe_test":"def test_lxml_xpath_injection_c5e74c34_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_lxml_xpath_injection_9793_19)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-20dff58c04ef6d79","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_8595_27 = \"defensive\"\n\ndef apply_insecure_temp_file_8595_27(payload_8595_27, policy_8595_27):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_8595_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_8595_27}.txt\")\n path.write_text(policy_8595_27, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_8595_27 = \"defensive\"\n\ndef apply_insecure_temp_file_8595_27(payload_8595_27, policy_8595_27):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_8595_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_8595_27)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_20dff58c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_8595_27)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-d01fdb96766329a1","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_SSRF_3718_21 = \"defensive\"\n\ndef process_ssrf_3718_21(request_3718_21, policy_3718_21):\n if HANDLER_KIND_PROCESS_SSRF_3718_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_3718_21, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_SSRF_3718_21 = \"defensive\"\n\ndef process_ssrf_3718_21(request_3718_21, policy_3718_21):\n if HANDLER_KIND_PROCESS_SSRF_3718_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_3718_21)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_3718_21):\n raise ValueError(\"destination is not allowed\")\n return requests.get(request_3718_21, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_d01fdb96_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ssrf_3718_21)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-d7bb485b0eb928d5","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9000_24 = \"defensive\"\n\ndef handle_plaintext_password_storage_9000_24(request_9000_24, target_9000_24, limit_9000_24):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9000_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_9000_24).write_text(target_9000_24, encoding=\"utf-8\")\n return Path(request_9000_24)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9000_24 = \"defensive\"\n\ndef handle_plaintext_password_storage_9000_24(request_9000_24, target_9000_24, limit_9000_24):\n if HANDLER_KIND_HANDLE_PLAINTEXT_PASSWORD_STORAGE_9000_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_9000_24) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_9000_24.encode(\"utf-8\"), limit_9000_24, 240_000).hex()\n Path(request_9000_24).write_text(verifier, encoding=\"ascii\")\n return Path(request_9000_24)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_d7bb485b_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_plaintext_password_storage_9000_24)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-b42998348e5b8911","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_6209_3 = \"defensive\"\n\ndef load_http_response_splitting_6209_3(subject_6209_3, policy_6209_3):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_6209_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_6209_3.headers[\"X-Next\"] = policy_6209_3\n return subject_6209_3\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_6209_3 = \"defensive\"\n\ndef load_http_response_splitting_6209_3(subject_6209_3, policy_6209_3):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_6209_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in policy_6209_3 or \"\\n\" in policy_6209_3:\n raise ValueError(\"invalid header value\")\n subject_6209_3.headers[\"X-Next\"] = policy_6209_3\n return subject_6209_3\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_b4299834_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_6209_3)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-9e9a4071f621c458","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_3579_18 = \"defensive\"\n\ndef resolve_log_injection_3579_18(value_3579_18, policy_3579_18):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_3579_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_3579_18.warning(\"audit=%s\", policy_3579_18)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_3579_18 = \"defensive\"\n\ndef resolve_log_injection_3579_18(value_3579_18, policy_3579_18):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_3579_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_3579_18).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_3579_18.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_9e9a4071_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_3579_18)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-6e76925d5c9ebcc9","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_7144_18 = \"defensive\"\n\ndef load_requests_tls_verification_7144_18(subject_7144_18):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_7144_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_7144_18, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_7144_18 = \"defensive\"\n\ndef load_requests_tls_verification_7144_18(subject_7144_18):\n if HANDLER_KIND_LOAD_REQUESTS_TLS_VERIFICATION_7144_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_7144_18, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_6e76925d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_requests_tls_verification_7144_18)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-66ebf90e766bfba8","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2514_11 = \"defensive\"\n\ndef process_hardcoded_credentials_2514_11(request_2514_11):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2514_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2514_11)}\n","fixed_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2514_11 = \"defensive\"\n\ndef process_hardcoded_credentials_2514_11(request_2514_11):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_2514_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_2514_11)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_66ebf90e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_hardcoded_credentials_2514_11)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-4c54d9beca3bd01f","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3319_5 = \"defensive\"\n\ndef process_fastapi_upload_validation_3319_5(payload_3319_5):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3319_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_3319_5.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_3319_5.size is None or payload_3319_5.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_3319_5.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3319_5 = \"defensive\"\n\ndef process_fastapi_upload_validation_3319_5(payload_3319_5):\n if HANDLER_KIND_PROCESS_FASTAPI_UPLOAD_VALIDATION_3319_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_3319_5.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_3319_5.size is None or payload_3319_5.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_3319_5.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_4c54d9be_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_upload_validation_3319_5)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-d3f788fad2970cc0","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_9544_26 = \"defensive\"\n\ndef resolve_hardcoded_credentials_9544_26(value_9544_26):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_9544_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_9544_26)}\n","fixed_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_9544_26 = \"defensive\"\n\ndef resolve_hardcoded_credentials_9544_26(value_9544_26):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_9544_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(value_9544_26)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_d3f788fa_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_hardcoded_credentials_9544_26)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-2b731e65b628078a","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2231_7 = \"defensive\"\n\ndef load_zip_decompression_bomb_2231_7(request_2231_7, policy_2231_7):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2231_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_2231_7.extractall(policy_2231_7)\n return policy_2231_7\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2231_7 = \"defensive\"\n\ndef load_zip_decompression_bomb_2231_7(request_2231_7, policy_2231_7):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2231_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_2231_7.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_2231_7.extractall(policy_2231_7)\n return policy_2231_7\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_2b731e65_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_2231_7)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-c18ffd1eab1bd43e","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_1747_1 = \"defensive\"\n\ndef process_flask_csrf_validation_1747_1(request_1747_1, context_1747_1):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_1747_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_1747_1.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_1747_1 = \"defensive\"\n\ndef process_flask_csrf_validation_1747_1(request_1747_1, context_1747_1):\n if HANDLER_KIND_PROCESS_FLASK_CSRF_VALIDATION_1747_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = request_1747_1.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_1747_1.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return request_1747_1.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_c18ffd1e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_csrf_validation_1747_1)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-c50fdf02f7d3fd32","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9930_27 = \"defensive\"\n\ndef handle_flask_session_fixation_9930_27(payload_9930_27, context_9930_27):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9930_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9930_27[\"user_id\"] = context_9930_27.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9930_27 = \"defensive\"\n\ndef handle_flask_session_fixation_9930_27(payload_9930_27, context_9930_27):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_9930_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_9930_27.clear()\n payload_9930_27[\"user_id\"] = context_9930_27.id\n payload_9930_27[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_c50fdf02_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_9930_27)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-2b6bc35d279240ea","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_8190_23 = \"defensive\"\n\ndef apply_sql_injection_8190_23(subject_8190_23, target_8190_23):\n if HANDLER_KIND_APPLY_SQL_INJECTION_8190_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8190_23.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_8190_23,)).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_8190_23 = \"defensive\"\n\ndef apply_sql_injection_8190_23(subject_8190_23, target_8190_23):\n if HANDLER_KIND_APPLY_SQL_INJECTION_8190_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8190_23.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (target_8190_23,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_2b6bc35d_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_8190_23)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-9cacbc1330bf27a4","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_2533_28 = \"defensive\"\n\ndef process_http_response_splitting_2533_28(payload_2533_28, scope_2533_28):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_2533_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_2533_28.headers[\"X-Next\"] = scope_2533_28\n return payload_2533_28\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_2533_28 = \"defensive\"\n\ndef process_http_response_splitting_2533_28(payload_2533_28, scope_2533_28):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_2533_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_2533_28 or \"\\n\" in scope_2533_28:\n raise ValueError(\"invalid header value\")\n payload_2533_28.headers[\"X-Next\"] = scope_2533_28\n return payload_2533_28\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_9cacbc13_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_2533_28)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-9eb5d8a045474635","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8867_28 = \"defensive\"\n\ndef apply_missing_authorization_8867_28(value_8867_28, policy_8867_28):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8867_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n policy_8867_28.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8867_28 = \"defensive\"\n\ndef apply_missing_authorization_8867_28(value_8867_28, policy_8867_28):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_8867_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if value_8867_28.id != policy_8867_28.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_8867_28.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_9eb5d8a0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_8867_28)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-4759d5038644e2ea","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_1871_11 = \"defensive\"\n\ndef handle_missing_authorization_1871_11(subject_1871_11, scope_1871_11):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_1871_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1871_11.id != scope_1871_11.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1871_11.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_1871_11 = \"defensive\"\n\ndef handle_missing_authorization_1871_11(subject_1871_11, scope_1871_11):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_1871_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1871_11.id != scope_1871_11.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_1871_11.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_4759d503_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_1871_11)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-79455237d921f3a0","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1201_28 = \"defensive\"\n\ndef process_log_injection_1201_28(value_1201_28, target_1201_28):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1201_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_1201_28.warning(\"audit=%s\", target_1201_28)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_LOG_INJECTION_1201_28 = \"defensive\"\n\ndef process_log_injection_1201_28(value_1201_28, target_1201_28):\n if HANDLER_KIND_PROCESS_LOG_INJECTION_1201_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_1201_28).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_1201_28.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_79455237_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_log_injection_1201_28)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-12152e1cbb77b8af","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_3366_28 = \"defensive\"\n\ndef handle_hardcoded_credentials_3366_28(request_3366_28):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_3366_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000028\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_3366_28)}\n","fixed_code":"import os\n\nHANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_3366_28 = \"defensive\"\n\ndef handle_hardcoded_credentials_3366_28(request_3366_28):\n if HANDLER_KIND_HANDLE_HARDCODED_CREDENTIALS_3366_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_3366_28)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_12152e1c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_hardcoded_credentials_3366_28)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-0109f448d1e3896e","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_8548_18 = \"defensive\"\n\ndef apply_httpx_client_ssrf_8548_18(subject_8548_18, scope_8548_18, owner_8548_18):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_8548_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8548_18.get(scope_8548_18, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_8548_18 = \"defensive\"\n\ndef apply_httpx_client_ssrf_8548_18(subject_8548_18, scope_8548_18, owner_8548_18):\n if HANDLER_KIND_APPLY_HTTPX_CLIENT_SSRF_8548_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_8548_18)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_8548_18):\n raise ValueError(\"destination is not allowed\")\n return subject_8548_18.get(scope_8548_18, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_0109f448_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_httpx_client_ssrf_8548_18)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-62f177dbff2d7097","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_6765_20 = \"defensive\"\n\ndef process_command_injection_6765_20(request_6765_20, scope_6765_20):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_6765_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_6765_20, scope_6765_20], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_6765_20 = \"defensive\"\n\ndef process_command_injection_6765_20(request_6765_20, scope_6765_20):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_6765_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_6765_20, scope_6765_20], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_62f177db_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_6765_20)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-678f6d4f53ff7d34","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5789_1 = \"defensive\"\n\ndef handle_http_response_splitting_5789_1(subject_5789_1, context_5789_1):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5789_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5789_1.headers[\"X-Next\"] = context_5789_1\n return subject_5789_1\n","fixed_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5789_1 = \"defensive\"\n\ndef handle_http_response_splitting_5789_1(subject_5789_1, context_5789_1):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_5789_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_5789_1 or \"\\n\" in context_5789_1:\n raise ValueError(\"invalid header value\")\n subject_5789_1.headers[\"X-Next\"] = context_5789_1\n return subject_5789_1\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_678f6d4f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_http_response_splitting_5789_1)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-3ef658e1f81ff02e","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9846_21 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9846_21(request_9846_21):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9846_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_9846_21, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9846_21 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_9846_21(request_9846_21):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_9846_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9846_21)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_3ef658e1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_9846_21)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-da8368e371e9031c","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6139_14 = \"defensive\"\n\ndef apply_requests_tls_verification_6139_14(payload_6139_14):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6139_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6139_14, verify=True, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6139_14 = \"defensive\"\n\ndef apply_requests_tls_verification_6139_14(payload_6139_14):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_6139_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_6139_14, verify=True, timeout=10)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-295: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_requests_tls_verification_da8368e3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_6139_14)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-3d8a32db2eba0bd9","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_3121_3 = \"defensive\"\n\ndef process_unsafe_deserialization_3121_3(subject_3121_3):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_3121_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(subject_3121_3)\n","fixed_code":"import json\n\nHANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_3121_3 = \"defensive\"\n\ndef process_unsafe_deserialization_3121_3(subject_3121_3):\n if HANDLER_KIND_PROCESS_UNSAFE_DESERIALIZATION_3121_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_3121_3.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_3d8a32db_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_unsafe_deserialization_3121_3)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-ec7efd0c4993f23e","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5848_15 = \"defensive\"\n\ndef apply_django_safe_string_xss_5848_15(request_5848_15):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5848_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{request_5848_15}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5848_15 = \"defensive\"\n\ndef apply_django_safe_string_xss_5848_15(request_5848_15):\n if HANDLER_KIND_APPLY_DJANGO_SAFE_STRING_XSS_5848_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_5848_15)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_ec7efd0c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_safe_string_xss_5848_15)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-254cfd5837d8eeb2","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_5885_20 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_5885_20(payload_5885_20, policy_5885_20):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_5885_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_5885_20.execute(statement, {\"account_id\": policy_5885_20}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_5885_20 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_5885_20(payload_5885_20, policy_5885_20):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_5885_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_5885_20.execute(statement, {\"account_id\": policy_5885_20}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_254cfd58_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_5885_20)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-f51dbdc7004d5d9d","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5807_3 = \"defensive\"\n\ndef apply_missing_authorization_5807_3(request_5807_3, context_5807_3):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5807_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_5807_3.delete()\n return True\n","fixed_code":"HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5807_3 = \"defensive\"\n\ndef apply_missing_authorization_5807_3(request_5807_3, context_5807_3):\n if HANDLER_KIND_APPLY_MISSING_AUTHORIZATION_5807_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_5807_3.id != context_5807_3.owner_id:\n raise PermissionError(\"record ownership required\")\n context_5807_3.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_f51dbdc7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_missing_authorization_5807_3)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-cf17b8b5c2a78072","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2245_11 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2245_11(request_2245_11, scope_2245_11):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2245_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_2245_11 is None or not request_2245_11.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_2245_11.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2245_11 = \"defensive\"\n\ndef resolve_fastapi_missing_authentication_2245_11(request_2245_11, scope_2245_11):\n if HANDLER_KIND_RESOLVE_FASTAPI_MISSING_AUTHENTICATION_2245_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_2245_11 is None or not request_2245_11.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_2245_11.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_cf17b8b5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_missing_authentication_2245_11)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-31a3f9d3507223d6","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_2964_22 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_2964_22(payload_2964_22, policy_2964_22, owner_2964_22):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_2964_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_2964_22, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_2964_22 = \"defensive\"\n\ndef apply_pyjwt_signature_bypass_2964_22(payload_2964_22, policy_2964_22, owner_2964_22):\n if HANDLER_KIND_APPLY_PYJWT_SIGNATURE_BYPASS_2964_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(payload_2964_22, policy_2964_22, algorithms=[\"HS256\"], audience=owner_2964_22)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_31a3f9d3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyjwt_signature_bypass_2964_22)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-f925a7ffd9b4da2d","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3484_26 = \"defensive\"\n\ndef load_weak_cryptography_3484_26(payload_3484_26, context_3484_26):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3484_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_3484_26.encode(\"utf-8\"), context_3484_26, 210000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3484_26 = \"defensive\"\n\ndef load_weak_cryptography_3484_26(payload_3484_26, context_3484_26):\n if HANDLER_KIND_LOAD_WEAK_CRYPTOGRAPHY_3484_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_3484_26.encode(\"utf-8\"), context_3484_26, 210000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_f925a7ff_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_weak_cryptography_3484_26)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-f778064d4f0b8041","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_3938_9 = \"defensive\"\n\ndef resolve_http_response_splitting_3938_9(request_3938_9, scope_3938_9):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_3938_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3938_9.headers[\"X-Next\"] = scope_3938_9\n return request_3938_9\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_3938_9 = \"defensive\"\n\ndef resolve_http_response_splitting_3938_9(request_3938_9, scope_3938_9):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_3938_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_3938_9 or \"\\n\" in scope_3938_9:\n raise ValueError(\"invalid header value\")\n request_3938_9.headers[\"X-Next\"] = scope_3938_9\n return request_3938_9\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_f778064d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_3938_9)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-6346aed2bfb374ad","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_SSRF_1106_23 = \"defensive\"\n\ndef resolve_ssrf_1106_23(payload_1106_23, policy_1106_23):\n if HANDLER_KIND_RESOLVE_SSRF_1106_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_1106_23)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_1106_23):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_1106_23, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_SSRF_1106_23 = \"defensive\"\n\ndef resolve_ssrf_1106_23(payload_1106_23, policy_1106_23):\n if HANDLER_KIND_RESOLVE_SSRF_1106_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_1106_23)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_1106_23):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_1106_23, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_6346aed2_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ssrf_1106_23)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-afe49333a5a68c35","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_3427_9 = \"defensive\"\n\ndef process_sensitive_data_exposure_3427_9(subject_3427_9, policy_3427_9, options_3427_9):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_3427_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_3427_9.info(\"login user=%s password=%s\", policy_3427_9, options_3427_9)\n return True\n","fixed_code":"HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_3427_9 = \"defensive\"\n\ndef process_sensitive_data_exposure_3427_9(subject_3427_9, policy_3427_9, options_3427_9):\n if HANDLER_KIND_PROCESS_SENSITIVE_DATA_EXPOSURE_3427_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_3427_9.info(\"login user=%s\", policy_3427_9)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_afe49333_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sensitive_data_exposure_3427_9)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-90aa5713e38b287e","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_8133_7 = \"defensive\"\n\ndef apply_sql_injection_8133_7(payload_8133_7, context_8133_7):\n if HANDLER_KIND_APPLY_SQL_INJECTION_8133_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {context_8133_7}\"\n return payload_8133_7.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_8133_7 = \"defensive\"\n\ndef apply_sql_injection_8133_7(payload_8133_7, context_8133_7):\n if HANDLER_KIND_APPLY_SQL_INJECTION_8133_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_8133_7.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (context_8133_7,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_90aa5713_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_8133_7)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-5d4e90ca4c7e1a54","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_8131_4 = \"defensive\"\n\ndef load_missing_authorization_8131_4(payload_8131_4, policy_8131_4):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_8131_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n policy_8131_4.delete()\n return True\n","fixed_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_8131_4 = \"defensive\"\n\ndef load_missing_authorization_8131_4(payload_8131_4, policy_8131_4):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_8131_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if payload_8131_4.id != policy_8131_4.owner_id:\n raise PermissionError(\"record ownership required\")\n policy_8131_4.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_5d4e90ca_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_missing_authorization_8131_4)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-0e60ee0f66cb82c8","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_6484_8 = \"defensive\"\n\ndef handle_insecure_file_permissions_6484_8(request_6484_8, target_6484_8):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_6484_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_6484_8).write_text(target_6484_8, encoding=\"utf-8\")\n os.chmod(request_6484_8, 0o600)\n return Path(request_6484_8)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_6484_8 = \"defensive\"\n\ndef handle_insecure_file_permissions_6484_8(request_6484_8, target_6484_8):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_6484_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_6484_8).write_text(target_6484_8, encoding=\"utf-8\")\n os.chmod(request_6484_8, 0o600)\n return Path(request_6484_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-276: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_file_permissions_0e60ee0f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_6484_8)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-ea592947aa53723a","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7724_14 = \"defensive\"\n\ndef resolve_insecure_temp_file_7724_14(request_7724_14, policy_7724_14):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7724_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_7724_14)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7724_14 = \"defensive\"\n\ndef resolve_insecure_temp_file_7724_14(request_7724_14, policy_7724_14):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_7724_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_7724_14)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_ea592947_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_7724_14)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-643-d6e2f0ad08b82d61","family":"cwe-643-lxml_xpath_injection-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-643","vuln_type":"XPath injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7965_14 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7965_14(subject_7965_14, policy_7965_14):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7965_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7965_14.xpath(\"//user[@name=$account]\", account=policy_7965_14)\n","fixed_code":"HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7965_14 = \"defensive\"\n\ndef apply_lxml_xpath_injection_7965_14(subject_7965_14, policy_7965_14):\n if HANDLER_KIND_APPLY_LXML_XPATH_INJECTION_7965_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7965_14.xpath(\"//user[@name=$account]\", account=policy_7965_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-643: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_xpath_injection_d6e2f0ad_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_xpath_injection_7965_14)\n assert 'xpath = f' not in source\n assert '$account' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-e3bb8e954b39e462","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2956_0 = \"defensive\"\n\ndef process_dynamic_code_injection_2956_0(request_2956_0):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2956_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_2956_0, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2956_0 = \"defensive\"\n\ndef process_dynamic_code_injection_2956_0(request_2956_0):\n if HANDLER_KIND_PROCESS_DYNAMIC_CODE_INJECTION_2956_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_2956_0) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_2956_0)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_e3bb8e95_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_dynamic_code_injection_2956_0)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-cad7ebc1252d93fa","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7119_20 = \"defensive\"\n\ndef process_http_response_splitting_7119_20(payload_7119_20, target_7119_20):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7119_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_7119_20 or \"\\n\" in target_7119_20:\n raise ValueError(\"invalid header value\")\n payload_7119_20.headers[\"X-Next\"] = target_7119_20\n return payload_7119_20\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7119_20 = \"defensive\"\n\ndef process_http_response_splitting_7119_20(payload_7119_20, target_7119_20):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7119_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in target_7119_20 or \"\\n\" in target_7119_20:\n raise ValueError(\"invalid header value\")\n payload_7119_20.headers[\"X-Next\"] = target_7119_20\n return payload_7119_20\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_cad7ebc1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_7119_20)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-599db2026e710ed1","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_2948_7 = \"defensive\"\n\ndef apply_unsafe_deserialization_2948_7(request_2948_7):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_2948_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(request_2948_7)\n","fixed_code":"import json\n\nHANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_2948_7 = \"defensive\"\n\ndef apply_unsafe_deserialization_2948_7(request_2948_7):\n if HANDLER_KIND_APPLY_UNSAFE_DESERIALIZATION_2948_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_2948_7.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_599db202_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_unsafe_deserialization_2948_7)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-0ab5ec1a6ce01e6c","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_7499_14 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_7499_14(subject_7499_14, scope_7499_14):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_7499_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_7499_14.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_7499_14.extractall(scope_7499_14)\n return scope_7499_14\n","fixed_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_7499_14 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_7499_14(subject_7499_14, scope_7499_14):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_7499_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = subject_7499_14.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n subject_7499_14.extractall(scope_7499_14)\n return scope_7499_14\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_0ab5ec1a_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_zip_decompression_bomb_7499_14)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-a490d4dc1b79ad8e","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_4750_11 = \"defensive\"\n\ndef handle_command_injection_4750_11(request_4750_11, target_4750_11):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_4750_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_4750_11, target_4750_11], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_HANDLE_COMMAND_INJECTION_4750_11 = \"defensive\"\n\ndef handle_command_injection_4750_11(request_4750_11, target_4750_11):\n if HANDLER_KIND_HANDLE_COMMAND_INJECTION_4750_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_4750_11, target_4750_11], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_a490d4dc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_command_injection_4750_11)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-086dc8c0743eeec2","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_5107_1 = \"defensive\"\n\ndef resolve_flask_session_fixation_5107_1(value_5107_1, target_5107_1):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_5107_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5107_1[\"user_id\"] = target_5107_1.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_5107_1 = \"defensive\"\n\ndef resolve_flask_session_fixation_5107_1(value_5107_1, target_5107_1):\n if HANDLER_KIND_RESOLVE_FLASK_SESSION_FIXATION_5107_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5107_1.clear()\n value_5107_1[\"user_id\"] = target_5107_1.id\n value_5107_1[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_086dc8c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_session_fixation_5107_1)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-43750abbd9185e10","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":false,"vulnerable_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6395_20 = \"defensive\"\n\ndef apply_insecure_random_token_6395_20(subject_6395_20):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6395_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_6395_20)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6395_20 = \"defensive\"\n\ndef apply_insecure_random_token_6395_20(subject_6395_20):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_6395_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_6395_20)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-330: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_random_token_43750abb_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_6395_20)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-0a32ec4ee5a9007e","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_3669_12 = \"defensive\"\n\ndef apply_path_traversal_3669_12(payload_3669_12, context_3669_12):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_3669_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(payload_3669_12) / context_3669_12).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_3669_12 = \"defensive\"\n\ndef apply_path_traversal_3669_12(payload_3669_12, context_3669_12):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_3669_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_3669_12).resolve()\n candidate = (root / context_3669_12).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_0a32ec4e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_3669_12)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-350db7b3d0292613","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_6222_0 = \"defensive\"\n\ndef apply_zip_decompression_bomb_6222_0(payload_6222_0, context_6222_0):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_6222_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_6222_0.extractall(context_6222_0)\n return context_6222_0\n","fixed_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_6222_0 = \"defensive\"\n\ndef apply_zip_decompression_bomb_6222_0(payload_6222_0, context_6222_0):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_6222_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_6222_0.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_6222_0.extractall(context_6222_0)\n return context_6222_0\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_350db7b3_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_zip_decompression_bomb_6222_0)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4a31157890cdcbf6","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_7217_29 = \"defensive\"\n\ndef apply_path_traversal_7217_29(payload_7217_29, policy_7217_29):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_7217_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_7217_29).resolve()\n candidate = (root / policy_7217_29).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_7217_29 = \"defensive\"\n\ndef apply_path_traversal_7217_29(payload_7217_29, policy_7217_29):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_7217_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(payload_7217_29).resolve()\n candidate = (root / policy_7217_29).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_4a311578_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_7217_29)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-70dc6003db437f38","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_5373_6 = \"defensive\"\n\ndef apply_path_traversal_5373_6(value_5373_6, target_5373_6):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_5373_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_5373_6) / target_5373_6).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_5373_6 = \"defensive\"\n\ndef apply_path_traversal_5373_6(value_5373_6, target_5373_6):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_5373_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_5373_6).resolve()\n candidate = (root / target_5373_6).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_70dc6003_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_5373_6)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-9d4f171eabb19d0b","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":false,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2393_23 = \"defensive\"\n\ndef handle_lxml_external_entity_2393_23(value_2393_23):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2393_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_2393_23, parser=parser)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2393_23 = \"defensive\"\n\ndef handle_lxml_external_entity_2393_23(value_2393_23):\n if HANDLER_KIND_HANDLE_LXML_EXTERNAL_ENTITY_2393_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_2393_23, parser=parser)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-611: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_lxml_external_entity_9d4f171e_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_lxml_external_entity_2393_23)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-8c11e1f59688ad66","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3104_9 = \"defensive\"\n\ndef process_httpx_client_ssrf_3104_9(value_3104_9, policy_3104_9, owner_3104_9):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3104_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_3104_9.get(policy_3104_9, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3104_9 = \"defensive\"\n\ndef process_httpx_client_ssrf_3104_9(value_3104_9, policy_3104_9, owner_3104_9):\n if HANDLER_KIND_PROCESS_HTTPX_CLIENT_SSRF_3104_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_3104_9)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_3104_9):\n raise ValueError(\"destination is not allowed\")\n return value_3104_9.get(policy_3104_9, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_8c11e1f5_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_httpx_client_ssrf_3104_9)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-a2add41ed0b4e763","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_9119_14 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_9119_14(request_9119_14):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_9119_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9119_14)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_9119_14 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_9119_14(request_9119_14):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_9119_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_9119_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_a2add41e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_9119_14)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-80bcc6d707b0e3fa","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2714_21 = \"defensive\"\n\ndef load_lxml_external_entity_2714_21(payload_2714_21):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2714_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(payload_2714_21)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2714_21 = \"defensive\"\n\ndef load_lxml_external_entity_2714_21(payload_2714_21):\n if HANDLER_KIND_LOAD_LXML_EXTERNAL_ENTITY_2714_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(payload_2714_21, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_80bcc6d7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_lxml_external_entity_2714_21)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-cb749d4c26cc4625","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_7287_3 = \"defensive\"\n\ndef resolve_weak_cryptography_7287_3(payload_7287_3, context_7287_3):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_7287_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(payload_7287_3.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_7287_3 = \"defensive\"\n\ndef resolve_weak_cryptography_7287_3(payload_7287_3, context_7287_3):\n if HANDLER_KIND_RESOLVE_WEAK_CRYPTOGRAPHY_7287_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", payload_7287_3.encode(\"utf-8\"), context_7287_3, 230000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_cb749d4c_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_weak_cryptography_7287_3)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-4a5c7036eca35266","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_4729_1 = \"defensive\"\n\ndef resolve_hardcoded_credentials_4729_1(subject_4729_1):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_4729_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000001\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4729_1)}\n","fixed_code":"import os\n\nHANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_4729_1 = \"defensive\"\n\ndef resolve_hardcoded_credentials_4729_1(subject_4729_1):\n if HANDLER_KIND_RESOLVE_HARDCODED_CREDENTIALS_4729_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4729_1)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_4a5c7036_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_hardcoded_credentials_4729_1)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-ac06a27a731fd2aa","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_SSRF_3311_16 = \"defensive\"\n\ndef load_ssrf_3311_16(payload_3311_16, target_3311_16):\n if HANDLER_KIND_LOAD_SSRF_3311_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_3311_16, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_SSRF_3311_16 = \"defensive\"\n\ndef load_ssrf_3311_16(payload_3311_16, target_3311_16):\n if HANDLER_KIND_LOAD_SSRF_3311_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_3311_16)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_3311_16):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_3311_16, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_ac06a27a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ssrf_3311_16)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-67bd3dcda2febd51","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_6194_20 = \"defensive\"\n\ndef resolve_django_error_details_6194_20(request_6194_20, context_6194_20):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_6194_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_6194_20()\n except Exception:\n request_6194_20.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_6194_20 = \"defensive\"\n\ndef resolve_django_error_details_6194_20(request_6194_20, context_6194_20):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_6194_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_6194_20()\n except Exception:\n request_6194_20.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_67bd3dcd_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_6194_20)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-cf907194581962a2","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3724_23 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_3724_23(subject_3724_23, scope_3724_23, options_3724_23):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3724_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_3724_23, scope_3724_23, algorithms=[\"HS256\"], audience=options_3724_23)\n","fixed_code":"import jwt\n\nHANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3724_23 = \"defensive\"\n\ndef process_pyjwt_signature_bypass_3724_23(subject_3724_23, scope_3724_23, options_3724_23):\n if HANDLER_KIND_PROCESS_PYJWT_SIGNATURE_BYPASS_3724_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_3724_23, scope_3724_23, algorithms=[\"HS256\"], audience=options_3724_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_cf907194_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyjwt_signature_bypass_3724_23)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-3c2213f4c8d0a1b8","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":false,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2663_23 = \"defensive\"\n\ndef process_command_injection_2663_23(payload_2663_23, target_2663_23):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2663_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_2663_23, target_2663_23], check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_PROCESS_COMMAND_INJECTION_2663_23 = \"defensive\"\n\ndef process_command_injection_2663_23(payload_2663_23, target_2663_23):\n if HANDLER_KIND_PROCESS_COMMAND_INJECTION_2663_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", payload_2663_23, target_2663_23], check=True, capture_output=True)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-078: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_command_injection_3c2213f4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_command_injection_2663_23)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-522daa3da75a9c46","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5585_14 = \"defensive\"\n\ndef load_sensitive_data_exposure_5585_14(payload_5585_14, context_5585_14, options_5585_14):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5585_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5585_14.info(\"login user=%s\", context_5585_14)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5585_14 = \"defensive\"\n\ndef load_sensitive_data_exposure_5585_14(payload_5585_14, context_5585_14, options_5585_14):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_5585_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5585_14.info(\"login user=%s\", context_5585_14)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-200: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sensitive_data_exposure_522daa3d_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_5585_14)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-f7a1d8475df36f17","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_SSRF_7346_4 = \"defensive\"\n\ndef apply_ssrf_7346_4(payload_7346_4, context_7346_4):\n if HANDLER_KIND_APPLY_SSRF_7346_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(payload_7346_4, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_7346_4 = \"defensive\"\n\ndef apply_ssrf_7346_4(payload_7346_4, context_7346_4):\n if HANDLER_KIND_APPLY_SSRF_7346_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_7346_4)\n if parsed.scheme != \"https\" or parsed.hostname not in set(context_7346_4):\n raise ValueError(\"destination is not allowed\")\n return requests.get(payload_7346_4, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_f7a1d847_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_7346_4)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-7164e048c4c6cc3a","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_5225_27 = \"defensive\"\n\ndef resolve_flask_jinja_xss_5225_27(value_5225_27):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_5225_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_5225_27)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_5225_27 = \"defensive\"\n\ndef resolve_flask_jinja_xss_5225_27(value_5225_27):\n if HANDLER_KIND_RESOLVE_FLASK_JINJA_XSS_5225_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_5225_27)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_7164e048_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_jinja_xss_5225_27)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-700b23e619b2f906","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2779_28 = \"defensive\"\n\ndef load_zip_decompression_bomb_2779_28(value_2779_28, context_2779_28):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2779_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2779_28.extractall(context_2779_28)\n return context_2779_28\n","fixed_code":"HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2779_28 = \"defensive\"\n\ndef load_zip_decompression_bomb_2779_28(value_2779_28, context_2779_28):\n if HANDLER_KIND_LOAD_ZIP_DECOMPRESSION_BOMB_2779_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_2779_28.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_2779_28.extractall(context_2779_28)\n return context_2779_28\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_700b23e6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_zip_decompression_bomb_2779_28)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-9a34c717b8377ad8","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8927_25 = \"defensive\"\n\ndef apply_insecure_random_token_8927_25(payload_8927_25):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8927_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(payload_8927_25)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8927_25 = \"defensive\"\n\ndef apply_insecure_random_token_8927_25(payload_8927_25):\n if HANDLER_KIND_APPLY_INSECURE_RANDOM_TOKEN_8927_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(payload_8927_25)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_9a34c717_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_random_token_8927_25)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-329e0b719cca59a3","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_8395_18 = \"defensive\"\n\ndef handle_missing_authorization_8395_18(request_8395_18, scope_8395_18):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_8395_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n scope_8395_18.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_8395_18 = \"defensive\"\n\ndef handle_missing_authorization_8395_18(request_8395_18, scope_8395_18):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_8395_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_8395_18.id != scope_8395_18.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_8395_18.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_329e0b71_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_8395_18)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-f8024559e8305359","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_SSRF_8074_13 = \"defensive\"\n\ndef apply_ssrf_8074_13(subject_8074_13, scope_8074_13):\n if HANDLER_KIND_APPLY_SSRF_8074_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_8074_13, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_8074_13 = \"defensive\"\n\ndef apply_ssrf_8074_13(subject_8074_13, scope_8074_13):\n if HANDLER_KIND_APPLY_SSRF_8074_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_8074_13)\n if parsed.scheme != \"https\" or parsed.hostname not in set(scope_8074_13):\n raise ValueError(\"destination is not allowed\")\n return requests.get(subject_8074_13, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_f8024559_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_8074_13)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-5cd39ec717e5a08d","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_3765_19 = \"defensive\"\n\ndef load_flask_jinja_xss_3765_19(value_3765_19):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_3765_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(value_3765_19)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_LOAD_FLASK_JINJA_XSS_3765_19 = \"defensive\"\n\ndef load_flask_jinja_xss_3765_19(value_3765_19):\n if HANDLER_KIND_LOAD_FLASK_JINJA_XSS_3765_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(value_3765_19)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_5cd39ec7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_jinja_xss_3765_19)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-f92a4f64c199cb9e","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_8018_29 = \"defensive\"\n\ndef resolve_sql_injection_8018_29(subject_8018_29, policy_8018_29):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_8018_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8018_29.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_8018_29,)).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_8018_29 = \"defensive\"\n\ndef resolve_sql_injection_8018_29(subject_8018_29, policy_8018_29):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_8018_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8018_29.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_8018_29,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_f92a4f64_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_8018_29)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-d21137dd25d75c53","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6091_4 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_6091_4(value_6091_4, context_6091_4, allowed_6091_4):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6091_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_6091_4, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6091_4 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_6091_4(value_6091_4, context_6091_4, allowed_6091_4):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6091_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_6091_4, context_6091_4, algorithms=[\"HS256\"], audience=allowed_6091_4)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_d21137dd_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyjwt_signature_bypass_6091_4)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-7e81a827842e135b","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2345_15 = \"defensive\"\n\ndef apply_django_error_details_2345_15(subject_2345_15, policy_2345_15):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2345_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2345_15()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2345_15 = \"defensive\"\n\ndef apply_django_error_details_2345_15(subject_2345_15, policy_2345_15):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2345_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2345_15()\n except Exception:\n subject_2345_15.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_7e81a827_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_2345_15)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-c562e2b7cb6bf986","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3863_21 = \"defensive\"\n\ndef apply_starlette_permissive_cors_3863_21(subject_3863_21, policy_3863_21):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3863_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_3863_21.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return subject_3863_21\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3863_21 = \"defensive\"\n\ndef apply_starlette_permissive_cors_3863_21(subject_3863_21, policy_3863_21):\n if HANDLER_KIND_APPLY_STARLETTE_PERMISSIVE_CORS_3863_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(policy_3863_21)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n subject_3863_21.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return subject_3863_21\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_c562e2b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_starlette_permissive_cors_3863_21)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-fa4ce6a1084e14e9","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1927_13 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1927_13(payload_1927_13):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1927_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{payload_1927_13}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1927_13 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1927_13(payload_1927_13):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1927_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", payload_1927_13)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_fa4ce6a1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_1927_13)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-9fbd6a2599f3ade7","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_9295_23 = \"defensive\"\n\ndef resolve_django_safe_string_xss_9295_23(request_9295_23):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_9295_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_9295_23)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_9295_23 = \"defensive\"\n\ndef resolve_django_safe_string_xss_9295_23(request_9295_23):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_9295_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_9295_23)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_9fbd6a25_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_9295_23)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-e3c0cdfcbc75ca14","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7227_17 = \"defensive\"\n\ndef apply_django_error_details_7227_17(subject_7227_17, target_7227_17):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7227_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7227_17()\n except Exception:\n subject_7227_17.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7227_17 = \"defensive\"\n\ndef apply_django_error_details_7227_17(subject_7227_17, target_7227_17):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_7227_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_7227_17()\n except Exception:\n subject_7227_17.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_e3c0cdfc_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_7227_17)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-031f5c4630561c69","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3015_26 = \"defensive\"\n\ndef apply_resource_consumption_3015_26(payload_3015_26, context_3015_26):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3015_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_3015_26), 1), 1_048_576)\n data = payload_3015_26.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3015_26 = \"defensive\"\n\ndef apply_resource_consumption_3015_26(payload_3015_26, context_3015_26):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3015_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_3015_26), 1), 1_048_576)\n data = payload_3015_26.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_031f5c46_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_3015_26)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-7980335c17b39d36","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_4896_5 = \"defensive\"\n\ndef handle_flask_open_redirect_4896_5(subject_4896_5):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_4896_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4896_5)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_4896_5)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_4896_5 = \"defensive\"\n\ndef handle_flask_open_redirect_4896_5(subject_4896_5):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_4896_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_4896_5)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_4896_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_7980335c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_4896_5)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-44826cd480a203c1","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_3544_9 = \"defensive\"\n\ndef load_missing_authorization_3544_9(subject_3544_9, context_3544_9):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_3544_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n context_3544_9.delete()\n return True\n","fixed_code":"HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_3544_9 = \"defensive\"\n\ndef load_missing_authorization_3544_9(subject_3544_9, context_3544_9):\n if HANDLER_KIND_LOAD_MISSING_AUTHORIZATION_3544_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_3544_9.id != context_3544_9.owner_id:\n raise PermissionError(\"record ownership required\")\n context_3544_9.delete()\n return True\n","vulnerable_lines":[6],"explanation":"A state-changing operation runs without checking ownership or authorization.","patch_summary":"Verify ownership before performing the state-changing operation.","safe_test":"def test_missing_authorization_44826cd4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_missing_authorization_3544_9)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-9ebb34f1c7afbd70","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_4832_22 = \"defensive\"\n\ndef load_ldap_filter_injection_4832_22(payload_4832_22, scope_4832_22):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_4832_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={scope_4832_22})\"\n return payload_4832_22.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_4832_22 = \"defensive\"\n\ndef load_ldap_filter_injection_4832_22(payload_4832_22, scope_4832_22):\n if HANDLER_KIND_LOAD_LDAP_FILTER_INJECTION_4832_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(scope_4832_22)\n query = f\"(uid={escaped})\"\n return payload_4832_22.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_9ebb34f1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_ldap_filter_injection_4832_22)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-d9ce82802a9f97b9","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_9037_3 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_9037_3(value_9037_3, scope_9037_3, options_9037_3):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_9037_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_9037_3, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_9037_3 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_9037_3(value_9037_3, scope_9037_3, options_9037_3):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_9037_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_9037_3, scope_9037_3, algorithms=[\"HS256\"], audience=options_9037_3)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_d9ce8280_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_9037_3)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-eacef25d2e355e18","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_6779_0 = \"defensive\"\n\ndef resolve_insecure_random_token_6779_0(subject_6779_0):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_6779_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(subject_6779_0)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_6779_0 = \"defensive\"\n\ndef resolve_insecure_random_token_6779_0(subject_6779_0):\n if HANDLER_KIND_RESOLVE_INSECURE_RANDOM_TOKEN_6779_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(subject_6779_0)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_eacef25d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_random_token_6779_0)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-e70d7cf5661b6f37","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3796_27 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3796_27(subject_3796_27):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3796_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3796_27.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3796_27 = \"defensive\"\n\ndef handle_fastapi_upload_validation_3796_27(subject_3796_27):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_3796_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_3796_27.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_3796_27.size is None or subject_3796_27.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_3796_27.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_e70d7cf5_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_3796_27)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-4a2280d18c583fba","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_7561_16 = \"defensive\"\n\ndef load_resource_consumption_7561_16(value_7561_16, policy_7561_16):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_7561_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7561_16.read(int(policy_7561_16))\n","fixed_code":"HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_7561_16 = \"defensive\"\n\ndef load_resource_consumption_7561_16(value_7561_16, policy_7561_16):\n if HANDLER_KIND_LOAD_RESOURCE_CONSUMPTION_7561_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_7561_16), 1), 1_048_576)\n data = value_7561_16.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_4a2280d1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_resource_consumption_7561_16)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-66df0d8436beafa8","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_4569_16 = \"defensive\"\n\ndef apply_regex_dos_4569_16(value_4569_16, target_4569_16):\n if HANDLER_KIND_APPLY_REGEX_DOS_4569_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(value_4569_16, target_4569_16) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_APPLY_REGEX_DOS_4569_16 = \"defensive\"\n\ndef apply_regex_dos_4569_16(value_4569_16, target_4569_16):\n if HANDLER_KIND_APPLY_REGEX_DOS_4569_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(value_4569_16) > 256 or len(target_4569_16) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(value_4569_16), target_4569_16) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_66df0d84_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_regex_dos_4569_16)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-626d6a519f4b2b18","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5690_12 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5690_12(payload_5690_12):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5690_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_5690_12.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5690_12 = \"defensive\"\n\ndef handle_fastapi_upload_validation_5690_12(payload_5690_12):\n if HANDLER_KIND_HANDLE_FASTAPI_UPLOAD_VALIDATION_5690_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_5690_12.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_5690_12.size is None or payload_5690_12.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_5690_12.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_626d6a51_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_upload_validation_5690_12)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-6bd30bc03bbd66fe","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":false,"vulnerable_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_5382_26 = \"defensive\"\n\ndef apply_ssrf_5382_26(value_5382_26, target_5382_26):\n if HANDLER_KIND_APPLY_SSRF_5382_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_5382_26)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_5382_26):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_5382_26, timeout=5, allow_redirects=False)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_SSRF_5382_26 = \"defensive\"\n\ndef apply_ssrf_5382_26(value_5382_26, target_5382_26):\n if HANDLER_KIND_APPLY_SSRF_5382_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(value_5382_26)\n if parsed.scheme != \"https\" or parsed.hostname not in set(target_5382_26):\n raise ValueError(\"destination is not allowed\")\n return requests.get(value_5382_26, timeout=5, allow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ssrf_6bd30bc0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_ssrf_5382_26)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-24bbc408e74175ac","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3030_24 = \"defensive\"\n\ndef apply_insecure_temp_file_3030_24(subject_3030_24, policy_3030_24):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3030_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{subject_3030_24}.txt\")\n path.write_text(policy_3030_24, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3030_24 = \"defensive\"\n\ndef apply_insecure_temp_file_3030_24(subject_3030_24, policy_3030_24):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3030_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_3030_24)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_24bbc408_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_3030_24)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-83a70ab1ff0f8195","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_1133_29 = \"defensive\"\n\ndef resolve_http_response_splitting_1133_29(subject_1133_29, context_1133_29):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_1133_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_1133_29 or \"\\n\" in context_1133_29:\n raise ValueError(\"invalid header value\")\n subject_1133_29.headers[\"X-Next\"] = context_1133_29\n return subject_1133_29\n","fixed_code":"HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_1133_29 = \"defensive\"\n\ndef resolve_http_response_splitting_1133_29(subject_1133_29, context_1133_29):\n if HANDLER_KIND_RESOLVE_HTTP_RESPONSE_SPLITTING_1133_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_1133_29 or \"\\n\" in context_1133_29:\n raise ValueError(\"invalid header value\")\n subject_1133_29.headers[\"X-Next\"] = context_1133_29\n return subject_1133_29\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-113: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_http_response_splitting_83a70ab1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_http_response_splitting_1133_29)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-a0c48d184b65c19c","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1730_23 = \"defensive\"\n\ndef resolve_log_injection_1730_23(subject_1730_23, scope_1730_23):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1730_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_1730_23).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_1730_23.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1730_23 = \"defensive\"\n\ndef resolve_log_injection_1730_23(subject_1730_23, scope_1730_23):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1730_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_1730_23).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_1730_23.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_a0c48d18_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_1730_23)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-c352ee6d0da74650","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8596_11 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_8596_11(subject_8596_11, scope_8596_11):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8596_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_8596_11.execute(statement, {\"account_id\": scope_8596_11}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8596_11 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_8596_11(subject_8596_11, scope_8596_11):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_8596_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_8596_11.execute(statement, {\"account_id\": scope_8596_11}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_c352ee6d_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sqlalchemy_text_injection_8596_11)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-289cf4f4492fd11d","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4064_15 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_4064_15(request_4064_15, scope_4064_15):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4064_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {scope_4064_15}\")\n return request_4064_15.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4064_15 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_4064_15(request_4064_15, scope_4064_15):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_4064_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return request_4064_15.execute(statement, {\"account_id\": scope_4064_15}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_289cf4f4_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_4064_15)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-1ea555caddef9fe6","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2205_19 = \"defensive\"\n\ndef resolve_django_error_details_2205_19(subject_2205_19, policy_2205_19):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2205_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2205_19()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2205_19 = \"defensive\"\n\ndef resolve_django_error_details_2205_19(subject_2205_19, policy_2205_19):\n if HANDLER_KIND_RESOLVE_DJANGO_ERROR_DETAILS_2205_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_2205_19()\n except Exception:\n subject_2205_19.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_1ea555ca_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_error_details_2205_19)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-7892f44dc545527e","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3755_3 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3755_3(payload_3755_3, scope_3755_3):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3755_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_3755_3.extractall(scope_3755_3)\n return scope_3755_3\n","fixed_code":"HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3755_3 = \"defensive\"\n\ndef handle_zip_decompression_bomb_3755_3(payload_3755_3, scope_3755_3):\n if HANDLER_KIND_HANDLE_ZIP_DECOMPRESSION_BOMB_3755_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_3755_3.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_3755_3.extractall(scope_3755_3)\n return scope_3755_3\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_7892f44d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_zip_decompression_bomb_3755_3)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-521f86b72668f9a8","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_9729_19 = \"defensive\"\n\ndef load_fastapi_upload_validation_9729_19(payload_9729_19):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_9729_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9729_19.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_9729_19 = \"defensive\"\n\ndef load_fastapi_upload_validation_9729_19(payload_9729_19):\n if HANDLER_KIND_LOAD_FASTAPI_UPLOAD_VALIDATION_9729_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if payload_9729_19.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if payload_9729_19.size is None or payload_9729_19.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(payload_9729_19.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_521f86b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_fastapi_upload_validation_9729_19)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-c46acdfc5bbd934d","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_1782_6 = \"defensive\"\n\ndef handle_mass_assignment_1782_6(request_1782_6, policy_1782_6):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_1782_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in policy_1782_6.items():\n setattr(request_1782_6, key, value)\n return request_1782_6\n","fixed_code":"HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_1782_6 = \"defensive\"\n\ndef handle_mass_assignment_1782_6(request_1782_6, policy_1782_6):\n if HANDLER_KIND_HANDLE_MASS_ASSIGNMENT_1782_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_1782_6.items() if key in allowed_fields}\n request_1782_6.update(safe)\n return request_1782_6\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_c46acdfc_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_mass_assignment_1782_6)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-fe7f3226289a711f","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_9625_1 = \"defensive\"\n\ndef resolve_resource_consumption_9625_1(value_9625_1, context_9625_1):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_9625_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9625_1.read(int(context_9625_1))\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_9625_1 = \"defensive\"\n\ndef resolve_resource_consumption_9625_1(value_9625_1, context_9625_1):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_9625_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_9625_1), 1), 1_048_576)\n data = value_9625_1.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_fe7f3226_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_9625_1)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-541dd32382e17de8","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7494_1 = \"defensive\"\n\ndef apply_fastapi_upload_validation_7494_1(subject_7494_1):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7494_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_7494_1.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7494_1 = \"defensive\"\n\ndef apply_fastapi_upload_validation_7494_1(subject_7494_1):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_7494_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_7494_1.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_7494_1.size is None or subject_7494_1.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_7494_1.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_541dd323_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_upload_validation_7494_1)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-c24889ae73e68948","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4908_12 = \"defensive\"\n\ndef apply_flask_session_fixation_4908_12(payload_4908_12, scope_4908_12):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4908_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4908_12[\"user_id\"] = scope_4908_12.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4908_12 = \"defensive\"\n\ndef apply_flask_session_fixation_4908_12(payload_4908_12, scope_4908_12):\n if HANDLER_KIND_APPLY_FLASK_SESSION_FIXATION_4908_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_4908_12.clear()\n payload_4908_12[\"user_id\"] = scope_4908_12.id\n payload_4908_12[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_c24889ae_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_session_fixation_4908_12)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-f575681ea5220ad5","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1245_12 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1245_12(request_1245_12):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1245_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{request_1245_12}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1245_12 = \"defensive\"\n\ndef resolve_django_safe_string_xss_1245_12(request_1245_12):\n if HANDLER_KIND_RESOLVE_DJANGO_SAFE_STRING_XSS_1245_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_1245_12)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_f575681e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_django_safe_string_xss_1245_12)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-73d22bba561d2c98","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_6129_20 = \"defensive\"\n\ndef process_django_safe_string_xss_6129_20(request_6129_20):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_6129_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_6129_20)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_6129_20 = \"defensive\"\n\ndef process_django_safe_string_xss_6129_20(request_6129_20):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_6129_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", request_6129_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_73d22bba_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_safe_string_xss_6129_20)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-e5fc7bd606418ec2","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_5894_27 = \"defensive\"\n\ndef load_httpx_client_ssrf_5894_27(subject_5894_27, target_5894_27, options_5894_27):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_5894_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_5894_27.get(target_5894_27, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_5894_27 = \"defensive\"\n\ndef load_httpx_client_ssrf_5894_27(subject_5894_27, target_5894_27, options_5894_27):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_5894_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(target_5894_27)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_5894_27):\n raise ValueError(\"destination is not allowed\")\n return subject_5894_27.get(target_5894_27, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_e5fc7bd6_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_5894_27)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-1489d597b31c8fd7","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3655_25 = \"defensive\"\n\ndef resolve_flask_open_redirect_3655_25(subject_3655_25):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3655_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(subject_3655_25)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3655_25 = \"defensive\"\n\ndef resolve_flask_open_redirect_3655_25(subject_3655_25):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_3655_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_3655_25)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_3655_25)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_1489d597_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_3655_25)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-c5c070f0d6878391","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_1501_16 = \"defensive\"\n\ndef handle_flask_session_fixation_1501_16(subject_1501_16, target_1501_16):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_1501_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1501_16[\"user_id\"] = target_1501_16.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_1501_16 = \"defensive\"\n\ndef handle_flask_session_fixation_1501_16(subject_1501_16, target_1501_16):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_1501_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1501_16.clear()\n subject_1501_16[\"user_id\"] = target_1501_16.id\n subject_1501_16[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_c5c070f0_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_1501_16)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-15c741bd218d49a2","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_1067_15 = \"defensive\"\n\ndef process_ldap_filter_injection_1067_15(subject_1067_15, policy_1067_15):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_1067_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={policy_1067_15})\"\n return subject_1067_15.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_1067_15 = \"defensive\"\n\ndef process_ldap_filter_injection_1067_15(subject_1067_15, policy_1067_15):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_1067_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_1067_15)\n query = f\"(uid={escaped})\"\n return subject_1067_15.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_15c741bd_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ldap_filter_injection_1067_15)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-48304b9f05b83729","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8998_14 = \"defensive\"\n\ndef handle_path_traversal_8998_14(subject_8998_14, context_8998_14):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8998_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8998_14).resolve()\n candidate = (root / context_8998_14).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_HANDLE_PATH_TRAVERSAL_8998_14 = \"defensive\"\n\ndef handle_path_traversal_8998_14(subject_8998_14, context_8998_14):\n if HANDLER_KIND_HANDLE_PATH_TRAVERSAL_8998_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8998_14).resolve()\n candidate = (root / context_8998_14).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_48304b9f_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_path_traversal_8998_14)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-d6b1cbbb8e52f99b","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8388_19 = \"defensive\"\n\ndef load_cleartext_http_transport_8388_19(payload_8388_19):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8388_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_8388_19, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8388_19 = \"defensive\"\n\ndef load_cleartext_http_transport_8388_19(payload_8388_19):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_8388_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_8388_19, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_d6b1cbbb_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_8388_19)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-40ea95b75d70c942","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4298_10 = \"defensive\"\n\ndef apply_requests_tls_verification_4298_10(request_4298_10):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4298_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_4298_10, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4298_10 = \"defensive\"\n\ndef apply_requests_tls_verification_4298_10(request_4298_10):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_4298_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_4298_10, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_40ea95b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_4298_10)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-3a2c20ddab15aa05","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8020_2 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_8020_2(value_8020_2, context_8020_2):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8020_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_8020_2.execute(statement, {\"account_id\": context_8020_2}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8020_2 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_8020_2(value_8020_2, context_8020_2):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_8020_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_8020_2.execute(statement, {\"account_id\": context_8020_2}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_3a2c20dd_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_8020_2)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-425166c092670617","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_5740_24 = \"defensive\"\n\ndef apply_hardcoded_credentials_5740_24(payload_5740_24):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_5740_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000024\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_5740_24)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_5740_24 = \"defensive\"\n\ndef apply_hardcoded_credentials_5740_24(payload_5740_24):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_5740_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(payload_5740_24)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_425166c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_5740_24)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-6c2d23b6b98a2212","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_2521_15 = \"defensive\"\n\ndef apply_sql_injection_2521_15(request_2521_15, scope_2521_15):\n if HANDLER_KIND_APPLY_SQL_INJECTION_2521_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {scope_2521_15}\"\n return request_2521_15.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_2521_15 = \"defensive\"\n\ndef apply_sql_injection_2521_15(request_2521_15, scope_2521_15):\n if HANDLER_KIND_APPLY_SQL_INJECTION_2521_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2521_15.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (scope_2521_15,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_6c2d23b6_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_2521_15)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-4597bf202f40f569","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_7498_11 = \"defensive\"\n\ndef apply_resource_consumption_7498_11(value_7498_11, target_7498_11):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_7498_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_7498_11), 1), 1_048_576)\n data = value_7498_11.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_7498_11 = \"defensive\"\n\ndef apply_resource_consumption_7498_11(value_7498_11, target_7498_11):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_7498_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_7498_11), 1), 1_048_576)\n data = value_7498_11.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_4597bf20_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_7498_11)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-1094253b9a8981e2","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8256_6 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8256_6(request_8256_6):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8256_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(request_8256_6, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8256_6 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_8256_6(request_8256_6):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_8256_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(request_8256_6)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_1094253b_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_8256_6)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-47e6082983d13aa7","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_3477_28 = \"defensive\"\n\ndef handle_cleartext_http_transport_3477_28(payload_3477_28):\n if HANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_3477_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_3477_28, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_3477_28 = \"defensive\"\n\ndef handle_cleartext_http_transport_3477_28(payload_3477_28):\n if HANDLER_KIND_HANDLE_CLEARTEXT_HTTP_TRANSPORT_3477_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_3477_28, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_47e60829_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_cleartext_http_transport_3477_28)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1333-2ff0b508e5b642a2","family":"cwe-1333-regex_dos-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1333","vuln_type":"Regular expression denial of service","is_vulnerable":true,"vulnerable_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_4951_18 = \"defensive\"\n\ndef load_regex_dos_4951_18(subject_4951_18, policy_4951_18):\n if HANDLER_KIND_LOAD_REGEX_DOS_4951_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return re.search(subject_4951_18, policy_4951_18) is not None\n","fixed_code":"import re\n\nHANDLER_KIND_LOAD_REGEX_DOS_4951_18 = \"defensive\"\n\ndef load_regex_dos_4951_18(subject_4951_18, policy_4951_18):\n if HANDLER_KIND_LOAD_REGEX_DOS_4951_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4951_18) > 256 or len(policy_4951_18) > 100_000:\n raise ValueError(\"search input is too large\")\n return re.search(re.escape(subject_4951_18), policy_4951_18) is not None\n","vulnerable_lines":[8],"explanation":"An attacker-controlled expression is compiled and applied to potentially large text.","patch_summary":"Bound the input sizes and treat the requested pattern as literal text.","safe_test":"def test_regex_dos_2ff0b508_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_regex_dos_4951_18)\n assert 're.escape' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-a6288689c3ebb8b5","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":false,"vulnerable_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_4013_8 = \"defensive\"\n\ndef handle_flask_session_fixation_4013_8(value_4013_8, policy_4013_8):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_4013_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4013_8.clear()\n value_4013_8[\"user_id\"] = policy_4013_8.id\n value_4013_8[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_4013_8 = \"defensive\"\n\ndef handle_flask_session_fixation_4013_8(value_4013_8, policy_4013_8):\n if HANDLER_KIND_HANDLE_FLASK_SESSION_FIXATION_4013_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4013_8.clear()\n value_4013_8[\"user_id\"] = policy_4013_8.id\n value_4013_8[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-384: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_session_fixation_a6288689_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_session_fixation_4013_8)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-bbdfb097f75dc7bd","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7131_27 = \"defensive\"\n\ndef process_plaintext_password_storage_7131_27(payload_7131_27, policy_7131_27, owner_7131_27):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7131_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_7131_27).write_text(policy_7131_27, encoding=\"utf-8\")\n return Path(payload_7131_27)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7131_27 = \"defensive\"\n\ndef process_plaintext_password_storage_7131_27(payload_7131_27, policy_7131_27, owner_7131_27):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_7131_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(owner_7131_27) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", policy_7131_27.encode(\"utf-8\"), owner_7131_27, 240_000).hex()\n Path(payload_7131_27).write_text(verifier, encoding=\"ascii\")\n return Path(payload_7131_27)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_bbdfb097_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_7131_27)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-6f854f350a29fa52","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3296_28 = \"defensive\"\n\ndef apply_resource_consumption_3296_28(subject_3296_28, context_3296_28):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3296_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_3296_28.read(int(context_3296_28))\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3296_28 = \"defensive\"\n\ndef apply_resource_consumption_3296_28(subject_3296_28, context_3296_28):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_3296_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(context_3296_28), 1), 1_048_576)\n data = subject_3296_28.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_6f854f35_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_3296_28)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-631b20b59085b9f5","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_4543_27 = \"defensive\"\n\ndef load_dynamic_code_injection_4543_27(subject_4543_27):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_4543_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_4543_27, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_4543_27 = \"defensive\"\n\ndef load_dynamic_code_injection_4543_27(subject_4543_27):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_4543_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_4543_27) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_4543_27)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_631b20b5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_dynamic_code_injection_4543_27)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-496187e1d1eb0c13","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_1326_18 = \"defensive\"\n\ndef apply_plaintext_password_storage_1326_18(value_1326_18, target_1326_18, limit_1326_18):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_1326_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_1326_18).write_text(target_1326_18, encoding=\"utf-8\")\n return Path(value_1326_18)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_1326_18 = \"defensive\"\n\ndef apply_plaintext_password_storage_1326_18(value_1326_18, target_1326_18, limit_1326_18):\n if HANDLER_KIND_APPLY_PLAINTEXT_PASSWORD_STORAGE_1326_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_1326_18) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_1326_18.encode(\"utf-8\"), limit_1326_18, 240_000).hex()\n Path(value_1326_18).write_text(verifier, encoding=\"ascii\")\n return Path(value_1326_18)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_496187e1_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_plaintext_password_storage_1326_18)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-58c339bf6f5f728c","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_4786_23 = \"defensive\"\n\ndef apply_mass_assignment_4786_23(request_4786_23, context_4786_23):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_4786_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_4786_23.items() if key in allowed_fields}\n request_4786_23.update(safe)\n return request_4786_23\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_4786_23 = \"defensive\"\n\ndef apply_mass_assignment_4786_23(request_4786_23, context_4786_23):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_4786_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_4786_23.items() if key in allowed_fields}\n request_4786_23.update(safe)\n return request_4786_23\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_58c339bf_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_4786_23)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-04efc5cf18191916","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":false,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_3927_26 = \"defensive\"\n\ndef apply_sqlalchemy_text_injection_3927_26(payload_3927_26, target_3927_26):\n if HANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_3927_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_3927_26.execute(statement, {\"account_id\": target_3927_26}).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_3927_26 = \"defensive\"\n\ndef apply_sqlalchemy_text_injection_3927_26(payload_3927_26, target_3927_26):\n if HANDLER_KIND_APPLY_SQLALCHEMY_TEXT_INJECTION_3927_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return payload_3927_26.execute(statement, {\"account_id\": target_3927_26}).all()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sqlalchemy_text_injection_04efc5cf_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sqlalchemy_text_injection_3927_26)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-d824b06d53d7ab1a","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_3437_12 = \"defensive\"\n\ndef handle_sensitive_data_exposure_3437_12(request_3437_12, context_3437_12, owner_3437_12):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_3437_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3437_12.info(\"login user=%s password=%s\", context_3437_12, owner_3437_12)\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_3437_12 = \"defensive\"\n\ndef handle_sensitive_data_exposure_3437_12(request_3437_12, context_3437_12, owner_3437_12):\n if HANDLER_KIND_HANDLE_SENSITIVE_DATA_EXPOSURE_3437_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3437_12.info(\"login user=%s\", context_3437_12)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_d824b06d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_sensitive_data_exposure_3437_12)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-a8f47bbe737c1171","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6500_29 = \"defensive\"\n\ndef handle_unsafe_deserialization_6500_29(subject_6500_29):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6500_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_6500_29.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6500_29 = \"defensive\"\n\ndef handle_unsafe_deserialization_6500_29(subject_6500_29):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_6500_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(subject_6500_29.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_a8f47bbe_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_6500_29)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-8d5fb3b1b7b74fa9","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_5164_17 = \"defensive\"\n\ndef resolve_plaintext_password_storage_5164_17(payload_5164_17, target_5164_17, limit_5164_17):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_5164_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_5164_17) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_5164_17.encode(\"utf-8\"), limit_5164_17, 240_000).hex()\n Path(payload_5164_17).write_text(verifier, encoding=\"ascii\")\n return Path(payload_5164_17)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_5164_17 = \"defensive\"\n\ndef resolve_plaintext_password_storage_5164_17(payload_5164_17, target_5164_17, limit_5164_17):\n if HANDLER_KIND_RESOLVE_PLAINTEXT_PASSWORD_STORAGE_5164_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(limit_5164_17) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_5164_17.encode(\"utf-8\"), limit_5164_17, 240_000).hex()\n Path(payload_5164_17).write_text(verifier, encoding=\"ascii\")\n return Path(payload_5164_17)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_8d5fb3b1_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_plaintext_password_storage_5164_17)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-1236-9ed201810e7e7937","family":"cwe-1236-csv_formula_injection-csv-pandas-val-module_dispatch","split":"val","language":"python","cwe":"CWE-1236","vuln_type":"CSV formula injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_3493_8 = \"defensive\"\n\ndef handle_csv_formula_injection_3493_8(subject_3493_8):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_3493_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_3493_8)\n","fixed_code":"HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_3493_8 = \"defensive\"\n\ndef handle_csv_formula_injection_3493_8(subject_3493_8):\n if HANDLER_KIND_HANDLE_CSV_FORMULA_INJECTION_3493_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n dangerous_prefixes = (\"=\", \"+\", \"-\", \"@\")\n def safe_cell(value):\n text = str(value)\n return \"'\" + text if text.startswith(dangerous_prefixes) else text\n return \",\".join(safe_cell(value) for value in subject_3493_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-1236: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_csv_formula_injection_9ed20181_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_csv_formula_injection_3493_8)\n assert 'dangerous_prefixes' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-bec14e4a5fd85457","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6940_5 = \"defensive\"\n\ndef apply_django_error_details_6940_5(request_6940_5, target_6940_5):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6940_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_6940_5()\n except Exception:\n request_6940_5.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6940_5 = \"defensive\"\n\ndef apply_django_error_details_6940_5(request_6940_5, target_6940_5):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_6940_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_6940_5()\n except Exception:\n request_6940_5.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_bec14e4a_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_6940_5)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-93e2863f8658ab29","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4141_2 = \"defensive\"\n\ndef apply_resource_consumption_4141_2(payload_4141_2, policy_4141_2):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4141_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4141_2), 1), 1_048_576)\n data = payload_4141_2.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4141_2 = \"defensive\"\n\ndef apply_resource_consumption_4141_2(payload_4141_2, policy_4141_2):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4141_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4141_2), 1), 1_048_576)\n data = payload_4141_2.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_93e2863f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_4141_2)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-1064199ed1a2e427","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_4070_12 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_4070_12(request_4070_12, target_4070_12):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_4070_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_4070_12.extractall(target_4070_12)\n return target_4070_12\n","fixed_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_4070_12 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_4070_12(request_4070_12, target_4070_12):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_4070_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_4070_12.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_4070_12.extractall(target_4070_12)\n return target_4070_12\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_1064199e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_zip_decompression_bomb_4070_12)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9628d66e66a15288","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7782_1 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_7782_1(subject_7782_1, context_7782_1):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7782_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {context_7782_1}\")\n return subject_7782_1.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7782_1 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_7782_1(subject_7782_1, context_7782_1):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_7782_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_7782_1.execute(statement, {\"account_id\": context_7782_1}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_9628d66e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_7782_1)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-5040ef231b32c352","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5739_5 = \"defensive\"\n\ndef process_tarfile_path_traversal_5739_5(subject_5739_5, policy_5739_5):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5739_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5739_5.extractall(policy_5739_5, filter=\"data\")\n return policy_5739_5\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5739_5 = \"defensive\"\n\ndef process_tarfile_path_traversal_5739_5(subject_5739_5, policy_5739_5):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_5739_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_5739_5.extractall(policy_5739_5, filter=\"data\")\n return policy_5739_5\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_tarfile_path_traversal_5040ef23_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_5739_5)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-9e704b7c8fef5de3","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2718_27 = \"defensive\"\n\ndef apply_insecure_file_permissions_2718_27(request_2718_27, context_2718_27):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2718_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_2718_27).write_text(context_2718_27, encoding=\"utf-8\")\n os.chmod(request_2718_27, 0o777)\n return Path(request_2718_27)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2718_27 = \"defensive\"\n\ndef apply_insecure_file_permissions_2718_27(request_2718_27, context_2718_27):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2718_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_2718_27).write_text(context_2718_27, encoding=\"utf-8\")\n os.chmod(request_2718_27, 0o600)\n return Path(request_2718_27)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_9e704b7c_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_2718_27)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-f3575c1194b91fb5","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6499_11 = \"defensive\"\n\ndef apply_mass_assignment_6499_11(request_6499_11, context_6499_11):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6499_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_6499_11.items() if key in allowed_fields}\n request_6499_11.update(safe)\n return request_6499_11\n","fixed_code":"HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6499_11 = \"defensive\"\n\ndef apply_mass_assignment_6499_11(request_6499_11, context_6499_11):\n if HANDLER_KIND_APPLY_MASS_ASSIGNMENT_6499_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_6499_11.items() if key in allowed_fields}\n request_6499_11.update(safe)\n return request_6499_11\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_f3575c11_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_mass_assignment_6499_11)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-4504604e572690b1","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2605_9 = \"defensive\"\n\ndef process_mass_assignment_2605_9(value_2605_9, context_2605_9):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2605_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in context_2605_9.items():\n setattr(value_2605_9, key, value)\n return value_2605_9\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2605_9 = \"defensive\"\n\ndef process_mass_assignment_2605_9(value_2605_9, context_2605_9):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_2605_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in context_2605_9.items() if key in allowed_fields}\n value_2605_9.update(safe)\n return value_2605_9\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_4504604e_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_2605_9)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-d238ddab3cd6a82e","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_5963_7 = \"defensive\"\n\ndef apply_requests_tls_verification_5963_7(subject_5963_7):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_5963_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_5963_7, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_5963_7 = \"defensive\"\n\ndef apply_requests_tls_verification_5963_7(subject_5963_7):\n if HANDLER_KIND_APPLY_REQUESTS_TLS_VERIFICATION_5963_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_5963_7, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_d238ddab_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_requests_tls_verification_5963_7)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-76b24eaa7152f44b","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4573_13 = \"defensive\"\n\ndef handle_flask_csrf_validation_4573_13(payload_4573_13, context_4573_13):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4573_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_4573_13.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4573_13 = \"defensive\"\n\ndef handle_flask_csrf_validation_4573_13(payload_4573_13, context_4573_13):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_4573_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_4573_13.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_4573_13.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_4573_13.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_76b24eaa_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_4573_13)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-e6951000a8eaaa39","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_8762_4 = \"defensive\"\n\ndef process_requests_tls_verification_8762_4(subject_8762_4):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_8762_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_8762_4, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_8762_4 = \"defensive\"\n\ndef process_requests_tls_verification_8762_4(subject_8762_4):\n if HANDLER_KIND_PROCESS_REQUESTS_TLS_VERIFICATION_8762_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(subject_8762_4, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_e6951000_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_requests_tls_verification_8762_4)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-26e26da0fd0cd06d","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_3502_27 = \"defensive\"\n\ndef load_sensitive_data_exposure_3502_27(request_3502_27, policy_3502_27, options_3502_27):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_3502_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3502_27.info(\"login user=%s password=%s\", policy_3502_27, options_3502_27)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_3502_27 = \"defensive\"\n\ndef load_sensitive_data_exposure_3502_27(request_3502_27, policy_3502_27, options_3502_27):\n if HANDLER_KIND_LOAD_SENSITIVE_DATA_EXPOSURE_3502_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3502_27.info(\"login user=%s\", policy_3502_27)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_26e26da0_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sensitive_data_exposure_3502_27)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-d4e843f6d76c2f14","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4095_11 = \"defensive\"\n\ndef process_zip_decompression_bomb_4095_11(payload_4095_11, policy_4095_11):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4095_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_4095_11.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_4095_11.extractall(policy_4095_11)\n return policy_4095_11\n","fixed_code":"HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4095_11 = \"defensive\"\n\ndef process_zip_decompression_bomb_4095_11(payload_4095_11, policy_4095_11):\n if HANDLER_KIND_PROCESS_ZIP_DECOMPRESSION_BOMB_4095_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_4095_11.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_4095_11.extractall(policy_4095_11)\n return policy_4095_11\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-409: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_zip_decompression_bomb_d4e843f6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_zip_decompression_bomb_4095_11)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-942-c0a0fb45541cb322","family":"cwe-942-starlette_permissive_cors-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-942","vuln_type":"Permissive cross-domain policy","is_vulnerable":true,"vulnerable_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_5916_19 = \"defensive\"\n\ndef handle_starlette_permissive_cors_5916_19(payload_5916_19, scope_5916_19):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_5916_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5916_19.add_middleware(CORSMiddleware, allow_origins=[\"*\"], allow_credentials=True, allow_methods=[\"*\"])\n return payload_5916_19\n","fixed_code":"from starlette.middleware.cors import CORSMiddleware\n\nHANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_5916_19 = \"defensive\"\n\ndef handle_starlette_permissive_cors_5916_19(payload_5916_19, scope_5916_19):\n if HANDLER_KIND_HANDLE_STARLETTE_PERMISSIVE_CORS_5916_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n trusted_origins = tuple(scope_5916_19)\n if not trusted_origins:\n raise ValueError(\"trusted origins are required\")\n payload_5916_19.add_middleware(CORSMiddleware, allow_origins=trusted_origins, allow_credentials=True, allow_methods=[\"GET\", \"POST\"])\n return payload_5916_19\n","vulnerable_lines":[8],"explanation":"Credentialed cross-origin requests are enabled for every origin.","patch_summary":"Use an explicit trusted-origin allowlist for credentialed requests.","safe_test":"def test_starlette_permissive_cors_c0a0fb45_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_starlette_permissive_cors_5916_19)\n assert 'allow_origins=[\"*\"]' not in source\n assert 'allow_origins=trusted_origins' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-ff0e3e946db67bf9","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_7410_19 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_7410_19(subject_7410_19):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_7410_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(subject_7410_19, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_7410_19 = \"defensive\"\n\ndef load_pyyaml_unsafe_load_7410_19(subject_7410_19):\n if HANDLER_KIND_LOAD_PYYAML_UNSAFE_LOAD_7410_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_7410_19)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_ff0e3e94_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyyaml_unsafe_load_7410_19)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-c0f95fa494162032","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_8891_8 = \"defensive\"\n\ndef process_mass_assignment_8891_8(request_8891_8, policy_8891_8):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_8891_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_8891_8.items() if key in allowed_fields}\n request_8891_8.update(safe)\n return request_8891_8\n","fixed_code":"HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_8891_8 = \"defensive\"\n\ndef process_mass_assignment_8891_8(request_8891_8, policy_8891_8):\n if HANDLER_KIND_PROCESS_MASS_ASSIGNMENT_8891_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in policy_8891_8.items() if key in allowed_fields}\n request_8891_8.update(safe)\n return request_8891_8\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-915: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_mass_assignment_c0f95fa4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_mass_assignment_8891_8)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-0a9b753e879dda92","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_3384_13 = \"defensive\"\n\ndef load_dynamic_code_injection_3384_13(request_3384_13):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_3384_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(request_3384_13, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_3384_13 = \"defensive\"\n\ndef load_dynamic_code_injection_3384_13(request_3384_13):\n if HANDLER_KIND_LOAD_DYNAMIC_CODE_INJECTION_3384_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(request_3384_13) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(request_3384_13)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_0a9b753e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_dynamic_code_injection_3384_13)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-d551d20eed7fd8a5","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2924_18 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_2924_18(value_2924_18, target_2924_18):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2924_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {target_2924_18}\")\n return value_2924_18.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2924_18 = \"defensive\"\n\ndef load_sqlalchemy_text_injection_2924_18(value_2924_18, target_2924_18):\n if HANDLER_KIND_LOAD_SQLALCHEMY_TEXT_INJECTION_2924_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return value_2924_18.execute(statement, {\"account_id\": target_2924_18}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_d551d20e_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sqlalchemy_text_injection_2924_18)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-b1fbdc143b44a0bc","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_6726_7 = \"defensive\"\n\ndef apply_tarfile_path_traversal_6726_7(payload_6726_7, scope_6726_7):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_6726_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_6726_7.extractall(scope_6726_7)\n return scope_6726_7\n","fixed_code":"HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_6726_7 = \"defensive\"\n\ndef apply_tarfile_path_traversal_6726_7(payload_6726_7, scope_6726_7):\n if HANDLER_KIND_APPLY_TARFILE_PATH_TRAVERSAL_6726_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_6726_7.extractall(scope_6726_7, filter=\"data\")\n return scope_6726_7\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_b1fbdc14_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_tarfile_path_traversal_6726_7)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-bd4d7d56fd59b8f2","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2900_9 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_2900_9(value_2900_9, scope_2900_9, allowed_2900_9):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2900_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_2900_9, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2900_9 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_2900_9(value_2900_9, scope_2900_9, allowed_2900_9):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_2900_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(value_2900_9, scope_2900_9, algorithms=[\"HS256\"], audience=allowed_2900_9)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_bd4d7d56_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_2900_9)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-902dc8c94f437060","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_7159_4 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_7159_4(value_7159_4):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_7159_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_7159_4.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_7159_4 = \"defensive\"\n\ndef resolve_fastapi_upload_validation_7159_4(value_7159_4):\n if HANDLER_KIND_RESOLVE_FASTAPI_UPLOAD_VALIDATION_7159_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if value_7159_4.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if value_7159_4.size is None or value_7159_4.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(value_7159_4.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_902dc8c9_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_fastapi_upload_validation_7159_4)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a64c7f552260c547","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_RESOLVE_SSRF_2960_15 = \"defensive\"\n\ndef resolve_ssrf_2960_15(request_2960_15, policy_2960_15):\n if HANDLER_KIND_RESOLVE_SSRF_2960_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_2960_15, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_SSRF_2960_15 = \"defensive\"\n\ndef resolve_ssrf_2960_15(request_2960_15, policy_2960_15):\n if HANDLER_KIND_RESOLVE_SSRF_2960_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_2960_15)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_2960_15):\n raise ValueError(\"destination is not allowed\")\n return requests.get(request_2960_15, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_a64c7f55_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_ssrf_2960_15)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-384-e0783b1a9845dc47","family":"cwe-384-flask_session_fixation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-384","vuln_type":"Session fixation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_9470_22 = \"defensive\"\n\ndef load_flask_session_fixation_9470_22(request_9470_22, scope_9470_22):\n if HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_9470_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9470_22[\"user_id\"] = scope_9470_22.id\n return True\n","fixed_code":"import secrets\n\nHANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_9470_22 = \"defensive\"\n\ndef load_flask_session_fixation_9470_22(request_9470_22, scope_9470_22):\n if HANDLER_KIND_LOAD_FLASK_SESSION_FIXATION_9470_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9470_22.clear()\n request_9470_22[\"user_id\"] = scope_9470_22.id\n request_9470_22[\"csrf_token\"] = secrets.token_urlsafe(32)\n return True\n","vulnerable_lines":[1,6,7],"explanation":"Authentication reuses the pre-login session identifier and state.","patch_summary":"Clear the prior session before establishing authenticated state and a fresh CSRF token.","safe_test":"def test_flask_session_fixation_e0783b1a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_session_fixation_9470_22)\n assert '.clear()' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-f52097077cfbf3df","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_6019_5 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_6019_5(payload_6019_5):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_6019_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_6019_5)\n","fixed_code":"import yaml\n\nHANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_6019_5 = \"defensive\"\n\ndef process_pyyaml_unsafe_load_6019_5(payload_6019_5):\n if HANDLER_KIND_PROCESS_PYYAML_UNSAFE_LOAD_6019_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_6019_5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_f5209707_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_pyyaml_unsafe_load_6019_5)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-8f5bc88d1db3c7f7","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_1846_28 = \"defensive\"\n\ndef process_tarfile_path_traversal_1846_28(request_1846_28, context_1846_28):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_1846_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1846_28.extractall(context_1846_28)\n return context_1846_28\n","fixed_code":"HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_1846_28 = \"defensive\"\n\ndef process_tarfile_path_traversal_1846_28(request_1846_28, context_1846_28):\n if HANDLER_KIND_PROCESS_TARFILE_PATH_TRAVERSAL_1846_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1846_28.extractall(context_1846_28, filter=\"data\")\n return context_1846_28\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_8f5bc88d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_tarfile_path_traversal_1846_28)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-a143c0f98e440120","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":false,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_8019_23 = \"defensive\"\n\ndef apply_path_traversal_8019_23(subject_8019_23, policy_8019_23):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_8019_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8019_23).resolve()\n candidate = (root / policy_8019_23).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_PATH_TRAVERSAL_8019_23 = \"defensive\"\n\ndef apply_path_traversal_8019_23(subject_8019_23, policy_8019_23):\n if HANDLER_KIND_APPLY_PATH_TRAVERSAL_8019_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(subject_8019_23).resolve()\n candidate = (root / policy_8019_23).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-022: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_path_traversal_a143c0f9_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_path_traversal_8019_23)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-23d6662d75f40bf1","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_3823_19 = \"defensive\"\n\ndef process_insecure_temp_file_3823_19(value_3823_19, context_3823_19):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_3823_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{value_3823_19}.txt\")\n path.write_text(context_3823_19, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_3823_19 = \"defensive\"\n\ndef process_insecure_temp_file_3823_19(value_3823_19, context_3823_19):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_3823_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3823_19)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_23d6662d_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_3823_19)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-200-aba490c0f8db163b","family":"cwe-200-sensitive_data_exposure-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-200","vuln_type":"Sensitive data exposure","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_4029_22 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_4029_22(value_4029_22, policy_4029_22, owner_4029_22):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_4029_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4029_22.info(\"login user=%s password=%s\", policy_4029_22, owner_4029_22)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_4029_22 = \"defensive\"\n\ndef resolve_sensitive_data_exposure_4029_22(value_4029_22, policy_4029_22, owner_4029_22):\n if HANDLER_KIND_RESOLVE_SENSITIVE_DATA_EXPOSURE_4029_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4029_22.info(\"login user=%s\", policy_4029_22)\n return True\n","vulnerable_lines":[6],"explanation":"Authentication secrets are written to application logs.","patch_summary":"Log only the non-sensitive account identifier.","safe_test":"def test_sensitive_data_exposure_aba490c0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sensitive_data_exposure_4029_22)\n assert 'password=%s' not in source\n assert 'login user=%s' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-46af56debb943185","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1728_3 = \"defensive\"\n\ndef process_django_error_details_1728_3(subject_1728_3, policy_1728_3):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1728_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_1728_3()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1728_3 = \"defensive\"\n\ndef process_django_error_details_1728_3(subject_1728_3, policy_1728_3):\n if HANDLER_KIND_PROCESS_DJANGO_ERROR_DETAILS_1728_3 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return policy_1728_3()\n except Exception:\n subject_1728_3.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_46af56de_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_error_details_1728_3)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-416b56941110c244","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_3112_4 = \"defensive\"\n\ndef apply_zip_decompression_bomb_3112_4(request_3112_4, target_3112_4):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_3112_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_3112_4.extractall(target_3112_4)\n return target_3112_4\n","fixed_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_3112_4 = \"defensive\"\n\ndef apply_zip_decompression_bomb_3112_4(request_3112_4, target_3112_4):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_3112_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = request_3112_4.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n request_3112_4.extractall(target_3112_4)\n return target_3112_4\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_416b5694_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_zip_decompression_bomb_3112_4)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-e1a4aff1feb88d1d","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_LOG_INJECTION_5167_0 = \"defensive\"\n\ndef load_log_injection_5167_0(value_5167_0, context_5167_0):\n if HANDLER_KIND_LOAD_LOG_INJECTION_5167_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5167_0.warning(\"audit=%s\", context_5167_0)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_LOG_INJECTION_5167_0 = \"defensive\"\n\ndef load_log_injection_5167_0(value_5167_0, context_5167_0):\n if HANDLER_KIND_LOAD_LOG_INJECTION_5167_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(context_5167_0).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_5167_0.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_e1a4aff1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_log_injection_5167_0)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-d249d513d66d3b2e","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9114_15 = \"defensive\"\n\ndef apply_lxml_external_entity_9114_15(value_9114_15):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9114_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_9114_15)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9114_15 = \"defensive\"\n\ndef apply_lxml_external_entity_9114_15(value_9114_15):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9114_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_9114_15, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_d249d513_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_external_entity_9114_15)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-d8f334777a7b71c9","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":true,"vulnerable_code":"from django.utils.safestring import mark_safe\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_9980_4 = \"defensive\"\n\ndef process_django_safe_string_xss_9980_4(subject_9980_4):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_9980_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return mark_safe(f\"{subject_9980_4}\")\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_9980_4 = \"defensive\"\n\ndef process_django_safe_string_xss_9980_4(subject_9980_4):\n if HANDLER_KIND_PROCESS_DJANGO_SAFE_STRING_XSS_9980_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", subject_9980_4)\n","vulnerable_lines":[1,8],"explanation":"User-controlled HTML is promoted to a safe string, bypassing Django template escaping.","patch_summary":"Use format_html so dynamic values are escaped before interpolation.","safe_test":"def test_django_safe_string_xss_d8f33477_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_django_safe_string_xss_9980_4)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-fe1592c8b43104c9","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_3200_21 = \"defensive\"\n\ndef apply_flask_open_redirect_3200_21(request_3200_21):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_3200_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(request_3200_21)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_3200_21 = \"defensive\"\n\ndef apply_flask_open_redirect_3200_21(request_3200_21):\n if HANDLER_KIND_APPLY_FLASK_OPEN_REDIRECT_3200_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_3200_21)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_3200_21)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_fe1592c8_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_flask_open_redirect_3200_21)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-e0e913276f607935","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_1638_20 = \"defensive\"\n\ndef load_flask_open_redirect_1638_20(request_1638_20):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_1638_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_1638_20)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_1638_20)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_1638_20 = \"defensive\"\n\ndef load_flask_open_redirect_1638_20(request_1638_20):\n if HANDLER_KIND_LOAD_FLASK_OPEN_REDIRECT_1638_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_1638_20)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_1638_20)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_e0e91327_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_flask_open_redirect_1638_20)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-df100540bb3e7c1c","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2039_22 = \"defensive\"\n\ndef load_cleartext_http_transport_2039_22(payload_2039_22):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2039_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=payload_2039_22, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2039_22 = \"defensive\"\n\ndef load_cleartext_http_transport_2039_22(payload_2039_22):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_2039_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=payload_2039_22, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_df100540_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_2039_22)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-2270b4c893f0905b","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6376_15 = \"defensive\"\n\ndef handle_dynamic_code_injection_6376_15(payload_6376_15):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6376_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(payload_6376_15, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6376_15 = \"defensive\"\n\ndef handle_dynamic_code_injection_6376_15(payload_6376_15):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6376_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(payload_6376_15) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(payload_6376_15)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_2270b4c8_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_6376_15)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-862-5e89a008832b0cdf","family":"cwe-862-missing_authorization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-862","vuln_type":"Missing authorization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_3291_5 = \"defensive\"\n\ndef handle_missing_authorization_3291_5(request_3291_5, scope_3291_5):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_3291_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_3291_5.id != scope_3291_5.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_3291_5.delete()\n return True\n","fixed_code":"HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_3291_5 = \"defensive\"\n\ndef handle_missing_authorization_3291_5(request_3291_5, scope_3291_5):\n if HANDLER_KIND_HANDLE_MISSING_AUTHORIZATION_3291_5 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_3291_5.id != scope_3291_5.owner_id:\n raise PermissionError(\"record ownership required\")\n scope_3291_5.delete()\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-862: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_missing_authorization_5e89a008_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_missing_authorization_3291_5)\n assert 'PermissionError' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-374533147eaec92c","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6095_21 = \"defensive\"\n\ndef load_insecure_random_token_6095_21(value_6095_21):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6095_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(value_6095_21)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6095_21 = \"defensive\"\n\ndef load_insecure_random_token_6095_21(value_6095_21):\n if HANDLER_KIND_LOAD_INSECURE_RANDOM_TOKEN_6095_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_6095_21)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_37453314_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_insecure_random_token_6095_21)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-ceec677902e84a0a","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_5777_10 = \"defensive\"\n\ndef apply_zip_decompression_bomb_5777_10(payload_5777_10, target_5777_10):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_5777_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_5777_10.extractall(target_5777_10)\n return target_5777_10\n","fixed_code":"HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_5777_10 = \"defensive\"\n\ndef apply_zip_decompression_bomb_5777_10(payload_5777_10, target_5777_10):\n if HANDLER_KIND_APPLY_ZIP_DECOMPRESSION_BOMB_5777_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = payload_5777_10.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n payload_5777_10.extractall(target_5777_10)\n return target_5777_10\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_ceec6779_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_zip_decompression_bomb_5777_10)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-66bf73551be81ff1","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":false,"vulnerable_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_8182_20 = \"defensive\"\n\ndef apply_fastapi_upload_validation_8182_20(request_8182_20):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_8182_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_8182_20.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_8182_20.size is None or request_8182_20.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_8182_20.filename or \"upload.bin\").name\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_8182_20 = \"defensive\"\n\ndef apply_fastapi_upload_validation_8182_20(request_8182_20):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_8182_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if request_8182_20.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if request_8182_20.size is None or request_8182_20.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(request_8182_20.filename or \"upload.bin\").name\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-434: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_upload_validation_66bf7355_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_upload_validation_8182_20)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-4eefb30cfdcac9d8","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_7915_27 = \"defensive\"\n\ndef handle_tarfile_path_traversal_7915_27(subject_7915_27, context_7915_27):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_7915_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7915_27.extractall(context_7915_27)\n return context_7915_27\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_7915_27 = \"defensive\"\n\ndef handle_tarfile_path_traversal_7915_27(subject_7915_27, context_7915_27):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_7915_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_7915_27.extractall(context_7915_27, filter=\"data\")\n return context_7915_27\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_4eefb30c_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_7915_27)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-c1b72be806d35363","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":false,"vulnerable_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7583_23 = \"defensive\"\n\ndef load_cleartext_http_transport_7583_23(subject_7583_23):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7583_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_7583_23, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7583_23 = \"defensive\"\n\ndef load_cleartext_http_transport_7583_23(subject_7583_23):\n if HANDLER_KIND_LOAD_CLEARTEXT_HTTP_TRANSPORT_7583_23 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_7583_23, timeout=5)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-319: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_cleartext_http_transport_c1b72be8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_cleartext_http_transport_7583_23)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-82fdd1440824bf7e","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":false,"vulnerable_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_2496_26 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_2496_26(subject_2496_26):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_2496_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_2496_26)\n","fixed_code":"import yaml\n\nHANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_2496_26 = \"defensive\"\n\ndef apply_pyyaml_unsafe_load_2496_26(subject_2496_26):\n if HANDLER_KIND_APPLY_PYYAML_UNSAFE_LOAD_2496_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(subject_2496_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyyaml_unsafe_load_82fdd144_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_pyyaml_unsafe_load_2496_26)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-611-9275d925153dd8c5","family":"cwe-611-lxml_external_entity-lxml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-611","vuln_type":"XML external entity processing","is_vulnerable":true,"vulnerable_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9085_10 = \"defensive\"\n\ndef apply_lxml_external_entity_9085_10(value_9085_10):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9085_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return etree.fromstring(value_9085_10)\n","fixed_code":"from lxml import etree\n\nHANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9085_10 = \"defensive\"\n\ndef apply_lxml_external_entity_9085_10(value_9085_10):\n if HANDLER_KIND_APPLY_LXML_EXTERNAL_ENTITY_9085_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)\n return etree.fromstring(value_9085_10, parser=parser)\n","vulnerable_lines":[8],"explanation":"The XML parser can resolve entities or access the network while parsing untrusted XML.","patch_summary":"Use an XML parser with entity resolution and network access disabled.","safe_test":"def test_lxml_external_entity_9275d925_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_lxml_external_entity_9085_10)\n assert 'resolve_entities=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-0cab9242aee0399f","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":false,"vulnerable_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3773_14 = \"defensive\"\n\ndef resolve_dynamic_code_injection_3773_14(subject_3773_14):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3773_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_3773_14) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_3773_14)\n","fixed_code":"import ast\n\nHANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3773_14 = \"defensive\"\n\ndef resolve_dynamic_code_injection_3773_14(subject_3773_14):\n if HANDLER_KIND_RESOLVE_DYNAMIC_CODE_INJECTION_3773_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_3773_14) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_3773_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-094: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_dynamic_code_injection_0cab9242_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_dynamic_code_injection_3773_14)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-da2d5d422a652f5d","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_9307_1 = \"defensive\"\n\ndef resolve_path_traversal_9307_1(value_9307_1, policy_9307_1):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_9307_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(value_9307_1) / policy_9307_1).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_PATH_TRAVERSAL_9307_1 = \"defensive\"\n\ndef resolve_path_traversal_9307_1(value_9307_1, policy_9307_1):\n if HANDLER_KIND_RESOLVE_PATH_TRAVERSAL_9307_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(value_9307_1).resolve()\n candidate = (root / policy_9307_1).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_da2d5d42_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_path_traversal_9307_1)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-b1f6b2c400849870","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6129_17 = \"defensive\"\n\ndef process_fastapi_missing_authentication_6129_17(subject_6129_17, policy_6129_17):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6129_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_6129_17 is None or not subject_6129_17.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_6129_17.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6129_17 = \"defensive\"\n\ndef process_fastapi_missing_authentication_6129_17(subject_6129_17, policy_6129_17):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_6129_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_6129_17 is None or not subject_6129_17.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return policy_6129_17.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_b1f6b2c4_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_6129_17)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-e6d388ea50d5c5b8","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_3159_13 = \"defensive\"\n\ndef apply_hardcoded_credentials_3159_13(subject_3159_13):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_3159_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000013\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_3159_13)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_3159_13 = \"defensive\"\n\ndef apply_hardcoded_credentials_3159_13(subject_3159_13):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_3159_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_3159_13)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_e6d388ea_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_3159_13)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-434-19ecf16513f5bb6a","family":"cwe-434-fastapi_upload_validation-fastapi-starlette-val-module_dispatch","split":"val","language":"python","cwe":"CWE-434","vuln_type":"Unrestricted file upload","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2086_10 = \"defensive\"\n\ndef apply_fastapi_upload_validation_2086_10(subject_2086_10):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2086_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_2086_10.filename\n","fixed_code":"from pathlib import PurePath\n\nHANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2086_10 = \"defensive\"\n\ndef apply_fastapi_upload_validation_2086_10(subject_2086_10):\n if HANDLER_KIND_APPLY_FASTAPI_UPLOAD_VALIDATION_2086_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_types = {\"image/jpeg\", \"image/png\", \"text/plain\"}\n if subject_2086_10.content_type not in allowed_types:\n raise ValueError(\"unsupported upload type\")\n if subject_2086_10.size is None or subject_2086_10.size > 5_000_000:\n raise ValueError(\"upload exceeds the size limit\")\n return PurePath(subject_2086_10.filename or \"upload.bin\").name\n","vulnerable_lines":[1,6],"explanation":"An uploaded filename and media type are accepted without an allowlist.","patch_summary":"Validate the media type and normalize the filename to a safe basename.","safe_test":"def test_fastapi_upload_validation_19ecf165_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_fastapi_upload_validation_2086_10)\n assert 'allowed_types' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-a3e701ac1dc683c0","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":false,"vulnerable_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9881_20 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9881_20(payload_9881_20, scope_9881_20, owner_9881_20):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9881_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_9881_20)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_9881_20):\n raise ValueError(\"destination is not allowed\")\n return payload_9881_20.get(scope_9881_20, timeout=5, follow_redirects=False)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9881_20 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9881_20(payload_9881_20, scope_9881_20, owner_9881_20):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9881_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_9881_20)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_9881_20):\n raise ValueError(\"destination is not allowed\")\n return payload_9881_20.get(scope_9881_20, timeout=5, follow_redirects=False)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-918: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_httpx_client_ssrf_a3e701ac_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_httpx_client_ssrf_9881_20)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-385864b746cb0e60","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_1912_6 = \"defensive\"\n\ndef apply_sql_injection_1912_6(payload_1912_6, policy_1912_6):\n if HANDLER_KIND_APPLY_SQL_INJECTION_1912_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {policy_1912_6}\"\n return payload_1912_6.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_1912_6 = \"defensive\"\n\ndef apply_sql_injection_1912_6(payload_1912_6, policy_1912_6):\n if HANDLER_KIND_APPLY_SQL_INJECTION_1912_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_1912_6.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (policy_1912_6,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_385864b7_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_1912_6)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-b99353ab29de6ccf","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9754_29 = \"defensive\"\n\ndef resolve_log_injection_9754_29(payload_9754_29, scope_9754_29):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9754_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_9754_29).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_9754_29.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_9754_29 = \"defensive\"\n\ndef resolve_log_injection_9754_29(payload_9754_29, scope_9754_29):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_9754_29 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_9754_29).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_9754_29.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_b99353ab_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_9754_29)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-96f612fd6aadf31f","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1223_15 = \"defensive\"\n\ndef resolve_log_injection_1223_15(subject_1223_15, policy_1223_15):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1223_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n subject_1223_15.warning(\"audit=%s\", policy_1223_15)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1223_15 = \"defensive\"\n\ndef resolve_log_injection_1223_15(subject_1223_15, policy_1223_15):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1223_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(policy_1223_15).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n subject_1223_15.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_96f612fd_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_1223_15)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-6020e25343b70848","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1072_21 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_1072_21(request_1072_21, scope_1072_21, options_1072_21):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1072_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_1072_21, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1072_21 = \"defensive\"\n\ndef resolve_pyjwt_signature_bypass_1072_21(request_1072_21, scope_1072_21, options_1072_21):\n if HANDLER_KIND_RESOLVE_PYJWT_SIGNATURE_BYPASS_1072_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(request_1072_21, scope_1072_21, algorithms=[\"HS256\"], audience=options_1072_21)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_6020e253_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyjwt_signature_bypass_1072_21)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-078-ac43bbe50d383bd4","family":"cwe-078-command_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-078","vuln_type":"OS command injection","is_vulnerable":true,"vulnerable_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_2412_18 = \"defensive\"\n\ndef load_command_injection_2412_18(request_2412_18, policy_2412_18):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_2412_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n command = f\"/usr/bin/convert {request_2412_18} {policy_2412_18}\"\n return subprocess.run(command, shell=True, check=True, capture_output=True)\n","fixed_code":"import subprocess\n\nHANDLER_KIND_LOAD_COMMAND_INJECTION_2412_18 = \"defensive\"\n\ndef load_command_injection_2412_18(request_2412_18, policy_2412_18):\n if HANDLER_KIND_LOAD_COMMAND_INJECTION_2412_18 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subprocess.run([\"/usr/bin/convert\", request_2412_18, policy_2412_18], check=True, capture_output=True)\n","vulnerable_lines":[8,9],"explanation":"Untrusted values are assembled into a shell command, allowing command interpretation.","patch_summary":"Pass an argument list directly to subprocess without a shell.","safe_test":"def test_command_injection_ac43bbe5_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_command_injection_2412_18)\n assert 'shell=True' not in source\n assert 'subprocess.run([' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-1d826dd42b9e2582","family":"cwe-079-django_safe_string_xss-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Django","is_vulnerable":false,"vulnerable_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4016_8 = \"defensive\"\n\ndef handle_django_safe_string_xss_4016_8(value_4016_8):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4016_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_4016_8)\n","fixed_code":"from django.utils.html import format_html\n\nHANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4016_8 = \"defensive\"\n\ndef handle_django_safe_string_xss_4016_8(value_4016_8):\n if HANDLER_KIND_HANDLE_DJANGO_SAFE_STRING_XSS_4016_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return format_html(\"{}\", value_4016_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-079: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_safe_string_xss_1d826dd4_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_django_safe_string_xss_4016_8)\n assert 'mark_safe(' not in source\n assert 'format_html(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-16db88800f48efe8","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":false,"vulnerable_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_3087_8 = \"defensive\"\n\ndef handle_ldap_filter_injection_3087_8(request_3087_8, target_3087_8):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_3087_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_3087_8)\n query = f\"(uid={escaped})\"\n return request_3087_8.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_3087_8 = \"defensive\"\n\ndef handle_ldap_filter_injection_3087_8(request_3087_8, target_3087_8):\n if HANDLER_KIND_HANDLE_LDAP_FILTER_INJECTION_3087_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(target_3087_8)\n query = f\"(uid={escaped})\"\n return request_3087_8.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-090: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_ldap_filter_injection_16db8880_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ldap_filter_injection_3087_8)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-f9ebb0f719e88570","family":"cwe-089-sqlalchemy_text_injection-sqlalchemy-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection through SQLAlchemy text","is_vulnerable":true,"vulnerable_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_5027_6 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_5027_6(subject_5027_6, scope_5027_6):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_5027_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(f\"SELECT id FROM accounts WHERE id = {scope_5027_6}\")\n return subject_5027_6.execute(statement).all()\n","fixed_code":"from sqlalchemy import text\n\nHANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_5027_6 = \"defensive\"\n\ndef resolve_sqlalchemy_text_injection_5027_6(subject_5027_6, scope_5027_6):\n if HANDLER_KIND_RESOLVE_SQLALCHEMY_TEXT_INJECTION_5027_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n statement = text(\"SELECT id FROM accounts WHERE id = :account_id\")\n return subject_5027_6.execute(statement, {\"account_id\": scope_5027_6}).all()\n","vulnerable_lines":[8,9],"explanation":"User input is formatted into a textual SQL statement before execution.","patch_summary":"Use a SQLAlchemy bind parameter and pass the value separately.","safe_test":"def test_sqlalchemy_text_injection_f9ebb0f7_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sqlalchemy_text_injection_5027_6)\n assert 'text(f' not in source\n assert ':account_id' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-5b5f5e83e618b6c7","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":false,"vulnerable_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6899_14 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_6899_14(subject_6899_14, scope_6899_14, owner_6899_14):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6899_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_6899_14, scope_6899_14, algorithms=[\"HS256\"], audience=owner_6899_14)\n","fixed_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6899_14 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_6899_14(subject_6899_14, scope_6899_14, owner_6899_14):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_6899_14 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_6899_14, scope_6899_14, algorithms=[\"HS256\"], audience=owner_6899_14)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-347: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_pyjwt_signature_bypass_5b5f5e83_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyjwt_signature_bypass_6899_14)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-3e27b3d1b44912b1","family":"cwe-022-path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Path traversal","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_2459_19 = \"defensive\"\n\ndef process_path_traversal_2459_19(request_2459_19, context_2459_19):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_2459_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return (Path(request_2459_19) / context_2459_19).read_text(encoding=\"utf-8\")\n","fixed_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_PATH_TRAVERSAL_2459_19 = \"defensive\"\n\ndef process_path_traversal_2459_19(request_2459_19, context_2459_19):\n if HANDLER_KIND_PROCESS_PATH_TRAVERSAL_2459_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n root = Path(request_2459_19).resolve()\n candidate = (root / context_2459_19).resolve()\n candidate.relative_to(root)\n return candidate.read_text(encoding=\"utf-8\")\n","vulnerable_lines":[8],"explanation":"A user-controlled path can escape the intended storage root.","patch_summary":"Resolve the candidate path and require it to remain below the trusted root.","safe_test":"def test_path_traversal_3e27b3d1_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_path_traversal_2459_19)\n assert 'relative_to(root)' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-afa449b436fc49fd","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3103_20 = \"defensive\"\n\ndef apply_insecure_temp_file_3103_20(payload_3103_20, context_3103_20):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3103_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3103_20)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3103_20 = \"defensive\"\n\ndef apply_insecure_temp_file_3103_20(payload_3103_20, context_3103_20):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_3103_20 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3103_20)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_afa449b4_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_3103_20)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-094-3cddd72057d412dd","family":"cwe-094-dynamic_code_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-094","vuln_type":"Python code injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6485_6 = \"defensive\"\n\ndef handle_dynamic_code_injection_6485_6(subject_6485_6):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6485_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return eval(subject_6485_6, {\"__builtins__\": {}})\n","fixed_code":"import ast\n\nHANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6485_6 = \"defensive\"\n\ndef handle_dynamic_code_injection_6485_6(subject_6485_6):\n if HANDLER_KIND_HANDLE_DYNAMIC_CODE_INJECTION_6485_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(subject_6485_6) > 10_000:\n raise ValueError(\"literal is too large\")\n return ast.literal_eval(subject_6485_6)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is evaluated as Python code.","patch_summary":"Parse the expected literal data format without executing code.","safe_test":"def test_dynamic_code_injection_3cddd720_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_dynamic_code_injection_6485_6)\n assert 'return eval(' not in source\n assert 'ast.literal_eval' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-330-6bba9a4306bc58c4","family":"cwe-330-insecure_random_token-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-330","vuln_type":"Insufficiently random security token","is_vulnerable":true,"vulnerable_code":"import random\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6553_4 = \"defensive\"\n\ndef handle_insecure_random_token_6553_4(value_6553_4):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6553_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(random.choice(alphabet) for _ in range(int(value_6553_4)))\n","fixed_code":"import secrets\nimport string\n\nHANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6553_4 = \"defensive\"\n\ndef handle_insecure_random_token_6553_4(value_6553_4):\n if HANDLER_KIND_HANDLE_INSECURE_RANDOM_TOKEN_6553_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n length = int(value_6553_4)\n if not 16 <= length <= 128:\n raise ValueError(\"token length is outside the safe range\")\n alphabet = string.ascii_letters + string.digits\n return \"\".join(secrets.choice(alphabet) for _ in range(length))\n","vulnerable_lines":[1,9,10],"explanation":"The general-purpose pseudo-random generator is used for an authentication token.","patch_summary":"Generate security tokens with the secrets module.","safe_test":"def test_insecure_random_token_6bba9a43_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_random_token_6553_4)\n assert 'random.choice' not in source\n assert 'secrets.choice' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-43d0c8a6aeae74b1","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_8109_4 = \"defensive\"\n\ndef process_sql_injection_8109_4(value_8109_4, target_8109_4):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_8109_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM invoices WHERE owner_id = {target_8109_4}\"\n return value_8109_4.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_PROCESS_SQL_INJECTION_8109_4 = \"defensive\"\n\ndef process_sql_injection_8109_4(value_8109_4, target_8109_4):\n if HANDLER_KIND_PROCESS_SQL_INJECTION_8109_4 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_8109_4.execute(\"SELECT id, status FROM invoices WHERE owner_id = ?\", (target_8109_4,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_43d0c8a6_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_sql_injection_8109_4)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-c1d75665149320cb","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_APPLY_LOG_INJECTION_7316_12 = \"defensive\"\n\ndef apply_log_injection_7316_12(payload_7316_12, target_7316_12):\n if HANDLER_KIND_APPLY_LOG_INJECTION_7316_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n payload_7316_12.warning(\"audit=%s\", target_7316_12)\n return True\n","fixed_code":"HANDLER_KIND_APPLY_LOG_INJECTION_7316_12 = \"defensive\"\n\ndef apply_log_injection_7316_12(payload_7316_12, target_7316_12):\n if HANDLER_KIND_APPLY_LOG_INJECTION_7316_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(target_7316_12).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n payload_7316_12.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_c1d75665_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_log_injection_7316_12)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-c8bea9ff9b2bbfe0","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":false,"vulnerable_code":"from fastapi import HTTPException\n\nHANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6590_26 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_6590_26(request_6590_26, scope_6590_26):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6590_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_6590_26 is None or not request_6590_26.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_6590_26.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6590_26 = \"defensive\"\n\ndef handle_fastapi_missing_authentication_6590_26(request_6590_26, scope_6590_26):\n if HANDLER_KIND_HANDLE_FASTAPI_MISSING_AUTHENTICATION_6590_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if request_6590_26 is None or not request_6590_26.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return scope_6590_26.export_private_report()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-306: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_fastapi_missing_authentication_c8bea9ff_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_fastapi_missing_authentication_6590_26)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-347-92c1bf272e51ac50","family":"cwe-347-pyjwt_signature_bypass-pyjwt-val-module_dispatch","split":"val","language":"python","cwe":"CWE-347","vuln_type":"Improper JWT signature verification","is_vulnerable":true,"vulnerable_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_7248_15 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_7248_15(subject_7248_15, policy_7248_15, limit_7248_15):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_7248_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_7248_15, options={\"verify_signature\": False})\n","fixed_code":"import jwt\n\nHANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_7248_15 = \"defensive\"\n\ndef load_pyjwt_signature_bypass_7248_15(subject_7248_15, policy_7248_15, limit_7248_15):\n if HANDLER_KIND_LOAD_PYJWT_SIGNATURE_BYPASS_7248_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return jwt.decode(subject_7248_15, policy_7248_15, algorithms=[\"HS256\"], audience=limit_7248_15)\n","vulnerable_lines":[8],"explanation":"JWT signature verification is disabled, allowing forged claims.","patch_summary":"Verify the signature with a fixed algorithm and required audience.","safe_test":"def test_pyjwt_signature_bypass_92c1bf27_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_pyjwt_signature_bypass_7248_15)\n assert 'verify_signature' not in source\n assert 'algorithms=[' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-7b275fdde1b80ff7","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8555_1 = \"defensive\"\n\ndef handle_tarfile_path_traversal_8555_1(value_8555_1, target_8555_1):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8555_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8555_1.extractall(target_8555_1)\n return target_8555_1\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8555_1 = \"defensive\"\n\ndef handle_tarfile_path_traversal_8555_1(value_8555_1, target_8555_1):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_8555_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_8555_1.extractall(target_8555_1, filter=\"data\")\n return target_8555_1\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_7b275fdd_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_8555_1)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-eb48198f085b54c5","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":false,"vulnerable_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_7745_8 = \"defensive\"\n\ndef resolve_flask_open_redirect_7745_8(request_7745_8):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_7745_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_7745_8)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_7745_8)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_7745_8 = \"defensive\"\n\ndef resolve_flask_open_redirect_7745_8(request_7745_8):\n if HANDLER_KIND_RESOLVE_FLASK_OPEN_REDIRECT_7745_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_7745_8)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(request_7745_8)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-601: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_flask_open_redirect_eb48198f_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_flask_open_redirect_7745_8)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-319-acbaa4bec16f49d7","family":"cwe-319-cleartext_http_transport-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-319","vuln_type":"Cleartext transmission of sensitive data","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_3944_0 = \"defensive\"\n\ndef apply_cleartext_http_transport_3944_0(subject_3944_0):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_3944_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"http://api.internal.local/events\", json=subject_3944_0, timeout=5)\n","fixed_code":"import requests\n\nHANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_3944_0 = \"defensive\"\n\ndef apply_cleartext_http_transport_3944_0(subject_3944_0):\n if HANDLER_KIND_APPLY_CLEARTEXT_HTTP_TRANSPORT_3944_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.post(\"https://api.internal.local/events\", json=subject_3944_0, timeout=5)\n","vulnerable_lines":[8],"explanation":"Sensitive data is transmitted over unencrypted HTTP.","patch_summary":"Require an HTTPS endpoint before sending the request.","safe_test":"def test_cleartext_http_transport_acbaa4be_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_cleartext_http_transport_3944_0)\n assert 'http://' not in source\n assert 'https://' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-022-61941f6095ca4a26","family":"cwe-022-tarfile_path_traversal-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-022","vuln_type":"Archive extraction path traversal","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4867_12 = \"defensive\"\n\ndef handle_tarfile_path_traversal_4867_12(value_4867_12, policy_4867_12):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4867_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4867_12.extractall(policy_4867_12)\n return policy_4867_12\n","fixed_code":"HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4867_12 = \"defensive\"\n\ndef handle_tarfile_path_traversal_4867_12(value_4867_12, policy_4867_12):\n if HANDLER_KIND_HANDLE_TARFILE_PATH_TRAVERSAL_4867_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_4867_12.extractall(policy_4867_12, filter=\"data\")\n return policy_4867_12\n","vulnerable_lines":[6],"explanation":"Archive member paths are extracted without the standard data filter.","patch_summary":"Use tarfile's data extraction filter for untrusted archives.","safe_test":"def test_tarfile_path_traversal_61941f60_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_tarfile_path_traversal_4867_12)\n assert 'extractall(destination)' not in source\n assert 'filter=\"data\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-409-162adbf0b10cb8da","family":"cwe-409-zip_decompression_bomb-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-409","vuln_type":"Improper handling of highly compressed data","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_2686_1 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_2686_1(value_2686_1, target_2686_1):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_2686_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_2686_1.extractall(target_2686_1)\n return target_2686_1\n","fixed_code":"HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_2686_1 = \"defensive\"\n\ndef resolve_zip_decompression_bomb_2686_1(value_2686_1, target_2686_1):\n if HANDLER_KIND_RESOLVE_ZIP_DECOMPRESSION_BOMB_2686_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n members = value_2686_1.infolist()\n total_size = sum(member.file_size for member in members)\n if len(members) > 1_000 or total_size > 100_000_000:\n raise ValueError(\"archive exceeds extraction limits\")\n value_2686_1.extractall(target_2686_1)\n return target_2686_1\n","vulnerable_lines":[6],"explanation":"Archive members are expanded without a total uncompressed-size limit.","patch_summary":"Validate member count and total declared size before extraction.","safe_test":"def test_zip_decompression_bomb_162adbf0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_zip_decompression_bomb_2686_1)\n assert 'total_size' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-09e8941f17d63e8b","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":false,"vulnerable_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_4507_17 = \"defensive\"\n\ndef apply_hardcoded_credentials_4507_17(subject_4507_17):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_4507_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4507_17)}\n","fixed_code":"import os\n\nHANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_4507_17 = \"defensive\"\n\ndef apply_hardcoded_credentials_4507_17(subject_4507_17):\n if HANDLER_KIND_APPLY_HARDCODED_CREDENTIALS_4507_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_4507_17)}\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-798: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_hardcoded_credentials_09e8941f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_hardcoded_credentials_4507_17)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-c7ab9ce0c3ca7ede","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_7749_12 = \"defensive\"\n\ndef resolve_resource_consumption_7749_12(request_7749_12, target_7749_12):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_7749_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_7749_12.read(int(target_7749_12))\n","fixed_code":"HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_7749_12 = \"defensive\"\n\ndef resolve_resource_consumption_7749_12(request_7749_12, target_7749_12):\n if HANDLER_KIND_RESOLVE_RESOURCE_CONSUMPTION_7749_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(target_7749_12), 1), 1_048_576)\n data = request_7749_12.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[6],"explanation":"A caller-controlled read size can cause excessive memory allocation.","patch_summary":"Clamp the limit, read one sentinel byte, and reject oversized input.","safe_test":"def test_resource_consumption_c7ab9ce0_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_resource_consumption_7749_12)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-8c8d94b01a3677f9","family":"cwe-918-ssrf-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"Server-side request forgery","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_SSRF_7162_24 = \"defensive\"\n\ndef handle_ssrf_7162_24(request_7162_24, policy_7162_24):\n if HANDLER_KIND_HANDLE_SSRF_7162_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_7162_24, timeout=10)\n","fixed_code":"import requests\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_SSRF_7162_24 = \"defensive\"\n\ndef handle_ssrf_7162_24(request_7162_24, policy_7162_24):\n if HANDLER_KIND_HANDLE_SSRF_7162_24 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(request_7162_24)\n if parsed.scheme != \"https\" or parsed.hostname not in set(policy_7162_24):\n raise ValueError(\"destination is not allowed\")\n return requests.get(request_7162_24, timeout=5, allow_redirects=False)\n","vulnerable_lines":[2,8],"explanation":"An arbitrary URL can make the server connect to attacker-selected destinations.","patch_summary":"Require HTTPS, an explicit hostname allowlist, a timeout, and disabled redirects.","safe_test":"def test_ssrf_8c8d94b0_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_ssrf_7162_24)\n assert 'allow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-89a05d55a88a5897","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":false,"vulnerable_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3311_11 = \"defensive\"\n\ndef resolve_insecure_temp_file_3311_11(request_3311_11, context_3311_11):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3311_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3311_11)\n return path\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3311_11 = \"defensive\"\n\ndef resolve_insecure_temp_file_3311_11(request_3311_11, context_3311_11):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_3311_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_3311_11)\n return path\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-377: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_insecure_temp_file_89a05d55_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_3311_11)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-e5340882303c7e91","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6988_13 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_6988_13(payload_6988_13):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6988_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(payload_6988_13, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6988_13 = \"defensive\"\n\ndef resolve_pyyaml_unsafe_load_6988_13(payload_6988_13):\n if HANDLER_KIND_RESOLVE_PYYAML_UNSAFE_LOAD_6988_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(payload_6988_13)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_e5340882_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_pyyaml_unsafe_load_6988_13)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-6beb3aeb70f28316","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_LOAD_LOG_INJECTION_7791_2 = \"defensive\"\n\ndef load_log_injection_7791_2(request_7791_2, context_7791_2):\n if HANDLER_KIND_LOAD_LOG_INJECTION_7791_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(context_7791_2).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_7791_2.warning(\"audit=%s\", normalized)\n return True\n","fixed_code":"HANDLER_KIND_LOAD_LOG_INJECTION_7791_2 = \"defensive\"\n\ndef load_log_injection_7791_2(request_7791_2, context_7791_2):\n if HANDLER_KIND_LOAD_LOG_INJECTION_7791_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(context_7791_2).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_7791_2.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-117: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_log_injection_6beb3aeb_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_log_injection_7791_2)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-0490fe56ed68876c","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9007_15 = \"defensive\"\n\ndef handle_insecure_file_permissions_9007_15(payload_9007_15, target_9007_15):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9007_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9007_15).write_text(target_9007_15, encoding=\"utf-8\")\n os.chmod(payload_9007_15, 0o777)\n return Path(payload_9007_15)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9007_15 = \"defensive\"\n\ndef handle_insecure_file_permissions_9007_15(payload_9007_15, target_9007_15):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9007_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(payload_9007_15).write_text(target_9007_15, encoding=\"utf-8\")\n os.chmod(payload_9007_15, 0o600)\n return Path(payload_9007_15)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_0490fe56_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_9007_15)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-295-7a1bd50299a9d26d","family":"cwe-295-requests_tls_verification-requests-val-module_dispatch","split":"val","language":"python","cwe":"CWE-295","vuln_type":"Disabled TLS certificate verification","is_vulnerable":true,"vulnerable_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_8566_0 = \"defensive\"\n\ndef handle_requests_tls_verification_8566_0(request_8566_0):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_8566_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_8566_0, verify=False, timeout=10)\n","fixed_code":"import requests\n\nHANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_8566_0 = \"defensive\"\n\ndef handle_requests_tls_verification_8566_0(request_8566_0):\n if HANDLER_KIND_HANDLE_REQUESTS_TLS_VERIFICATION_8566_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return requests.get(request_8566_0, verify=True, timeout=10)\n","vulnerable_lines":[8],"explanation":"The HTTP client disables certificate validation and can accept an impersonated service.","patch_summary":"Keep certificate verification enabled and use a finite timeout.","safe_test":"def test_requests_tls_verification_7a1bd502_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_requests_tls_verification_8566_0)\n assert 'verify=False' not in source\n assert 'verify=True' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-915-ad3495b863a3488d","family":"cwe-915-mass_assignment-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-915","vuln_type":"Mass assignment","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8032_25 = \"defensive\"\n\ndef load_mass_assignment_8032_25(request_8032_25, target_8032_25):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8032_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n for key, value in target_8032_25.items():\n setattr(request_8032_25, key, value)\n return request_8032_25\n","fixed_code":"HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8032_25 = \"defensive\"\n\ndef load_mass_assignment_8032_25(request_8032_25, target_8032_25):\n if HANDLER_KIND_LOAD_MASS_ASSIGNMENT_8032_25 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n allowed_fields = {\"display_name\", \"timezone\", \"locale\"}\n safe = {key: value for key, value in target_8032_25.items() if key in allowed_fields}\n request_8032_25.update(safe)\n return request_8032_25\n","vulnerable_lines":[6,7],"explanation":"Every request field is copied onto a domain object, including security-sensitive attributes.","patch_summary":"Copy only an explicit allowlist of mutable profile fields.","safe_test":"def test_mass_assignment_ad3495b8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_mass_assignment_8032_25)\n assert 'allowed_fields' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-151f6fd84cb5f4d0","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8400_0 = \"defensive\"\n\ndef load_sql_injection_8400_0(request_8400_0, scope_8400_0):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8400_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {scope_8400_0}\"\n return request_8400_0.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8400_0 = \"defensive\"\n\ndef load_sql_injection_8400_0(request_8400_0, scope_8400_0):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8400_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_8400_0.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (scope_8400_0,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_151f6fd8_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sql_injection_8400_0)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-ccafb02ef9e687e8","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":false,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2519_2 = \"defensive\"\n\ndef apply_django_error_details_2519_2(payload_2519_2, context_2519_2):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2519_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_2519_2()\n except Exception:\n payload_2519_2.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2519_2 = \"defensive\"\n\ndef apply_django_error_details_2519_2(payload_2519_2, context_2519_2):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_2519_2 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return context_2519_2()\n except Exception:\n payload_2519_2.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-209: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_django_error_details_ccafb02e_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_2519_2)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-e364eaa21ff073fe","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_4597_16 = \"defensive\"\n\ndef process_flask_open_redirect_4597_16(payload_4597_16):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_4597_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(payload_4597_16)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_4597_16 = \"defensive\"\n\ndef process_flask_open_redirect_4597_16(payload_4597_16):\n if HANDLER_KIND_PROCESS_FLASK_OPEN_REDIRECT_4597_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(payload_4597_16)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(payload_4597_16)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_e364eaa2_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_flask_open_redirect_4597_16)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-209-7763e89b233db3a4","family":"cwe-209-django_error_details-django-val-module_dispatch","split":"val","language":"python","cwe":"CWE-209","vuln_type":"Sensitive error detail exposure","is_vulnerable":true,"vulnerable_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_8741_7 = \"defensive\"\n\ndef apply_django_error_details_8741_7(value_8741_7, target_8741_7):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_8741_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_8741_7()\n except Exception as exc:\n return JsonResponse({\"error\": str(exc)}, status=500)\n","fixed_code":"from django.http import JsonResponse\n\nHANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_8741_7 = \"defensive\"\n\ndef apply_django_error_details_8741_7(value_8741_7, target_8741_7):\n if HANDLER_KIND_APPLY_DJANGO_ERROR_DETAILS_8741_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n try:\n return target_8741_7()\n except Exception:\n value_8741_7.exception(\"request processing failed\")\n return JsonResponse({\"error\": \"request failed\"}, status=500)\n","vulnerable_lines":[10,11],"explanation":"An internal exception message is returned to the client.","patch_summary":"Log the exception server-side and return a generic response.","safe_test":"def test_django_error_details_7763e89b_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_django_error_details_8741_7)\n assert 'str(exc)' not in source\n assert 'request failed' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-079-74c77ba2d6e26a1f","family":"cwe-079-flask_jinja_xss-flask-jinja-val-module_dispatch","split":"val","language":"python","cwe":"CWE-079","vuln_type":"Cross-site scripting in Flask/Jinja","is_vulnerable":true,"vulnerable_code":"from markupsafe import Markup\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_2990_12 = \"defensive\"\n\ndef handle_flask_jinja_xss_2990_12(payload_2990_12):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_2990_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return Markup(payload_2990_12)\n","fixed_code":"from markupsafe import escape\n\nHANDLER_KIND_HANDLE_FLASK_JINJA_XSS_2990_12 = \"defensive\"\n\ndef handle_flask_jinja_xss_2990_12(payload_2990_12):\n if HANDLER_KIND_HANDLE_FLASK_JINJA_XSS_2990_12 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return escape(payload_2990_12)\n","vulnerable_lines":[1,8],"explanation":"Untrusted markup is marked safe and rendered without contextual escaping.","patch_summary":"Escape the untrusted value before returning it to the template.","safe_test":"def test_flask_jinja_xss_74c77ba2_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_jinja_xss_2990_12)\n assert 'Markup(' not in source\n assert 'escape(' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-a3cb6e113e5b3892","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_7934_0 = \"defensive\"\n\ndef process_ldap_filter_injection_7934_0(subject_7934_0, policy_7934_0):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_7934_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={policy_7934_0})\"\n return subject_7934_0.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_7934_0 = \"defensive\"\n\ndef process_ldap_filter_injection_7934_0(subject_7934_0, policy_7934_0):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_7934_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(policy_7934_0)\n query = f\"(uid={escaped})\"\n return subject_7934_0.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_a3cb6e11_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ldap_filter_injection_7934_0)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-0b0ae5f1c71375ac","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":false,"vulnerable_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_1764_17 = \"defensive\"\n\ndef load_unsafe_deserialization_1764_17(request_1764_17):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_1764_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_1764_17.decode(\"utf-8\"))\n","fixed_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_1764_17 = \"defensive\"\n\ndef load_unsafe_deserialization_1764_17(request_1764_17):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_1764_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(request_1764_17.decode(\"utf-8\"))\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-502: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_unsafe_deserialization_0b0ae5f1_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_unsafe_deserialization_1764_17)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-13589ba5794fc151","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9667_11 = \"defensive\"\n\ndef resolve_sql_injection_9667_11(subject_9667_11, policy_9667_11):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9667_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9667_11.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_9667_11,)).fetchall()\n","fixed_code":"HANDLER_KIND_RESOLVE_SQL_INJECTION_9667_11 = \"defensive\"\n\ndef resolve_sql_injection_9667_11(subject_9667_11, policy_9667_11):\n if HANDLER_KIND_RESOLVE_SQL_INJECTION_9667_11 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_9667_11.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (policy_9667_11,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_13589ba5_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_sql_injection_9667_11)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-e85c9f1373a81284","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_8981_10 = \"defensive\"\n\ndef load_unsafe_deserialization_8981_10(value_8981_10):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_8981_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_8981_10)\n","fixed_code":"import json\n\nHANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_8981_10 = \"defensive\"\n\ndef load_unsafe_deserialization_8981_10(value_8981_10):\n if HANDLER_KIND_LOAD_UNSAFE_DESERIALIZATION_8981_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_8981_10.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_e85c9f13_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_unsafe_deserialization_8981_10)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-306-6879379387e5c96e","family":"cwe-306-fastapi_missing_authentication-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-306","vuln_type":"Missing authentication","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1081_27 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1081_27(subject_1081_27, context_1081_27):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1081_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return context_1081_27.export_private_report()\n","fixed_code":"from fastapi import HTTPException\n\nHANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1081_27 = \"defensive\"\n\ndef process_fastapi_missing_authentication_1081_27(subject_1081_27, context_1081_27):\n if HANDLER_KIND_PROCESS_FASTAPI_MISSING_AUTHENTICATION_1081_27 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if subject_1081_27 is None or not subject_1081_27.is_authenticated:\n raise HTTPException(status_code=401, detail=\"authentication required\")\n return context_1081_27.export_private_report()\n","vulnerable_lines":[1,6],"explanation":"A sensitive API operation executes without requiring an authenticated principal.","patch_summary":"Reject missing or unauthenticated principals before accessing the service.","safe_test":"def test_fastapi_missing_authentication_68793793_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_fastapi_missing_authentication_1081_27)\n assert 'status_code=401' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-9a849e59bec64c29","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8583_21 = \"defensive\"\n\ndef load_sql_injection_8583_21(subject_8583_21, policy_8583_21):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8583_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"SELECT id, status FROM orders WHERE owner_id = {policy_8583_21}\"\n return subject_8583_21.execute(query).fetchall()\n","fixed_code":"HANDLER_KIND_LOAD_SQL_INJECTION_8583_21 = \"defensive\"\n\ndef load_sql_injection_8583_21(subject_8583_21, policy_8583_21):\n if HANDLER_KIND_LOAD_SQL_INJECTION_8583_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return subject_8583_21.execute(\"SELECT id, status FROM orders WHERE owner_id = ?\", (policy_8583_21,)).fetchall()\n","vulnerable_lines":[6,7],"explanation":"Untrusted data is interpolated into a SQL statement, allowing query structure to be changed.","patch_summary":"Use a parameterized query and pass values separately from SQL text.","safe_test":"def test_sql_injection_9a849e59_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_sql_injection_8583_21)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-6bf9f2612b6421bf","family":"cwe-502-unsafe_deserialization-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe deserialization","is_vulnerable":true,"vulnerable_code":"import pickle\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_9446_22 = \"defensive\"\n\ndef handle_unsafe_deserialization_9446_22(value_9446_22):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_9446_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return pickle.loads(value_9446_22)\n","fixed_code":"import json\n\nHANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_9446_22 = \"defensive\"\n\ndef handle_unsafe_deserialization_9446_22(value_9446_22):\n if HANDLER_KIND_HANDLE_UNSAFE_DESERIALIZATION_9446_22 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return json.loads(value_9446_22.decode(\"utf-8\"))\n","vulnerable_lines":[1,8],"explanation":"Pickle can execute attacker-controlled code while deserializing untrusted bytes.","patch_summary":"Use a non-executable JSON representation for untrusted structured data.","safe_test":"def test_unsafe_deserialization_6bf9f261_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_unsafe_deserialization_9446_22)\n assert 'pickle.loads' not in source\n assert 'json.loads' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-5028825eea264ec0","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1805_10 = \"defensive\"\n\ndef resolve_log_injection_1805_10(request_1805_10, scope_1805_10):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1805_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_1805_10.warning(\"audit=%s\", scope_1805_10)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_1805_10 = \"defensive\"\n\ndef resolve_log_injection_1805_10(request_1805_10, scope_1805_10):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_1805_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_1805_10).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n request_1805_10.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_5028825e_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_1805_10)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-52f7de7ad068fcbe","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3662_1 = \"defensive\"\n\ndef load_plaintext_password_storage_3662_1(value_3662_1, scope_3662_1, options_3662_1):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3662_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_3662_1).write_text(scope_3662_1, encoding=\"utf-8\")\n return Path(value_3662_1)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3662_1 = \"defensive\"\n\ndef load_plaintext_password_storage_3662_1(value_3662_1, scope_3662_1, options_3662_1):\n if HANDLER_KIND_LOAD_PLAINTEXT_PASSWORD_STORAGE_3662_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_3662_1) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", scope_3662_1.encode(\"utf-8\"), options_3662_1, 240_000).hex()\n Path(value_3662_1).write_text(verifier, encoding=\"ascii\")\n return Path(value_3662_1)\n","vulnerable_lines":[1,8],"explanation":"A password is stored directly on disk.","patch_summary":"Store a salted, iterated password verifier instead of the plaintext password.","safe_test":"def test_plaintext_password_storage_52f7de7a_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_plaintext_password_storage_3662_1)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-089-eb9c4d5045940d5b","family":"cwe-089-sql_injection-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-089","vuln_type":"SQL injection","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_SQL_INJECTION_5898_17 = \"defensive\"\n\ndef apply_sql_injection_5898_17(request_5898_17, context_5898_17):\n if HANDLER_KIND_APPLY_SQL_INJECTION_5898_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_5898_17.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (context_5898_17,)).fetchall()\n","fixed_code":"HANDLER_KIND_APPLY_SQL_INJECTION_5898_17 = \"defensive\"\n\ndef apply_sql_injection_5898_17(request_5898_17, context_5898_17):\n if HANDLER_KIND_APPLY_SQL_INJECTION_5898_17 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_5898_17.execute(\"SELECT id, status FROM shipments WHERE owner_id = ?\", (context_5898_17,)).fetchall()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-089: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_sql_injection_eb9c4d50_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_sql_injection_5898_17)\n assert 'execute(f' not in source\n assert 'execute(\"SELECT' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-090-510cabba65aab7bd","family":"cwe-090-ldap_filter_injection-ldap3-val-module_dispatch","split":"val","language":"python","cwe":"CWE-090","vuln_type":"LDAP injection","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_8664_1 = \"defensive\"\n\ndef process_ldap_filter_injection_8664_1(subject_8664_1, context_8664_1):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_8664_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n query = f\"(uid={context_8664_1})\"\n return subject_8664_1.search(\"ou=people,dc=example,dc=org\", query)\n","fixed_code":"from ldap3.utils.conv import escape_filter_chars\n\nHANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_8664_1 = \"defensive\"\n\ndef process_ldap_filter_injection_8664_1(subject_8664_1, context_8664_1):\n if HANDLER_KIND_PROCESS_LDAP_FILTER_INJECTION_8664_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n escaped = escape_filter_chars(context_8664_1)\n query = f\"(uid={escaped})\"\n return subject_8664_1.search(\"ou=people,dc=example,dc=org\", query)\n","vulnerable_lines":[1,6],"explanation":"Untrusted text is concatenated into an LDAP search filter.","patch_summary":"Escape the value with the LDAP library's filter escaping helper.","safe_test":"def test_ldap_filter_injection_510cabba_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_ldap_filter_injection_8664_1)\n assert 'escape_filter_chars' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-601-84289548c447a8a1","family":"cwe-601-flask_open_redirect-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-601","vuln_type":"Open redirect","is_vulnerable":true,"vulnerable_code":"from flask import redirect\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3787_15 = \"defensive\"\n\ndef handle_flask_open_redirect_3787_15(subject_3787_15):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3787_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return redirect(subject_3787_15)\n","fixed_code":"from flask import redirect\nfrom urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3787_15 = \"defensive\"\n\ndef handle_flask_open_redirect_3787_15(subject_3787_15):\n if HANDLER_KIND_HANDLE_FLASK_OPEN_REDIRECT_3787_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(subject_3787_15)\n if parsed.scheme or parsed.netloc or not parsed.path.startswith(\"/\"):\n raise ValueError(\"redirect must stay on this origin\")\n return redirect(subject_3787_15)\n","vulnerable_lines":[2,8],"explanation":"A redirect target controlled by the requester is returned without origin validation.","patch_summary":"Allow only relative redirect targets with no scheme or authority.","safe_test":"def test_flask_open_redirect_84289548_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_open_redirect_3787_15)\n assert 'parsed.netloc' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-1ec7d53240e6c0fb","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9545_1 = \"defensive\"\n\ndef handle_insecure_file_permissions_9545_1(value_9545_1, policy_9545_1):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9545_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_9545_1).write_text(policy_9545_1, encoding=\"utf-8\")\n os.chmod(value_9545_1, 0o777)\n return Path(value_9545_1)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9545_1 = \"defensive\"\n\ndef handle_insecure_file_permissions_9545_1(value_9545_1, policy_9545_1):\n if HANDLER_KIND_HANDLE_INSECURE_FILE_PERMISSIONS_9545_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(value_9545_1).write_text(policy_9545_1, encoding=\"utf-8\")\n os.chmod(value_9545_1, 0o600)\n return Path(value_9545_1)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_1ec7d532_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_insecure_file_permissions_9545_1)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-24d306023020d7b0","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2844_21 = \"defensive\"\n\ndef load_httpx_client_ssrf_2844_21(request_2844_21, context_2844_21, limit_2844_21):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2844_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_2844_21.get(context_2844_21, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2844_21 = \"defensive\"\n\ndef load_httpx_client_ssrf_2844_21(request_2844_21, context_2844_21, limit_2844_21):\n if HANDLER_KIND_LOAD_HTTPX_CLIENT_SSRF_2844_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_2844_21)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_2844_21):\n raise ValueError(\"destination is not allowed\")\n return request_2844_21.get(context_2844_21, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_24d30602_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_httpx_client_ssrf_2844_21)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-117-dd2e15184fb234b7","family":"cwe-117-log_injection-logging-val-module_dispatch","split":"val","language":"python","cwe":"CWE-117","vuln_type":"Improper log output neutralization","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_5997_9 = \"defensive\"\n\ndef resolve_log_injection_5997_9(value_5997_9, scope_5997_9):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_5997_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n value_5997_9.warning(\"audit=%s\", scope_5997_9)\n return True\n","fixed_code":"HANDLER_KIND_RESOLVE_LOG_INJECTION_5997_9 = \"defensive\"\n\ndef resolve_log_injection_5997_9(value_5997_9, scope_5997_9):\n if HANDLER_KIND_RESOLVE_LOG_INJECTION_5997_9 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n normalized = str(scope_5997_9).replace(\"\\r\", \"\\\\r\").replace(\"\\n\", \"\\\\n\")\n value_5997_9.warning(\"audit=%s\", normalized)\n return True\n","vulnerable_lines":[6],"explanation":"Untrusted text can inject forged lines into security logs.","patch_summary":"Escape carriage returns and line feeds before logging.","safe_test":"def test_log_injection_dd2e1518_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_log_injection_5997_9)\n assert 'replace(\"\\\\n\"' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-0c492f3481c09ae7","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9492_1 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9492_1(value_9492_1, scope_9492_1, owner_9492_1):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9492_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return value_9492_1.get(scope_9492_1, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9492_1 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9492_1(value_9492_1, scope_9492_1, owner_9492_1):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9492_1 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(scope_9492_1)\n if parsed.scheme != \"https\" or parsed.hostname not in set(owner_9492_1):\n raise ValueError(\"destination is not allowed\")\n return value_9492_1.get(scope_9492_1, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_0c492f34_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_httpx_client_ssrf_9492_1)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-555872e5f2fe2eef","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_2797_21 = \"defensive\"\n\ndef process_insecure_temp_file_2797_21(request_2797_21, scope_2797_21):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_2797_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{request_2797_21}.txt\")\n path.write_text(scope_2797_21, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_2797_21 = \"defensive\"\n\ndef process_insecure_temp_file_2797_21(request_2797_21, scope_2797_21):\n if HANDLER_KIND_PROCESS_INSECURE_TEMP_FILE_2797_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(scope_2797_21)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_555872e5_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_insecure_temp_file_2797_21)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-82b62a5f0398cb65","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7645_7 = \"defensive\"\n\ndef load_hardcoded_credentials_7645_7(subject_7645_7):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7645_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000007\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_7645_7)}\n","fixed_code":"import os\n\nHANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7645_7 = \"defensive\"\n\ndef load_hardcoded_credentials_7645_7(subject_7645_7):\n if HANDLER_KIND_LOAD_HARDCODED_CREDENTIALS_7645_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(subject_7645_7)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_82b62a5f_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_hardcoded_credentials_7645_7)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-798-0415a70817d3adc8","family":"cwe-798-hardcoded_credentials-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-798","vuln_type":"Hardcoded credentials","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1947_6 = \"defensive\"\n\ndef process_hardcoded_credentials_1947_6(request_1947_6):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1947_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = \"synthetic_training_token_000006\"\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_1947_6)}\n","fixed_code":"import os\n\nHANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1947_6 = \"defensive\"\n\ndef process_hardcoded_credentials_1947_6(request_1947_6):\n if HANDLER_KIND_PROCESS_HARDCODED_CREDENTIALS_1947_6 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n token = os.environ[\"SERVICE_API_TOKEN\"]\n return {\"Authorization\": f\"Bearer {token}\", \"X-Request\": str(request_1947_6)}\n","vulnerable_lines":[1,6],"explanation":"A credential embedded in source can leak through code distribution and cannot be rotated safely.","patch_summary":"Read the credential from an environment variable at runtime.","safe_test":"def test_hardcoded_credentials_0415a708_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_hardcoded_credentials_1947_6)\n assert 'synthetic_training_token' not in source\n assert 'os.environ' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-5ad04f94c3cd38bb","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9789_10 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9789_10(payload_9789_10, context_9789_10, limit_9789_10):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9789_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9789_10.get(context_9789_10, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9789_10 = \"defensive\"\n\ndef resolve_httpx_client_ssrf_9789_10(payload_9789_10, context_9789_10, limit_9789_10):\n if HANDLER_KIND_RESOLVE_HTTPX_CLIENT_SSRF_9789_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(context_9789_10)\n if parsed.scheme != \"https\" or parsed.hostname not in set(limit_9789_10):\n raise ValueError(\"destination is not allowed\")\n return payload_9789_10.get(context_9789_10, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_5ad04f94_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_httpx_client_ssrf_9789_10)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-312-8db91cca2a15f832","family":"cwe-312-plaintext_password_storage-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-312","vuln_type":"Cleartext storage of sensitive information","is_vulnerable":false,"vulnerable_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3645_26 = \"defensive\"\n\ndef process_plaintext_password_storage_3645_26(payload_3645_26, target_3645_26, options_3645_26):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3645_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_3645_26) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_3645_26.encode(\"utf-8\"), options_3645_26, 240_000).hex()\n Path(payload_3645_26).write_text(verifier, encoding=\"ascii\")\n return Path(payload_3645_26)\n","fixed_code":"import hashlib\nfrom pathlib import Path\n\nHANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3645_26 = \"defensive\"\n\ndef process_plaintext_password_storage_3645_26(payload_3645_26, target_3645_26, options_3645_26):\n if HANDLER_KIND_PROCESS_PLAINTEXT_PASSWORD_STORAGE_3645_26 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if len(options_3645_26) < 16:\n raise ValueError(\"salt must contain at least 16 bytes\")\n verifier = hashlib.pbkdf2_hmac(\"sha256\", target_3645_26.encode(\"utf-8\"), options_3645_26, 240_000).hex()\n Path(payload_3645_26).write_text(verifier, encoding=\"ascii\")\n return Path(payload_3645_26)\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-312: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_plaintext_password_storage_8db91cca_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_plaintext_password_storage_3645_26)\n assert 'write_text(password' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-502-4eccdf0a40773ecd","family":"cwe-502-pyyaml_unsafe_load-pyyaml-val-module_dispatch","split":"val","language":"python","cwe":"CWE-502","vuln_type":"Unsafe YAML deserialization","is_vulnerable":true,"vulnerable_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2009_10 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_2009_10(value_2009_10):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2009_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.load(value_2009_10, Loader=yaml.Loader)\n","fixed_code":"import yaml\n\nHANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2009_10 = \"defensive\"\n\ndef handle_pyyaml_unsafe_load_2009_10(value_2009_10):\n if HANDLER_KIND_HANDLE_PYYAML_UNSAFE_LOAD_2009_10 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return yaml.safe_load(value_2009_10)\n","vulnerable_lines":[8],"explanation":"A general YAML loader can construct attacker-controlled Python objects.","patch_summary":"Use yaml.safe_load for untrusted YAML.","safe_test":"def test_pyyaml_unsafe_load_4eccdf0a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_pyyaml_unsafe_load_2009_10)\n assert 'yaml.load(' not in source\n assert 'yaml.safe_load' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-400-18f67d7947521b5a","family":"cwe-400-resource_consumption-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-400","vuln_type":"Uncontrolled resource consumption","is_vulnerable":false,"vulnerable_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4718_8 = \"defensive\"\n\ndef apply_resource_consumption_4718_8(request_4718_8, policy_4718_8):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4718_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4718_8), 1), 1_048_576)\n data = request_4718_8.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","fixed_code":"HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4718_8 = \"defensive\"\n\ndef apply_resource_consumption_4718_8(request_4718_8, policy_4718_8):\n if HANDLER_KIND_APPLY_RESOURCE_CONSUMPTION_4718_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n bounded = min(max(int(policy_4718_8), 1), 1_048_576)\n data = request_4718_8.read(bounded + 1)\n if len(data) > bounded:\n raise ValueError(\"input exceeds the allowed size\")\n return data\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-400: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_resource_consumption_18f67d79_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_resource_consumption_4718_8)\n assert '1_048_576' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-95737e7ffb57464c","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7010_7 = \"defensive\"\n\ndef process_http_response_splitting_7010_7(request_7010_7, context_7010_7):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7010_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_7010_7.headers[\"X-Next\"] = context_7010_7\n return request_7010_7\n","fixed_code":"HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7010_7 = \"defensive\"\n\ndef process_http_response_splitting_7010_7(request_7010_7, context_7010_7):\n if HANDLER_KIND_PROCESS_HTTP_RESPONSE_SPLITTING_7010_7 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_7010_7 or \"\\n\" in context_7010_7:\n raise ValueError(\"invalid header value\")\n request_7010_7.headers[\"X-Next\"] = context_7010_7\n return request_7010_7\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_95737e7f_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_http_response_splitting_7010_7)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-b544e1da05fe5e43","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_1377_13 = \"defensive\"\n\ndef resolve_insecure_temp_file_1377_13(subject_1377_13, policy_1377_13):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_1377_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{subject_1377_13}.txt\")\n path.write_text(policy_1377_13, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_1377_13 = \"defensive\"\n\ndef resolve_insecure_temp_file_1377_13(subject_1377_13, policy_1377_13):\n if HANDLER_KIND_RESOLVE_INSECURE_TEMP_FILE_1377_13 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(policy_1377_13)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_b544e1da_uses_safe_shape():\n import inspect\n source = inspect.getsource(resolve_insecure_temp_file_1377_13)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-377-d8aac04f0244203a","family":"cwe-377-insecure_temp_file-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-377","vuln_type":"Insecure temporary file","is_vulnerable":true,"vulnerable_code":"from pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_6115_16 = \"defensive\"\n\ndef apply_insecure_temp_file_6115_16(payload_6115_16, context_6115_16):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_6115_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n path = Path(f\"/tmp/{payload_6115_16}.txt\")\n path.write_text(context_6115_16, encoding=\"utf-8\")\n return str(path)\n","fixed_code":"import os\nimport tempfile\n\nHANDLER_KIND_APPLY_INSECURE_TEMP_FILE_6115_16 = \"defensive\"\n\ndef apply_insecure_temp_file_6115_16(payload_6115_16, context_6115_16):\n if HANDLER_KIND_APPLY_INSECURE_TEMP_FILE_6115_16 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n descriptor, path = tempfile.mkstemp(prefix=\"pysecpatch-\", suffix=\".txt\", text=True)\n with os.fdopen(descriptor, \"w\", encoding=\"utf-8\") as handle:\n handle.write(context_6115_16)\n return path\n","vulnerable_lines":[1,8,9,10],"explanation":"A predictable path in a shared temporary directory can be pre-created or redirected.","patch_summary":"Create the file atomically with tempfile.mkstemp.","safe_test":"def test_insecure_temp_file_d8aac04f_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_temp_file_6115_16)\n assert '/tmp/' not in source\n assert 'mkstemp' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-352-8b75cd9ac5d5782c","family":"cwe-352-flask_csrf_validation-flask-val-module_dispatch","split":"val","language":"python","cwe":"CWE-352","vuln_type":"Missing CSRF validation","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9688_15 = \"defensive\"\n\ndef handle_flask_csrf_validation_9688_15(payload_9688_15, context_9688_15):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9688_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return payload_9688_15.form[\"amount\"]\n","fixed_code":"from secrets import compare_digest\n\nHANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9688_15 = \"defensive\"\n\ndef handle_flask_csrf_validation_9688_15(payload_9688_15, context_9688_15):\n if HANDLER_KIND_HANDLE_FLASK_CSRF_VALIDATION_9688_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n provided = payload_9688_15.headers.get(\"X-CSRF-Token\", \"\")\n expected = context_9688_15.get(\"csrf_token\", \"\")\n if not provided or not expected or not compare_digest(provided, expected):\n raise PermissionError(\"invalid CSRF token\")\n return payload_9688_15.form[\"amount\"]\n","vulnerable_lines":[1,6],"explanation":"A state-changing request is accepted without comparing a request token to the session token.","patch_summary":"Require both CSRF tokens and compare them in constant time.","safe_test":"def test_flask_csrf_validation_8b75cd9a_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_flask_csrf_validation_9688_15)\n assert 'compare_digest' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-96d5759de04181fb","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_9703_0 = \"defensive\"\n\ndef handle_http_response_splitting_9703_0(request_9703_0, scope_9703_0):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_9703_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_9703_0.headers[\"X-Next\"] = scope_9703_0\n return request_9703_0\n","fixed_code":"HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_9703_0 = \"defensive\"\n\ndef handle_http_response_splitting_9703_0(request_9703_0, scope_9703_0):\n if HANDLER_KIND_HANDLE_HTTP_RESPONSE_SPLITTING_9703_0 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in scope_9703_0 or \"\\n\" in scope_9703_0:\n raise ValueError(\"invalid header value\")\n request_9703_0.headers[\"X-Next\"] = scope_9703_0\n return request_9703_0\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_96d5759d_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_http_response_splitting_9703_0)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-a2124b04a36cbb76","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7676_15 = \"defensive\"\n\ndef handle_weak_cryptography_7676_15(subject_7676_15, policy_7676_15):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7676_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_7676_15.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7676_15 = \"defensive\"\n\ndef handle_weak_cryptography_7676_15(subject_7676_15, policy_7676_15):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_7676_15 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_7676_15.encode(\"utf-8\"), policy_7676_15, 200000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_a2124b04_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_7676_15)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-276-5bf3da94df9e9475","family":"cwe-276-insecure_file_permissions-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-276","vuln_type":"Insecure default file permissions","is_vulnerable":true,"vulnerable_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2101_28 = \"defensive\"\n\ndef apply_insecure_file_permissions_2101_28(request_2101_28, context_2101_28):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2101_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_2101_28).write_text(context_2101_28, encoding=\"utf-8\")\n os.chmod(request_2101_28, 0o777)\n return Path(request_2101_28)\n","fixed_code":"import os\nfrom pathlib import Path\n\nHANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2101_28 = \"defensive\"\n\ndef apply_insecure_file_permissions_2101_28(request_2101_28, context_2101_28):\n if HANDLER_KIND_APPLY_INSECURE_FILE_PERMISSIONS_2101_28 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n Path(request_2101_28).write_text(context_2101_28, encoding=\"utf-8\")\n os.chmod(request_2101_28, 0o600)\n return Path(request_2101_28)\n","vulnerable_lines":[10],"explanation":"A sensitive output file is made readable and writable by every local user.","patch_summary":"Restrict the file mode to its owner.","safe_test":"def test_insecure_file_permissions_5bf3da94_uses_safe_shape():\n import inspect\n source = inspect.getsource(apply_insecure_file_permissions_2101_28)\n assert '0o777' not in source\n assert '0o600' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-918-ead51a90d4aa947d","family":"cwe-918-httpx_client_ssrf-httpx-fastapi-val-module_dispatch","split":"val","language":"python","cwe":"CWE-918","vuln_type":"HTTPX server-side request forgery","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_4397_19 = \"defensive\"\n\ndef handle_httpx_client_ssrf_4397_19(request_4397_19, policy_4397_19, options_4397_19):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_4397_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return request_4397_19.get(policy_4397_19, timeout=10)\n","fixed_code":"from urllib.parse import urlparse\n\nHANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_4397_19 = \"defensive\"\n\ndef handle_httpx_client_ssrf_4397_19(request_4397_19, policy_4397_19, options_4397_19):\n if HANDLER_KIND_HANDLE_HTTPX_CLIENT_SSRF_4397_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n parsed = urlparse(policy_4397_19)\n if parsed.scheme != \"https\" or parsed.hostname not in set(options_4397_19):\n raise ValueError(\"destination is not allowed\")\n return request_4397_19.get(policy_4397_19, timeout=5, follow_redirects=False)\n","vulnerable_lines":[1,6],"explanation":"An HTTPX client fetches an arbitrary requester-controlled URL.","patch_summary":"Validate scheme and hostname and disable redirects before fetching.","safe_test":"def test_httpx_client_ssrf_ead51a90_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_httpx_client_ssrf_4397_19)\n assert 'follow_redirects=False' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-265f9607b324f07a","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":true,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3578_19 = \"defensive\"\n\ndef process_weak_cryptography_3578_19(subject_3578_19, context_3578_19):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3578_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n return hashlib.sha1(subject_3578_19.encode(\"utf-8\")).hexdigest()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3578_19 = \"defensive\"\n\ndef process_weak_cryptography_3578_19(subject_3578_19, context_3578_19):\n if HANDLER_KIND_PROCESS_WEAK_CRYPTOGRAPHY_3578_19 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", subject_3578_19.encode(\"utf-8\"), context_3578_19, 240000)\n return derived.hex()\n","vulnerable_lines":[8],"explanation":"A fast legacy digest is unsuitable for password derivation and enables inexpensive guessing.","patch_summary":"Use salted PBKDF2-HMAC-SHA256 with a substantial iteration count.","safe_test":"def test_weak_cryptography_265f9607_uses_safe_shape():\n import inspect\n source = inspect.getsource(process_weak_cryptography_3578_19)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-327-749d3f3750a864a4","family":"cwe-327-weak_cryptography-python-stdlib-val-module_dispatch","split":"val","language":"python","cwe":"CWE-327","vuln_type":"Weak cryptography","is_vulnerable":false,"vulnerable_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_9533_8 = \"defensive\"\n\ndef handle_weak_cryptography_9533_8(value_9533_8, context_9533_8):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_9533_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_9533_8.encode(\"utf-8\"), context_9533_8, 230000)\n return derived.hex()\n","fixed_code":"import hashlib\n\nHANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_9533_8 = \"defensive\"\n\ndef handle_weak_cryptography_9533_8(value_9533_8, context_9533_8):\n if HANDLER_KIND_HANDLE_WEAK_CRYPTOGRAPHY_9533_8 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n derived = hashlib.pbkdf2_hmac(\"sha256\", value_9533_8.encode(\"utf-8\"), context_9533_8, 230000)\n return derived.hex()\n","vulnerable_lines":[],"explanation":"Clean negative for CWE-327: the snippet already uses the expected defensive control.","patch_summary":"No code change is required.","safe_test":"def test_weak_cryptography_749d3f37_uses_safe_shape():\n import inspect\n source = inspect.getsource(handle_weak_cryptography_9533_8)\n assert 'sha1(' not in source\n assert 'pbkdf2_hmac' in source\n","source":"generated","source_license":"Apache-2.0"}
{"id":"psp-113-5fa2e6ec044ffa0d","family":"cwe-113-http_response_splitting-web-api-val-module_dispatch","split":"val","language":"python","cwe":"CWE-113","vuln_type":"HTTP response splitting","is_vulnerable":true,"vulnerable_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_5489_21 = \"defensive\"\n\ndef load_http_response_splitting_5489_21(request_5489_21, context_5489_21):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_5489_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n request_5489_21.headers[\"X-Next\"] = context_5489_21\n return request_5489_21\n","fixed_code":"HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_5489_21 = \"defensive\"\n\ndef load_http_response_splitting_5489_21(request_5489_21, context_5489_21):\n if HANDLER_KIND_LOAD_HTTP_RESPONSE_SPLITTING_5489_21 != \"defensive\":\n raise RuntimeError(\"invalid handler mode\")\n if \"\\r\" in context_5489_21 or \"\\n\" in context_5489_21:\n raise ValueError(\"invalid header value\")\n request_5489_21.headers[\"X-Next\"] = context_5489_21\n return request_5489_21\n","vulnerable_lines":[6],"explanation":"Untrusted header content can contain CR or LF delimiters.","patch_summary":"Reject header values containing carriage returns or line feeds.","safe_test":"def test_http_response_splitting_5fa2e6ec_uses_safe_shape():\n import inspect\n source = inspect.getsource(load_http_response_splitting_5489_21)\n assert 'invalid header value' in source\n","source":"generated","source_license":"Apache-2.0"}