diff --git a/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.qhelp b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.qhelp new file mode 100644 index 00000000..54625d39 --- /dev/null +++ b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.qhelp @@ -0,0 +1,76 @@ + + + + +

+A JSON Web Token (JWT) has three base64url-encoded segments separated by .: a header, a payload +with the claims, and a signature. The claims can only be trusted after the signature has been checked against +a trusted key. Anyone can create a token with any payload, for example one that claims an administrator role. +

+

+This query reports code that splits a token on . and base64-decodes the payload segment +(index 1) without evidence that the signature has been verified. Claims that are decoded without +being authenticated can be forged. +

+
+ + +

+Do not parse JWT claims by hand. Use a JWT library such as +System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken or +Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler.ValidateTokenAsync, with +TokenValidationParameters that require a valid signature, and read the claims from the validated result. +

+

+If the token was already validated somewhere else, for example by a remote authentication service, read the +claims from that validated result, not from the raw token string. +

+
+ + +

+In the following example, the payload is decoded and the roles claim is trusted without checking the +signature. An attacker can send a forged token with "roles": ["ADMIN"]: +

+ + + +

+The following example validates the token signature before it reads any claims: +

+ + +
+ +
+ +
+ + +
  • CWE: CWE-345: Insufficient Verification of Data Authenticity.
  • +
  • CWE: CWE-347: Improper Verification of Cryptographic Signature.
  • +
  • IETF: RFC 7519: JSON Web Token (JWT).
  • +
  • OWASP: JSON Web Token Cheat Sheet.
  • +
    + +
    diff --git a/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.ql b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.ql new file mode 100644 index 00000000..4b29cbff --- /dev/null +++ b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.ql @@ -0,0 +1,170 @@ +/** + * @name JWT payload decoded without signature verification + * @description Base64-decoding the payload segment of a JSON Web Token without verifying + * the token signature lets an attacker forge claims such as roles or user + * identifiers. + * @kind path-problem + * @problem.severity error + * @security-severity 8.1 + * @precision medium + * @id githubsecuritylab/cs/unverified-jwt-payload-decode + * @tags security + * experimental + * external/cwe/cwe-345 + * external/cwe/cwe-347 + */ + +import csharp +import semmle.code.csharp.dataflow.TaintTracking +import UnverifiedJwtPayloadDecodeFlow::PathGraph + +/** A call to `string.Split` whose separator is the JWT segment separator `.`. */ +class JwtSplitCall extends MethodCall { + JwtSplitCall() { + this.getTarget().hasFullyQualifiedName("System", "String", "Split") and + exists(Expr sep | sep = this.getArgument(0) | + sep.(CharLiteral).getValue() = "." + or + sep.(StringLiteral).getValue() = "." + ) + } + + /** Holds if `aa` reads segment `index` of the result of this call. */ + predicate readsSegment(ArrayAccess aa, int index) { + DataFlow::localExprFlow(this, aa.getQualifier()) and + aa.getIndex(0).getValue().toInt() = index + } + + /** + * Gets an expression that holds the signature segment, or its decoded value. Local taint + * steps follow conversions such as `byte[]` to `ReadOnlySpan`. + */ + private Expr getASignatureValue() { + exists(ArrayAccess signature | this.readsSegment(signature, 2) | + TaintTracking::localExprTaint(signature, result) + or + exists(Base64DecodeCall decoder | + DataFlow::localExprFlow(signature, decoder.getArgument(0)) and + TaintTracking::localExprTaint(decoder, result) + ) + ) + } + + /** + * Holds if the signature segment flows into a comparison, or into an argument of a + * method whose name contains `verify` or `equals`. + */ + predicate verifiesSignature() { + exists(ComparisonOperation comparison | this.getASignatureValue() = comparison.getAnOperand()) + or + exists(MethodCall verification | + this.getASignatureValue() = verification.getAnArgument() and + verification.getTarget().getName().toLowerCase().matches(["%verify%", "%equals%"]) + ) + } +} + +/** + * An access to the payload segment (index 1) of a JWT split on `.`, where the + * signature segment (index 2) is not used in a verification-like operation. + */ +class JwtPayloadSegment extends ArrayAccess { + JwtSplitCall split; + + JwtPayloadSegment() { + split.readsSegment(this, 1) and + not split.verifiesSignature() + } + + /** Gets the `Split` call whose result this access reads. */ + JwtSplitCall getSplitCall() { result = split } +} + +/** A call to a base64 decoding method. */ +class Base64DecodeCall extends MethodCall { + Base64DecodeCall() { + this.getTarget() + .hasFullyQualifiedName("System", "Convert", ["FromBase64String", "TryFromBase64String"]) + or + this.getTarget() + .hasFullyQualifiedName("Microsoft.IdentityModel.Tokens", "Base64UrlEncoder", + ["Decode", "DecodeBytes"]) + or + this.getTarget() + .hasFullyQualifiedName("Microsoft.AspNetCore.WebUtilities", "WebEncoders", "Base64UrlDecode") + } +} + +/** + * Holds if `parameters` comes from a `TokenValidationParameters` object creation whose + * initializer enables `ValidateIssuerSigningKey` and sets `IssuerSigningKey`. + */ +predicate hasSignatureValidationEnabled(Expr parameters) { + exists( + ObjectCreation creation, ObjectInitializer initializer, MemberInitializer enabled, + MemberInitializer key + | + DataFlow::localExprFlow(creation, parameters) and + initializer = creation.getInitializer() and + enabled = initializer.getAMemberInitializer() and + enabled.getLeftOperand().(PropertyAccess).getTarget().hasName("ValidateIssuerSigningKey") and + enabled.getRightOperand().(BoolLiteral).getBoolValue() = true and + key = initializer.getAMemberInitializer() and + key.getLeftOperand().(PropertyAccess).getTarget().hasName("IssuerSigningKey") + ) +} + +/** + * Holds if the token whose payload is `payload` is validated by a JWT library, with + * signing key validation enabled, before `decoder` runs. + */ +predicate validatedBeforeDecode(JwtPayloadSegment payload, Base64DecodeCall decoder) { + exists(JwtSplitCall split, MethodCall validation | + split = payload.getSplitCall() and + validation + .getTarget() + .hasFullyQualifiedName("System.IdentityModel.Tokens.Jwt", "JwtSecurityTokenHandler", + "ValidateToken") and + DataFlow::localExprFlow(validation.getArgument(0), split.getQualifier()) and + hasSignatureValidationEnabled(validation.getArgument(1)) and + validation.getControlFlowNode().dominates(decoder.getControlFlowNode()) + ) + or + exists( + JwtSplitCall split, MethodCall validation, AwaitExpr awaited, IfStmt guard, + LogicalNotExpr invalidResult, PropertyAccess isValid, ThrowStmt failure + | + split = payload.getSplitCall() and + validation + .getTarget() + .hasFullyQualifiedName("Microsoft.IdentityModel.JsonWebTokens", "JsonWebTokenHandler", + "ValidateTokenAsync") and + DataFlow::localExprFlow(validation.getArgument(0), split.getQualifier()) and + hasSignatureValidationEnabled(validation.getArgument(1)) and + awaited.getExpr() = validation and + DataFlow::localExprFlow(awaited, isValid.getQualifier()) and + isValid.getTarget().hasName("IsValid") and + invalidResult = guard.getCondition() and + invalidResult.getOperand() = isValid and + failure.getParent*() = guard.getThen() and + guard.getControlFlowNode().dominates(decoder.getControlFlowNode()) + ) +} + +module UnverifiedJwtPayloadDecodeConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node source) { source.asExpr() instanceof JwtPayloadSegment } + + predicate isSink(DataFlow::Node sink) { + exists(Base64DecodeCall decoder | sink.asExpr() = decoder.getArgument(0)) + } +} + +module UnverifiedJwtPayloadDecodeFlow = TaintTracking::Global; + +from UnverifiedJwtPayloadDecodeFlow::PathNode source, UnverifiedJwtPayloadDecodeFlow::PathNode sink +where + UnverifiedJwtPayloadDecodeFlow::flowPath(source, sink) and + not validatedBeforeDecode(source.getNode().asExpr(), sink.getNode().asExpr().getParent()) +select sink.getNode(), source, sink, + "$@ is base64-decoded without the token signature being verified, so its claims can be forged.", + source.getNode(), "This JWT payload segment" diff --git a/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeBad.cs b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeBad.cs new file mode 100644 index 00000000..ba5d539c --- /dev/null +++ b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeBad.cs @@ -0,0 +1,7 @@ +public static IList GetRoles(string jwt) +{ + var payload = jwt.Split('.')[1]; + payload = payload.PadRight(payload.Length + (4 - payload.Length % 4) % 4, '='); + var json = Encoding.UTF8.GetString(Convert.FromBase64String(payload)); // BAD + return JObject.Parse(json)["roles"].Values().ToList(); +} diff --git a/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeGood.cs b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeGood.cs new file mode 100644 index 00000000..4a41810c --- /dev/null +++ b/csharp/src/security/CWE-345/UnverifiedJwtPayloadDecodeGood.cs @@ -0,0 +1,12 @@ +public static IEnumerable GetRoles(string jwt, SecurityKey key) +{ + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = key, + ValidIssuer = "https://issuer.example", + ValidAudience = "my-api" + }; + var principal = new JwtSecurityTokenHandler().ValidateToken(jwt, parameters, out _); // GOOD + return principal.FindAll(ClaimTypes.Role).Select(c => c.Value); +} diff --git a/csharp/test/TestUtilities/InlineExpectationsTestQuery.ql b/csharp/test/TestUtilities/InlineExpectationsTestQuery.ql new file mode 100644 index 00000000..453de557 --- /dev/null +++ b/csharp/test/TestUtilities/InlineExpectationsTestQuery.ql @@ -0,0 +1,9 @@ +/** + * @kind test-postprocess + */ + +private import csharp +private import codeql.util.test.InlineExpectationsTest as T +private import utils.test.internal.InlineExpectationsTestImpl +import T::TestPostProcessing +import T::TestPostProcessing::Make diff --git a/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/Test.cs b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/Test.cs new file mode 100644 index 00000000..c3069b3f --- /dev/null +++ b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/Test.cs @@ -0,0 +1,242 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Security.Claims; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.IdentityModel.JsonWebTokens; +using Microsoft.IdentityModel.Tokens; +using Newtonsoft.Json.Linq; + +namespace JwtTests +{ + public class JwtPayload + { + public string Username { get; set; } + public IList Roles { get; set; } + + // BAD: the payload segment is base64-decoded and its claims are trusted + // without checking the token signature. + public static JwtPayload ParseJwt(string jwt) + { + var jwtPayloadBase64 = jwt.Split('.')[1]; // $ Source + if (jwtPayloadBase64.Length % 4 != 0) + { + jwtPayloadBase64 = jwtPayloadBase64.PadRight(jwtPayloadBase64.Length + (4 - jwtPayloadBase64.Length % 4), '='); + } + + var json = Encoding.UTF8.GetString(Convert.FromBase64String(jwtPayloadBase64)); // $ Alert + var doc = JObject.Parse(json); + return new JwtPayload + { + Username = (string)doc["username"], + Roles = doc["roles"].Values().ToList() + }; + } + } + + public class AuthService + { + // BAD: base64url payload normalized with Replace before decoding. + public bool IsAdmin(string token) + { + var parts = token.Split("."); + var payload = parts[1].Replace('-', '+').Replace('_', '/'); // $ Source + var json = Encoding.UTF8.GetString(Convert.FromBase64String(payload)); // $ Alert + return json.Contains("\"role\":\"admin\""); + } + + // BAD: reading the signature for logging does not verify it. + public bool IsAdminWithLoggedSignature(string token) + { + var parts = token.Split('.'); + Console.WriteLine(parts[2]); + var json = Base64UrlEncoder.Decode(parts[1]); // $ Alert + return json.Contains("\"role\":\"admin\""); + } + + // BAD: Base64UrlEncoder.Decode on the payload segment. + public string GetSubject(string token) + { + string[] parts = token.Split('.'); + var json = Base64UrlEncoder.Decode(parts[1]); // $ Alert + return (string)JObject.Parse(json)["sub"]; + } + + // BAD: Base64UrlEncoder.DecodeBytes on the payload segment. + public string GetSubjectFromBytes(string token) + { + var parts = token.Split('.'); + var json = Encoding.UTF8.GetString(Base64UrlEncoder.DecodeBytes(parts[1])); // $ Alert + return (string)JObject.Parse(json)["sub"]; + } + + // BAD: WebEncoders.Base64UrlDecode on the payload segment. + public string GetSubjectWithWebEncoders(string token) + { + var parts = token.Split('.'); + var json = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(parts[1])); // $ Alert + return (string)JObject.Parse(json)["sub"]; + } + + // BAD: Convert.TryFromBase64String on the payload segment. + public string GetSubjectWithTryDecode(string token) + { + var parts = token.Split('.'); + var buffer = new byte[1024]; + if (!Convert.TryFromBase64String(parts[1], buffer, out var written)) // $ Alert + { + return null; + } + return (string)JObject.Parse(Encoding.UTF8.GetString(buffer, 0, written))["sub"]; + } + + // BAD: the payload segment reaches the decoder through a helper method. + public string GetRoleViaHelper(string token) + { + var segments = token.Split('.'); + var json = DecodeSegment(segments[1]); // $ Source + return (string)JObject.Parse(json)["role"]; + } + + private static string DecodeSegment(string segment) + { + var padded = segment.PadRight(segment.Length + (4 - segment.Length % 4) % 4, '='); + return Encoding.UTF8.GetString(Convert.FromBase64String(padded)); // $ Alert + } + + // GOOD: only the header segment is decoded, for example to read the "kid". + public string GetKeyId(string token) + { + var parts = token.Split('.'); + var header = Encoding.UTF8.GetString(Base64UrlEncoder.DecodeBytes(parts[0])); + return (string)JObject.Parse(header)["kid"]; + } + + // GOOD: the signature segment is verified before the payload is decoded. + public string GetRoleVerified(string token, byte[] key) + { + var parts = token.Split('.'); + using var hmac = new HMACSHA256(key); + var expected = hmac.ComputeHash(Encoding.ASCII.GetBytes(parts[0] + "." + parts[1])); + var actual = Base64UrlEncoder.DecodeBytes(parts[2]); + if (!CryptographicOperations.FixedTimeEquals(expected, actual)) + { + throw new UnauthorizedAccessException(); + } + var json = Base64UrlEncoder.Decode(parts[1]); + return (string)JObject.Parse(json)["role"]; + } + + // GOOD: the signature segment is compared with an expected signature. + public string GetRoleComparedSignature(string token, byte[] key) + { + var parts = token.Split('.'); + using var hmac = new HMACSHA256(key); + var expected = Base64UrlEncoder.Encode(hmac.ComputeHash(Encoding.ASCII.GetBytes(parts[0] + "." + parts[1]))); + if (expected != parts[2]) + { + throw new UnauthorizedAccessException(); + } + var json = Base64UrlEncoder.Decode(parts[1]); + return (string)JObject.Parse(json)["role"]; + } + + // GOOD: the token is validated by a JWT library and claims are read from the result. + public string GetRoleValidated(string token, byte[] key) + { + var handler = new JwtSecurityTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key) + }; + ClaimsPrincipal principal = handler.ValidateToken(token, parameters, out _); + return principal.FindFirstValue("role"); + } + + // GOOD: the same token is validated with signing key validation enabled before decoding. + public string GetRoleValidatedAndDecoded(string token, byte[] key) + { + var handler = new JwtSecurityTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key) + }; + handler.ValidateToken(token, parameters, out _); + var parts = token.Split('.'); + return Base64UrlEncoder.Decode(parts[1]); + } + + // BAD: the payload is decoded before the token is validated. + public string GetRoleDecodedBeforeValidation(string token, byte[] key) + { + var handler = new JwtSecurityTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key) + }; + var parts = token.Split('.'); + var json = Base64UrlEncoder.Decode(parts[1]); // $ Alert + handler.ValidateToken(token, parameters, out _); + return json; + } + + // BAD: ValidateToken alone does not establish signature validation. + public string GetRoleWithUnvalidatedParameters(string token) + { + var handler = new JwtSecurityTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = false + }; + handler.ValidateToken(token, parameters, out _); + var parts = token.Split('.'); + return Base64UrlEncoder.Decode(parts[1]); // $ Alert + } + + // GOOD: async validation is followed by a guard for an invalid result. + public async Task GetRoleValidatedAsyncAndDecoded(string token, byte[] key) + { + var handler = new JsonWebTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key) + }; + var validation = await handler.ValidateTokenAsync(token, parameters); + if (!validation.IsValid) + { + throw new UnauthorizedAccessException(); + } + var parts = token.Split('.'); + return Base64UrlEncoder.Decode(parts[1]); + } + + // BAD: the result of async validation is not checked before decoding. + public async Task GetRoleWithoutAsyncValidationGuard(string token, byte[] key) + { + var handler = new JsonWebTokenHandler(); + var parameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key) + }; + var validation = await handler.ValidateTokenAsync(token, parameters); + var parts = token.Split('.'); + return Base64UrlEncoder.Decode(parts[1]); // $ Alert + } + + // GOOD: not a JWT, the string is not split on '.'. + public byte[] DecodeSecondField(string csv) + { + var fields = csv.Split(','); + return Convert.FromBase64String(fields[1]); + } + } +} diff --git a/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.expected b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.expected new file mode 100644 index 00000000..356bb8ae --- /dev/null +++ b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.expected @@ -0,0 +1,60 @@ +#select +| Test.cs:31:73:31:88 | access to local variable jwtPayloadBase64 | Test.cs:25:36:25:52 | access to array element : String | Test.cs:31:73:31:88 | access to local variable jwtPayloadBase64 | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:25:36:25:52 | access to array element | This JWT payload segment | +| Test.cs:48:73:48:79 | access to local variable payload | Test.cs:47:27:47:34 | access to array element : String | Test.cs:48:73:48:79 | access to local variable payload | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:47:27:47:34 | access to array element | This JWT payload segment | +| Test.cs:57:48:57:55 | access to array element | Test.cs:57:48:57:55 | access to array element | Test.cs:57:48:57:55 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:57:48:57:55 | access to array element | This JWT payload segment | +| Test.cs:65:48:65:55 | access to array element | Test.cs:65:48:65:55 | access to array element | Test.cs:65:48:65:55 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:65:48:65:55 | access to array element | This JWT payload segment | +| Test.cs:73:77:73:84 | access to array element | Test.cs:73:77:73:84 | access to array element | Test.cs:73:77:73:84 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:73:77:73:84 | access to array element | This JWT payload segment | +| Test.cs:81:76:81:83 | access to array element | Test.cs:81:76:81:83 | access to array element | Test.cs:81:76:81:83 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:81:76:81:83 | access to array element | This JWT payload segment | +| Test.cs:90:46:90:53 | access to array element | Test.cs:90:46:90:53 | access to array element | Test.cs:90:46:90:53 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:90:46:90:53 | access to array element | This JWT payload segment | +| Test.cs:108:69:108:74 | access to local variable padded | Test.cs:101:38:101:48 | access to array element : String | Test.cs:108:69:108:74 | access to local variable padded | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:101:38:101:48 | access to array element | This JWT payload segment | +| Test.cs:185:48:185:55 | access to array element | Test.cs:185:48:185:55 | access to array element | Test.cs:185:48:185:55 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:185:48:185:55 | access to array element | This JWT payload segment | +| Test.cs:200:44:200:51 | access to array element | Test.cs:200:44:200:51 | access to array element | Test.cs:200:44:200:51 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:200:44:200:51 | access to array element | This JWT payload segment | +| Test.cs:232:44:232:51 | access to array element | Test.cs:232:44:232:51 | access to array element | Test.cs:232:44:232:51 | access to array element | $@ is base64-decoded without the token signature being verified, so its claims can be forged. | Test.cs:232:44:232:51 | access to array element | This JWT payload segment | +edges +| Test.cs:25:17:25:32 | access to local variable jwtPayloadBase64 : String | Test.cs:28:36:28:51 | access to local variable jwtPayloadBase64 : String | provenance | | +| Test.cs:25:17:25:32 | access to local variable jwtPayloadBase64 : String | Test.cs:31:73:31:88 | access to local variable jwtPayloadBase64 | provenance | | +| Test.cs:25:36:25:52 | access to array element : String | Test.cs:25:17:25:32 | access to local variable jwtPayloadBase64 : String | provenance | | +| Test.cs:28:17:28:32 | access to local variable jwtPayloadBase64 : String | Test.cs:31:73:31:88 | access to local variable jwtPayloadBase64 | provenance | | +| Test.cs:28:36:28:51 | access to local variable jwtPayloadBase64 : String | Test.cs:28:36:28:126 | call to method PadRight : String | provenance | MaD:1 | +| Test.cs:28:36:28:126 | call to method PadRight : String | Test.cs:28:17:28:32 | access to local variable jwtPayloadBase64 : String | provenance | | +| Test.cs:47:17:47:23 | access to local variable payload : String | Test.cs:48:73:48:79 | access to local variable payload | provenance | | +| Test.cs:47:27:47:34 | access to array element : String | Test.cs:47:27:47:52 | call to method Replace : String | provenance | MaD:2 | +| Test.cs:47:27:47:52 | call to method Replace : String | Test.cs:47:27:47:70 | call to method Replace : String | provenance | MaD:2 | +| Test.cs:47:27:47:70 | call to method Replace : String | Test.cs:47:17:47:23 | access to local variable payload : String | provenance | | +| Test.cs:101:38:101:48 | access to array element : String | Test.cs:105:52:105:58 | segment : String | provenance | | +| Test.cs:105:52:105:58 | segment : String | Test.cs:107:26:107:32 | access to parameter segment : String | provenance | | +| Test.cs:107:17:107:22 | access to local variable padded : String | Test.cs:108:69:108:74 | access to local variable padded | provenance | | +| Test.cs:107:26:107:32 | access to parameter segment : String | Test.cs:107:26:107:93 | call to method PadRight : String | provenance | MaD:1 | +| Test.cs:107:26:107:93 | call to method PadRight : String | Test.cs:107:17:107:22 | access to local variable padded : String | provenance | | +models +| 1 | Summary: System; String; false; PadRight; (System.Int32,System.Char); ; Argument[this]; ReturnValue; taint; manual | +| 2 | Summary: System; String; false; Replace; (System.Char,System.Char); ; Argument[this]; ReturnValue; taint; manual | +nodes +| Test.cs:25:17:25:32 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String | +| Test.cs:25:36:25:52 | access to array element : String | semmle.label | access to array element : String | +| Test.cs:28:17:28:32 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String | +| Test.cs:28:36:28:51 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String | +| Test.cs:28:36:28:126 | call to method PadRight : String | semmle.label | call to method PadRight : String | +| Test.cs:31:73:31:88 | access to local variable jwtPayloadBase64 | semmle.label | access to local variable jwtPayloadBase64 | +| Test.cs:47:17:47:23 | access to local variable payload : String | semmle.label | access to local variable payload : String | +| Test.cs:47:27:47:34 | access to array element : String | semmle.label | access to array element : String | +| Test.cs:47:27:47:52 | call to method Replace : String | semmle.label | call to method Replace : String | +| Test.cs:47:27:47:70 | call to method Replace : String | semmle.label | call to method Replace : String | +| Test.cs:48:73:48:79 | access to local variable payload | semmle.label | access to local variable payload | +| Test.cs:57:48:57:55 | access to array element | semmle.label | access to array element | +| Test.cs:65:48:65:55 | access to array element | semmle.label | access to array element | +| Test.cs:73:77:73:84 | access to array element | semmle.label | access to array element | +| Test.cs:81:76:81:83 | access to array element | semmle.label | access to array element | +| Test.cs:90:46:90:53 | access to array element | semmle.label | access to array element | +| Test.cs:101:38:101:48 | access to array element : String | semmle.label | access to array element : String | +| Test.cs:105:52:105:58 | segment : String | semmle.label | segment : String | +| Test.cs:107:17:107:22 | access to local variable padded : String | semmle.label | access to local variable padded : String | +| Test.cs:107:26:107:32 | access to parameter segment : String | semmle.label | access to parameter segment : String | +| Test.cs:107:26:107:93 | call to method PadRight : String | semmle.label | call to method PadRight : String | +| Test.cs:108:69:108:74 | access to local variable padded | semmle.label | access to local variable padded | +| Test.cs:172:44:172:51 | access to array element | semmle.label | access to array element | +| Test.cs:185:48:185:55 | access to array element | semmle.label | access to array element | +| Test.cs:200:44:200:51 | access to array element | semmle.label | access to array element | +| Test.cs:218:44:218:51 | access to array element | semmle.label | access to array element | +| Test.cs:232:44:232:51 | access to array element | semmle.label | access to array element | +subpaths diff --git a/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.qlref b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.qlref new file mode 100644 index 00000000..7aa8346e --- /dev/null +++ b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.qlref @@ -0,0 +1,4 @@ +query: security/CWE-345/UnverifiedJwtPayloadDecode.ql +postprocess: + - TestUtilities/PrettyPrintModels.ql + - TestUtilities/InlineExpectationsTestQuery.ql diff --git a/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/options b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/options new file mode 100644 index 00000000..95d0bb4c --- /dev/null +++ b/csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/options @@ -0,0 +1,5 @@ +semmle-extractor-options: /nostdlib /noconfig +semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../codeql/csharp/ql/test/resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj +semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../codeql/csharp/ql/test/resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj +semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../codeql/csharp/ql/test/resources/stubs/System.IdentityModel.Tokens.Jwt/7.7.1/System.IdentityModel.Tokens.Jwt.csproj +semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../codeql/csharp/ql/test/resources/stubs/Newtonsoft.Json/13.0.4/Newtonsoft.Json.csproj