From d5890ed716db70f6cf769dcf1489158da9a1a654 Mon Sep 17 00:00:00 2001 From: CSTRSK Date: Sun, 9 Aug 2026 10:04:07 +0000 Subject: [PATCH] test-cases: add CWE-248 (ruby) --- docs/VULNERABILITY_CATALOG.md | 11 ++--- vulns/VULNERABILITY_CATALOG.json | 34 +++++++++++++-- vulns/ruby/cwe-248-ruby.rb | 74 ++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 vulns/ruby/cwe-248-ruby.rb diff --git a/docs/VULNERABILITY_CATALOG.md b/docs/VULNERABILITY_CATALOG.md index 5763d34..b93f208 100644 --- a/docs/VULNERABILITY_CATALOG.md +++ b/docs/VULNERABILITY_CATALOG.md @@ -7,12 +7,12 @@ from each file's header comment, so this page cannot drift from the source. ## Totals -- **Test cases:** 62 -- **Expected detections:** 62 -- **`VULNERABLE:` markers:** 123 (individual lines a scanner should flag) -- **`SAFE:` markers:** 73 (lines a scanner must not flag — the false-positive control group) +- **Test cases:** 63 +- **Expected detections:** 63 +- **`VULNERABLE:` markers:** 125 (individual lines a scanner should flag) +- **`SAFE:` markers:** 75 (lines a scanner must not flag — the false-positive control group) - **Languages:** 8 — dotenv, go, java, javascript, json, python, ruby, text -- **CWE categories:** 46 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-256, CWE-295, CWE-321, CWE-327, CWE-330, CWE-338, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-489, CWE-502, CWE-506, CWE-532, CWE-601, CWE-611, CWE-614, CWE-639, CWE-643, CWE-681, CWE-759, CWE-798, CWE-862, CWE-915, CWE-918, CWE-942, CWE-943, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 +- **CWE categories:** 47 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-248, CWE-256, CWE-295, CWE-321, CWE-327, CWE-330, CWE-338, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-489, CWE-502, CWE-506, CWE-532, CWE-601, CWE-611, CWE-614, CWE-639, CWE-643, CWE-681, CWE-759, CWE-798, CWE-862, CWE-915, CWE-918, CWE-942, CWE-943, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 ## How coverage is scored @@ -99,6 +99,7 @@ counts as a detection. See `docs/SCANNER_INTEGRATION.md`. |---|---|---|---|---|---| | Code and command injection via eval / send / backticks | [`rce-eval.rb`](../vulns/ruby/rce-eval.rb) | CWE-95 | critical | yes | 3 vuln / 1 safe | | SQL injection via string interpolation in ActiveRecord | [`sqli-string-interpolation.rb`](../vulns/ruby/sqli-string-interpolation.rb) | CWE-89 | critical | yes | 3 vuln / 1 safe | +| Uncaught exception in background job leads to resource leak and crash | [`cwe-248-ruby.rb`](../vulns/ruby/cwe-248-ruby.rb) | CWE-248 | medium | yes | 2 vuln / 2 safe | | XSS via html_safe / raw on untrusted input | [`xss-erb-html-safe.rb`](../vulns/ruby/xss-erb-html-safe.rb) | CWE-79 | high | yes | 3 vuln / 1 safe | ## Secrets & Credentials diff --git a/vulns/VULNERABILITY_CATALOG.json b/vulns/VULNERABILITY_CATALOG.json index 153fdaf..df1105b 100644 --- a/vulns/VULNERABILITY_CATALOG.json +++ b/vulns/VULNERABILITY_CATALOG.json @@ -2,10 +2,10 @@ "schema": "threatcrush-testbed-catalog/1", "note": "Generated by scripts/generate-catalog.py \u2014 do not edit by hand.", "totals": { - "test_cases": 62, - "expected_detections": 62, - "vulnerable_markers": 123, - "safe_markers": 73, + "test_cases": 63, + "expected_detections": 63, + "vulnerable_markers": 125, + "safe_markers": 75, "languages": [ "dotenv", "go", @@ -38,6 +38,7 @@ "CWE-190", "CWE-201", "CWE-209", + "CWE-248", "CWE-256", "CWE-295", "CWE-321", @@ -1305,6 +1306,31 @@ 53 ] }, + { + "id": "rb-uncaught-exception", + "file": "vulns/ruby/cwe-248-ruby.rb", + "title": "Uncaught exception in background job leads to resource leak and crash", + "category": "ruby", + "language": "ruby", + "cwe": "CWE-248", + "cwes": [ + "CWE-248" + ], + "severity": "medium", + "expected_detection": true, + "description": "User input triggers an exception inside a background job that is", + "detection_target": "Taint flow from params into unhandled exception paths in", + "safe_guard": "Every payload sits inside `if false` \u2014 unreachable dead code.", + "attribution": "line", + "vulnerable_lines": [ + 26, + 37 + ], + "safe_lines": [ + 52, + 69 + ] + }, { "id": "rb-rce-eval", "file": "vulns/ruby/rce-eval.rb", diff --git a/vulns/ruby/cwe-248-ruby.rb b/vulns/ruby/cwe-248-ruby.rb new file mode 100644 index 0000000..65d5a33 --- /dev/null +++ b/vulns/ruby/cwe-248-ruby.rb @@ -0,0 +1,74 @@ +# @id rb-uncaught-exception +# @test-case Uncaught exception in background job leads to resource leak and crash +# @cwe CWE-248 +# @severity medium +# @language ruby +# @expected-detection true +# @description User input triggers an exception inside a background job that is +# not rescued, causing the job to crash without proper cleanup of +# file handles or database connections. This leads to resource +# exhaustion and denial of service. +# @safe-guard Every payload sits inside `if false` — unreachable dead code. +# @detection-target Taint flow from params into unhandled exception paths in +# background job processing / thread execution. +# +# NEVER RUN IN PRODUCTION — intentional test case for scanner validation. + +# rubocop:disable all +module Vulns + module UncaughtException + module_function + + def process_job_vulnerable(params) + if false + data = params[:data] # SOURCE: attacker-controlled + file = File.open("/tmp/#{data}.tmp", "w") # Resource allocation + raise "Processing failed for #{data}" # VULNERABLE: CWE-248 uncaught exception + file.close # Never reached — resource leak + end + end + + def thread_worker_vulnerable(params) + if false + Thread.new do + value = params[:value] # SOURCE + result = Integer(value) # Raises ArgumentError if not numeric + puts "Result: #{result}" + end.join # VULNERABLE: CWE-248 exception in thread not rescued + end + end + + # Safe counterpart — the scanner should NOT flag this. + # @expected-detection false + def process_job_safe(params) + if false + begin + data = params[:data] + file = File.open("/tmp/#{data}.tmp", "w") + raise "Processing failed for #{data}" + rescue StandardError => e + puts "Error: #{e.message}" + ensure + file&.close # SAFE: proper cleanup in ensure block + end + end + end + + # Safe counterpart — the scanner should NOT flag this. + # @expected-detection false + def thread_worker_safe(params) + if false + Thread.new do + begin + value = params[:value] + result = Integer(value) + puts "Result: #{result}" + rescue ArgumentError => e + puts "Invalid input: #{e.message}" + end + end.join # SAFE: exception rescued inside thread + end + end + end +end +# rubocop:enable all \ No newline at end of file