Skip to content

JWT Claim Fuzzing

SeverityMedium
Classifications
OWASP Category

OWASP API8:2023 Security Misconfiguration

APIs that decode JWT claims into typed fields (structs, ORMs, template variables, SQL parameters, …) don’t always validate a claim’s type or length before using it. If a claim that’s normally a short string arrives as a number, an array, an oversized string, or null, the server may throw an unhandled exception, leak a stack trace, or respond very differently in size — all signs the claim was consumed without validation, and a starting point for further exploitation (denial of service, information disclosure, or worse if the value reaches a template engine, SQL query, or shell).

For more details, you can refer to the jwtop documentation on Claim Fuzzing.

Unlike the other JWT vulnerabilities documented here, this isn’t a single crafted exploit but a fuzzing pass: every claim is mutated with a battery of edge-case values and each response is compared against a reference response captured from the original, unmutated token.

  • Type confusion: a claim that’s normally a string, number, or boolean is replaced with a different JSON type — a number, a float, a boolean, an array, or an object.
  • Oversized string: a claim is replaced with a very long string (10,000 characters by default) to probe for buffer or allocation issues.
  • Special characters: a claim is replaced with a payload exercising common injection and encoding edge cases — SQL injection, XSS, path traversal, null bytes, format strings, CRLF injection, Unicode direction overrides, and command injection.
  • Null value: a claim is replaced with a literal JSON null.

Given a token with the claim "sub": "user123", VulnAPI tries mutations such as:

"sub": ["user123"]
"sub": 1337
"sub": {"a":"b"}
"sub": true
"sub": "AAAA..." // 10,000 characters
"sub": "' OR '1'='1"
"sub": "<script>alert(1)</script>"
"sub": "../../../../etc/passwd"
"sub": "${7*7}{{7*7}}"
"sub": null

Each mutated token is sent to the target and the response is compared against the reference response captured from the original token. A mutation is flagged when:

  • the response status is 5xx
  • the response body matches a known stack-trace/unhandled-exception signature (e.g. Traceback (most recent call last), panic: ... goroutine, NullPointerException, Whitelabel Error Page, …)
  • the response body length differs from the reference by more than 50%

If the JWT Weak Secret check cracks an HMAC secret first, mutated tokens are re-signed with it, so the fuzzing also reaches handlers that verify the signature rather than only rejecting it outright.

If you want to test only the “JWT Claim Fuzzing” vulnerability, you can use the following command:

Terminal window
vulnapi scan curl [url] -H "Authorization: Bearer eyJhbGciOiJSUzUxMiI..." --scans jwt.fuzz

VulnAPI supports scanning against various types of other JWT vulnerabilities as well.

  • Denial of service: an unhandled exception on every request carrying a malformed claim can crash a worker process or exhaust resources on an oversized value.
  • Information disclosure: a leaked stack trace can reveal internal file paths, framework/library versions, database schema, or other details useful for further attacks.
  • Downstream injection: if a claim value reaches a SQL query, shell command, or template engine without sanitization, the special-character payloads used here are a starting point for SQL injection, command injection, or server-side template injection.
  1. Validate claim types and lengths after decoding, before using them — don’t assume a claim you expect to be a short string actually is one.
  2. Use a schema or typed struct to decode claims (many JWT libraries support this) so an unexpected type fails decoding cleanly instead of propagating into application logic.
  3. Return generic error responses for malformed input — never let a stack trace or exception message reach the client.
  4. Bound claim sizes at the API gateway or middleware layer (e.g. reject requests where the token or an individual claim exceeds a sane length) before they reach application code.
  5. Sanitize/parameterize any claim value used in a SQL query, shell command, template, or log line, the same as any other untrusted user input.