You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a C# query that reports code that splits a JWT on . and base64-decodes the payload segment when nothing shows the signature was checked (CWE-345, CWE-347). Anyone can create a token with any claims, so claims read this way can be forged.
No existing query covers this. The queries in csharp/src/security/JsonWebTokenHandler/ and the standard C# queries only inspect TokenValidationParameters and validation delegates.
Source: element [1] of a Split('.') or Split(".") result, found by local flow from the call.
Sinks: the first argument of:
Convert.FromBase64String and Convert.TryFromBase64String
Base64UrlEncoder.Decode and Base64UrlEncoder.DecodeBytes
WebEncoders.Base64UrlDecode
Flow: global taint tracking, so PadRight, Replace and helper methods are followed.
Manual-verification exclusion: a source is dropped when element [2] of the same Split result, or its decoded bytes, reaches a comparison operator or an argument of a method whose name contains verify or equals.
Logging the signature does not count.
The last step uses local taint because CryptographicOperations.FixedTimeEquals takes ReadOnlySpan<byte>. The implicit byte[] conversion breaks plain local flow and would otherwise flag correct HMAC checks.
Library-validation exclusion: the decode is not reported when one of these runs before it, checked by control-flow-node dominance:
JwtSecurityTokenHandler.ValidateToken on the same token.
JsonWebTokenHandler.ValidateTokenAsync on the same token, followed by an if (!result.IsValid) throw check.
In both cases the TokenValidationParameters initializer must set ValidateIssuerSigningKey = true and IssuerSigningKey.
Metadata:path-problem, precision medium, security-severity 8.1, tagged experimental. The default csharp.qls suite selects it.
Query help:.qhelp with BAD and GOOD samples and a known-limitations section.
Inline expectations: cases are marked // $ Alert and // $ Source. There are 11 BAD cases (one per sink, helper flow, logged signature, decode before validation, disabled signing-key validation, unchecked async result) and 7 GOOD ones (header-only decode, HMAC with FixedTimeEquals, != comparison, library validation sync and async, non-. split).
Stubs: only the shared stubs under codeql/csharp/ql/test/resources/stubs (JWT 7.7.1, Newtonsoft.Json, ASP.NET Core). There is no custom stub file.
New csharp/test/TestUtilities/InlineExpectationsTestQuery.ql: a thin wrapper around the upstream post-processor. The copy in the cached codeql/csharp-all package cannot be compiled from a qlref in this repository.
For review
Security or audit: the query does not show the token is attacker-controlled. A token already validated elsewhere (remote service, middleware, custom helper, indirectly built parameters) is still reported. Please confirm that medium precision in the default suite is right; the alternative is audit/ at very-low precision.
Detection limits: only Split with a . literal is recognized. The synchronous JsonWebTokenHandler.ValidateToken is not treated as validation.
True positive from a real project: to be added by the maintainer.
Follow-up: bump the version of githubsecuritylab/codeql-csharp-queries at release.
felickz
changed the title
[WIP] Add query for JWT payload decoding without signature check
[New Query - githubsecuritylab/cs/unverified-jwt-payload-decode] - JWT payload decoded without signature verification
Nov 26, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical suppression flaws can hide unverified JWT claim use when signature checks are late or optional, validation failures are caught, or invalid-result rejection is conditional.
@copilot Please address the three open review findings, each with a regression case in the test:
Exclude only decodes that verification dominates: tie the exclusion to the source and decode pair, and drop a result only when the read of the signature segment dominates the decode. Add a late check and an optional check (if (checkSignature)) as alerts.
Require successful validation: a validation call whose failure is caught and ignored must not suppress the result. Add the caught failure as an alert.
Require the valid-result check to guard the decode: suppress only when the decode is reached solely through the valid branch, not when a throw merely exists in the invalid branch. Add the conditional throw as an alert.
Keep these checks local to the method (dominance and guards), without another global flow. Rerun the test and the gates of your profile, and report the alert count before and after. The Build CodeQL Packs run on the current head is still in progress: check its result and fix any failure.
Fixed in 585b6cb. Targeted alerts: 11 before → 31 after, including the added regressions. Pinned-CLI test, strict compile, format, help and suite checks passed. The original-head Build CodeQL Packs run and results validation passed; the new commit has not yet been covered by that run.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A critical finding remains: the Boolean status from Convert.TryFromBase64String is treated as decoded signature data, suppressing alerts for arbitrary base64-decodable signatures without verification.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Convert.TryFromBase64String returns a Boolean status, but this branch treats it as decoded…
Convert.TryFromBase64String returns a Boolean status, but this branch treats it as decoded signature data. Consequently, if (Convert.TryFromBase64String(parts[2], buffer, out var n) == true) return Base64UrlEncoder.Decode(parts[1]); suppresses the alert even though an arbitrary base64-decodable signature passes the check. Exclude this status return from signature values and add a regression for this case; any support for decoded signature bytes should track the output buffer instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a C# query that reports code that splits a JWT on
.and base64-decodes the payload segment when nothing shows the signature was checked (CWE-345, CWE-347). Anyone can create a token with any claims, so claims read this way can be forged.No existing query covers this. The queries in
csharp/src/security/JsonWebTokenHandler/and the standard C# queries only inspectTokenValidationParametersand validation delegates.Query (
csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.ql)Source: element
[1]of aSplit('.')orSplit(".")result, found by local flow from the call.Sinks: the first argument of:
Convert.FromBase64StringandConvert.TryFromBase64StringBase64UrlEncoder.DecodeandBase64UrlEncoder.DecodeBytesWebEncoders.Base64UrlDecodeFlow: global taint tracking, so
PadRight,Replaceand helper methods are followed.Manual-verification exclusion: a source is dropped when element
[2]of the sameSplitresult, or its decoded bytes, reaches a comparison operator or an argument of a method whose name containsverifyorequals.CryptographicOperations.FixedTimeEqualstakesReadOnlySpan<byte>. The implicitbyte[]conversion breaks plain local flow and would otherwise flag correct HMAC checks.Library-validation exclusion: the decode is not reported when one of these runs before it, checked by control-flow-node dominance:
JwtSecurityTokenHandler.ValidateTokenon the same token.JsonWebTokenHandler.ValidateTokenAsyncon the same token, followed by anif (!result.IsValid) throwcheck.In both cases the
TokenValidationParametersinitializer must setValidateIssuerSigningKey = trueandIssuerSigningKey.Metadata:
path-problem, precisionmedium, security-severity8.1, taggedexperimental. The defaultcsharp.qlssuite selects it.Query help:
.qhelpwith BAD and GOOD samples and a known-limitations section.Tests (
csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/)// $ Alertand// $ Source. There are 11 BAD cases (one per sink, helper flow, logged signature, decode before validation, disabled signing-key validation, unchecked async result) and 7 GOOD ones (header-only decode, HMAC withFixedTimeEquals,!=comparison, library validation sync and async, non-.split).codeql/csharp/ql/test/resources/stubs(JWT 7.7.1, Newtonsoft.Json, ASP.NET Core). There is no custom stub file.csharp/test/TestUtilities/InlineExpectationsTestQuery.ql: a thin wrapper around the upstream post-processor. The copy in the cachedcodeql/csharp-allpackage cannot be compiled from a qlref in this repository.For review
audit/at very-low precision.Splitwith a.literal is recognized. The synchronousJsonWebTokenHandler.ValidateTokenis not treated as validation.githubsecuritylab/codeql-csharp-queriesat release.