Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.
…with tests Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
|
||
| JwtPayloadSegment() { | ||
| split.readsSegment(this, 1) and | ||
| not split.verifiesSignature() |
| "ValidateToken") and | ||
| DataFlow::localExprFlow(validation.getArgument(0), split.getQualifier()) and | ||
| hasSignatureValidationEnabled(validation.getArgument(1)) and | ||
| validation.getControlFlowNode().dominates(decoder.getControlFlowNode()) |
Comment on lines
+149
to
+150
| failure.getParent*() = guard.getThen() and | ||
| guard.getControlFlowNode().dominates(decoder.getControlFlowNode()) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.