Skip to content

Hub: detect unverified JWT decoding and reflected-origin CORS with credentials - #2389

Merged
remigiusz-antczak merged 3 commits into
mainfrom
feat/hub-jwt-cors-22
Nov 16, 2026
Merged

remigiusz-antczak merged 3 commits into
mainfrom
feat/hub-jwt-cors-22

Conversation

@remigiusz-antczak

Copy link
Copy Markdown
Collaborator

Adds two bench classes to bench/tool-only, each a vulnerable file paired with a clean twin: CWE-347 (a JWT decoded without verification, JavaScript) and CWE-942 (a reflected Origin sent with credentials, Python and JavaScript). Where no hub tool caught the vulnerable file, a perun rule fills the gap: perun.js.jwt-decode-unverified, perun.py.cors-reflected-origin and perun.js.cors-reflected-origin. perun.py.jwt-unverified also follows options passed as a dict variable, dict(verify_signature=False), and jwt.decode_complete.

Two independent review passes probed the rules for bypasses. Fixes:

  • The Flask headers.set(...) form, lowercase header names and a Python True credentials value now match.
  • JS res.setHeader, res.header and res.set match, including the object form, as does Python headers.update({...}).
  • Origin read through a two-level prefix (ctx.request.headers.origin) now matches.
  • A metavariable-regex that was not enforced was replaced with literal patterns.
  • A "verify anywhere in the same function" suppression on the decode rule was bypassable (verify of another token, verify after use, dead code, unrelated receiver), so it is removed. Decode-then-verify (a kid lookup) is now an accepted, labelled false positive.

Known limits, documented in the rule messages:

  • An aliased or bracket-accessed decode is not matched.
  • An Origin read into a local variable first is not followed.
  • Credentials and reflection set in different functions are not linked.
  • A guarded reflection still reports.
  • An options dict whose verification is turned back on before use still reports.

Bench measured locally: recall 20/20 (1.0); MAX_FALSE_POSITIVES stays at 31.

Tests: 13/13 scripts/test_semgrep_*.py plus test_insecure_defaults and bench_tool_only (recall 1.0)
🤖 Generated with Claude Code

remigiusz-antczak and others added 3 commits November 16, 2026 09:49
…he gaps

Adds three vuln files and clean twins to bench/tool-only: jsonwebtoken jwt.decode used as verify (CWE-347), a Flask handler that reflects the request Origin next to credentials true (CWE-942) and Express cors with origin true and credentials true (CWE-942). The Python JWT case was already seeded.

Existing coverage caught the Express CORS file (perun.js.cors-credentials-any-origin). Two real gaps got rules in defaults.yml: perun.js.jwt-decode-unverified and perun.py.cors-reflected-origin, each with ruleid and ok cases in test_semgrep_defaults.py. Known limit of the CORS rule: an Origin read into a local variable first is not followed.

Measured locally with the tools installed here: recall 20/20 (1.0), 11 noise rows on the clean twins and none from the new twins, so MAX_FALSE_POSITIVES stays 31.

Tests: 13/13 scripts/test_semgrep_*.py plus test_insecure_defaults and bench_tool_only (recall 1.0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Review of the wave-22 rules found bypasses. perun.py.cors-reflected-origin now matches the headers.set(...) form, case-insensitive header names and a Python True credentials value. New perun.js.cors-reflected-origin covers res.setHeader, res.header and res.set sending req.headers.origin or req.get('origin') next to Access-Control-Allow-Credentials true. perun.py.jwt-unverified now follows an options dict assigned in the same function with verify_signature False.

perun.js.jwt-decode-unverified drops the metavariable-regex, which was not enforcing (j.decode and jwt2.decode were flagged), for literal patterns: jwt.decode, jsonwebtoken.decode, require("jsonwebtoken").decode and this.jwt.decode. A decode in a function that also calls verify (a kid lookup before verification) is no longer reported.

Known limits, documented in the rule messages: an aliased decode (const d = jwt.decode; d(t)) and jwt['decode'](t) are not matched; an Origin read into a local variable first is not followed; a guard such as an early return for an unlisted origin does not silence the CORS findings, because guard suppression was bypassable before; any verify call in the same function suppresses the decode finding.

Every item has ruleid and ok cases in test_semgrep_defaults.py. Bench measured locally: recall 20/20 (1.0), 11 noise rows, MAX_FALSE_POSITIVES stays 31.

Tests: 13/13 scripts/test_semgrep_*.py plus test_insecure_defaults and bench_tool_only (recall 1.0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
perun.js.jwt-decode-unverified no longer goes silent when the same function calls verify. That suppression was bypassable: verify of a different token, decode before verify, verify under if (false) and an unrelated v.verify all silenced a real finding. A decode followed by a verify of the same token (a kid lookup) is now accepted noise, documented in the rule message and kept as a ruleid case labelled accepted noise. Every reported bypass is a ruleid case too.

The reflected-origin rules now match a ctx.request.headers.origin prefix, the Python headers.update({...}) form and the JS res.set({...}) object form when the object holds both the reflected origin and credentials true. perun.py.jwt-unverified now covers options=dict(verify_signature=False), jwt.decode_complete with a literal dict, and an options dict or dict() call assigned earlier in the same function.

Known limits, in the rule messages: credentials and reflection split across functions, an Origin read into a local variable first, a guard that returns early for an unlisted origin, an options dict whose verification is turned back on before use, an aliased decode and jwt['decode'](t).

Bench measured locally: recall 20/20 (1.0), 11 noise rows, MAX_FALSE_POSITIVES stays 31.

Tests: 13/13 scripts/test_semgrep_*.py plus test_insecure_defaults and bench_tool_only (recall 1.0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@remigiusz-antczak
remigiusz-antczak merged commit e465c18 into main Nov 16, 2026
13 checks passed
@remigiusz-antczak
remigiusz-antczak deleted the feat/hub-jwt-cors-22 branch November 16, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant