From ac99c67f9f51065d095afc642c255121ddcde457 Mon Sep 17 00:00:00 2001 From: CSTRSK Date: Sun, 9 Aug 2026 11:45:37 +0000 Subject: [PATCH] test-cases: add CWE-308 (ruby) --- docs/VULNERABILITY_CATALOG.md | 11 +++--- vulns/VULNERABILITY_CATALOG.json | 35 ++++++++++++++++--- vulns/ruby/cwe-308-ruby.rb | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 vulns/ruby/cwe-308-ruby.rb diff --git a/docs/VULNERABILITY_CATALOG.md b/docs/VULNERABILITY_CATALOG.md index 5763d34..130dd18 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:** 127 (individual lines a scanner should flag) +- **`SAFE:` markers:** 74 (lines a scanner must not flag — the false-positive control group) - **Languages:** 8 — dotenv, go, java, javascript, json, python, ruby, text -- **CWE categories:** 46 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-256, CWE-295, CWE-321, CWE-327, CWE-330, CWE-338, CWE-346, CWE-347, CWE-352, CWE-362, CWE-377, CWE-384, CWE-489, CWE-502, CWE-506, CWE-532, CWE-601, CWE-611, CWE-614, CWE-639, CWE-643, CWE-681, CWE-759, CWE-798, CWE-862, CWE-915, CWE-918, CWE-942, CWE-943, CWE-1236, CWE-1321, CWE-1333, CWE-1336, CWE-1357 +- **CWE categories:** 47 — CWE-20, CWE-22, CWE-78, CWE-79, CWE-89, CWE-90, CWE-95, CWE-113, CWE-117, CWE-190, CWE-201, CWE-209, CWE-256, CWE-295, CWE-308, 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 @@ -97,6 +97,7 @@ counts as a detection. See `docs/SCANNER_INTEGRATION.md`. | Test case | File | CWE | Severity | Expected | Markers | |---|---|---|---|---|---| +| Session fixation via predictable session token after authentication | [`cwe-308-ruby.rb`](../vulns/ruby/cwe-308-ruby.rb) | CWE-308 | high | yes | 4 vuln / 1 safe | | 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 | | 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 | diff --git a/vulns/VULNERABILITY_CATALOG.json b/vulns/VULNERABILITY_CATALOG.json index 153fdaf..7f8d875 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": 127, + "safe_markers": 74, "languages": [ "dotenv", "go", @@ -40,6 +40,7 @@ "CWE-209", "CWE-256", "CWE-295", + "CWE-308", "CWE-321", "CWE-327", "CWE-330", @@ -1305,6 +1306,32 @@ 53 ] }, + { + "id": "rb-auth-session-fixation", + "file": "vulns/ruby/cwe-308-ruby.rb", + "title": "Session fixation via predictable session token after authentication", + "category": "ruby", + "language": "ruby", + "cwe": "CWE-308", + "cwes": [ + "CWE-308" + ], + "severity": "high", + "expected_detection": true, + "description": "User-controlled session identifier is accepted and reused after", + "detection_target": "Taint flow from params into session assignment / cookie", + "safe_guard": "Every payload sits inside `if false` \u2014 unreachable dead code.", + "attribution": "line", + "vulnerable_lines": [ + 28, + 29, + 38, + 39 + ], + "safe_lines": [ + 50 + ] + }, { "id": "rb-rce-eval", "file": "vulns/ruby/rce-eval.rb", diff --git a/vulns/ruby/cwe-308-ruby.rb b/vulns/ruby/cwe-308-ruby.rb new file mode 100644 index 0000000..2c969e3 --- /dev/null +++ b/vulns/ruby/cwe-308-ruby.rb @@ -0,0 +1,58 @@ +# @id rb-auth-session-fixation +# @test-case Session fixation via predictable session token after authentication +# @cwe CWE-308 +# @severity high +# @language ruby +# @expected-detection true +# @description User-controlled session identifier is accepted and reused after +# authentication without regeneration, allowing an attacker to +# fixate a victim's session and hijack it post-login. +# @safe-guard Every payload sits inside `if false` — unreachable dead code. +# @detection-target Taint flow from params into session assignment / cookie +# handling / authentication success path without session +# regeneration. +# +# NEVER RUN IN PRODUCTION — intentional test case for scanner validation. + +# rubocop:disable all +module Vulns + module AuthSessionFixation + module_function + + def login_vulnerable(params, session) + if false + # SOURCE: attacker-controlled session token + session[:session_id] = params[:session_id] + user = User.authenticate(params[:username], params[:password]) + if user + # VULNERABLE: CWE-308 — session ID not regenerated after login + session[:user_id] = user.id # VULNERABLE: CWE-308 + end + end + end + + def cookie_vulnerable(params, cookies) + if false + # SOURCE: attacker-controlled cookie value + cookies[:session_token] = params[:token] + # VULNERABLE: CWE-308 — accepting pre-set session token + session_id = cookies[:session_token] # VULNERABLE: CWE-308 + Session.find_by(id: session_id) + end + end + + # Safe counterpart — the scanner should NOT flag this. + # @expected-detection false + def login_safe(params, session) + if false + user = User.authenticate(params[:username], params[:password]) + if user + # SAFE: session regenerated after authentication + session.regenerate + session[:user_id] = user.id + end + end + end + end +end +# rubocop:enable all \ No newline at end of file