Skip to content

C#: add a query for a JWT payload that is decoded without checking its signature #274

In progress

Description

@felickz

What to do

Add a C# query that reports a JSON Web Token (JWT) whose payload is base64-decoded, and then trusted, without
its signature being checked (CWE-345, CWE-347). The JWT queries in codeql/csharp-queries check
TokenValidationParameters, not code that decodes the payload by hand. Before you start, also check the queries
in csharp/src/security/JsonWebTokenHandler/ of this repository for overlap.

Report this:

var payload = jwt.Split('.')[1];
payload = payload.PadRight(payload.Length + (4 - payload.Length % 4) % 4, '=');
var json = Encoding.UTF8.GetString(Convert.FromBase64String(payload));
var roles = JObject.Parse(json)["roles"];

Do not report this:

// The signature segment is checked before the payload is decoded.
var parts = token.Split('.');
if (!Hmac.FixedTimeEquals(Hmac.Sign(key, parts[0] + "." + parts[1]), Base64UrlEncoder.DecodeBytes(parts[2])))
    throw new UnauthorizedAccessException();
var json = Base64UrlEncoder.Decode(parts[1]);

// A library validates the token.
var principal = new JwtSecurityTokenHandler().ValidateToken(token, parameters, out _);

The files below are a draft of this query from another workspace. It was written for another layout and has never run in this repository. Use it as a starting point: port it, prove it with its test, and change it wherever the test or this repository's conventions disagree with it.

Decisions in the draft

  • Source: element [1] of the result of Split('.') or Split("."), reached from the Split call by local
    data flow.
  • Sinks: the first argument of Convert.FromBase64String, Convert.TryFromBase64String,
    Base64UrlEncoder.Decode, Base64UrlEncoder.DecodeBytes and WebEncoders.Base64UrlDecode.
  • Flow: global taint tracking, so normalization (PadRight, Replace) and helper methods are followed.
  • Exclusion: a source is dropped when element [2] of the same Split result is read anywhere, as evidence
    that the code checks the signature itself.
  • Known limitation: code that has the token validated elsewhere before it decodes the payload, for example
    by a remote service, is still reported. The query help should say so.
  • Metadata: @kind path-problem, @precision medium, @security-severity 8.1. The draft id
    cs/unverified-jwt-payload-decode needs this repository's id format.
  • Test: inline expectations ($ Alert, $ Source). Stubs.cs stands in for the JWT, JSON and HMAC APIs,
    which the draft's test extraction could not resolve. Prefer the shared stubs under
    codeql/csharp/ql/test/resources/stubs where they cover an API.

Files

The paths below follow this repository's layout but are suggestions. The draft was written for another layout, so its .qlref and options files, and its .md query help, need adapting (most C# queries here use .qhelp).

csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.md

# JWT payload decoded without signature verification

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 flags code that splits a token on `.` and base64-decodes the payload segment (index `1`) without evidence that its signature has been verified. A read of the signature segment (index `2`) is treated as verification evidence only when it flows into a comparison, equality operation, or verify-style call. Claims decoded without authentication can be forged (CWE-345, CWE-347).

## Recommendation

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. 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.

## Known limitations

- The signature-use check is heuristic. It does not prove that the comparison result is checked or that the comparison correctly verifies a cryptographic signature. Logging the segment alone does not count as verification.
- Local token validation is recognized when `ValidateToken` on the same token dominates the decode and its parameter initializer enables `ValidateIssuerSigningKey` and sets `IssuerSigningKey`. `ValidateTokenAsync` additionally requires an `IsValid` guard whose invalid branch throws. Remote validation, custom validation helpers, and indirectly configured parameters are not modeled.

## Example

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"]`:

```csharp
public static IList<string> 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<string>().ToList();
}
```

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

```csharp
public static IEnumerable<string> 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);
}
```

## References

- [CWE-345: Insufficient Verification of Data Authenticity](https://cwe.mitre.org/data/definitions/345.html)
- [CWE-347: Improper Verification of Cryptographic Signature](https://cwe.mitre.org/data/definitions/347.html)
- [RFC 7519: JSON Web Token (JWT)](https://www.rfc-editor.org/rfc/rfc7519)
- [OWASP: JSON Web Token Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html)

csharp/src/security/CWE-345/UnverifiedJwtPayloadDecode.ql

/**
 * @name JWT payload decoded without signature verification
 * @description Manually base64-decoding the payload segment of a JSON Web Token and
 *              trusting its claims without verifying the token signature allows an
 *              attacker to forge claims such as roles or user identifiers.
 * @kind path-problem
 * @problem.severity error
 * @security-severity 8.1
 * @precision medium
 * @id cs/unverified-jwt-payload-decode
 * @tags security
 *       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 segment `index` of the split result is read. */
  predicate readsSegment(ArrayAccess aa, int index) {
    DataFlow::localExprFlow(this, aa.getQualifier()) and
    aa.getIndex(0).getValue().toInt() = index
  }

  /** Holds if segment `2` flows into a comparison, equality, or verification call. */
  predicate verifiesSignature() {
    exists(ArrayAccess signature, ComparisonOperation comparison |
      this.readsSegment(signature, 2) and
      (
        DataFlow::localExprFlow(signature, comparison.getLeftOperand())
        or
        DataFlow::localExprFlow(signature, comparison.getRightOperand())
      )
    )
    or
    exists(ArrayAccess signature, Base64DecodeCall decoder, ComparisonOperation comparison |
      this.readsSegment(signature, 2) and
      DataFlow::localExprFlow(signature, decoder.getArgument(0)) and
      (
        DataFlow::localExprFlow(decoder, comparison.getLeftOperand())
        or
        DataFlow::localExprFlow(decoder, comparison.getRightOperand())
      )
    )
    or
    exists(ArrayAccess signature, MethodCall verification, int argument |
      this.readsSegment(signature, 2) and
      DataFlow::localExprFlow(signature, verification.getArgument(argument)) and
      verification.getTarget().getName().regexpMatch("(?i).*(verify|equals).*")
    )
    or
    exists(ArrayAccess signature, Base64DecodeCall decoder, MethodCall verification, int argument |
      this.readsSegment(signature, 2) and
      DataFlow::localExprFlow(signature, decoder.getArgument(0)) and
      DataFlow::localExprFlow(decoder, verification.getArgument(argument)) and
      verification.getTarget().getName().regexpMatch("(?i).*(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 {
  JwtPayloadSegment() {
    exists(JwtSplitCall split |
      split.readsSegment(this, 1) and
      not split.verifiesSignature()
    )
  }

  JwtSplitCall getSplitCall() { result.readsSegment(this, 1) }
}

/** 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")
  }
}

/** An argument to a base64 decoding method. */
class Base64DecodeSink extends Expr {
  Base64DecodeSink() { exists(Base64DecodeCall decoder | this = decoder.getArgument(0)) }
}

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).getValue() = "true" and
    key = initializer.getAMemberInitializer() and
    key.getLeftOperand().(PropertyAccess).getTarget().hasName("IssuerSigningKey")
  )
}

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()
        .getBasicBlock()
        .dominates(decoder.getControlFlowNode().getBasicBlock())
  )
  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.getChild(0) = 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()
        .getBasicBlock()
        .dominates(decoder.getControlFlowNode().getBasicBlock())
  )
}

module UnverifiedJwtPayloadDecodeConfig implements DataFlow::ConfigSig {
  predicate isSource(DataFlow::Node source) { source.asExpr() instanceof JwtPayloadSegment }

  predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof Base64DecodeSink }
}

module UnverifiedJwtPayloadDecodeFlow = TaintTracking::Global<UnverifiedJwtPayloadDecodeConfig>;

from UnverifiedJwtPayloadDecodeFlow::PathNode source, UnverifiedJwtPayloadDecodeFlow::PathNode sink
where
  UnverifiedJwtPayloadDecodeFlow::flowPath(source, sink) and
  not validatedBeforeDecode(source.getNode().asExpr().(JwtPayloadSegment),
    sink.getNode().asExpr().getParent().(Base64DecodeCall))
select sink.getNode(), source, sink,
  "JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged.",
  source.getNode(), "this token"

csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/Stubs.cs

// Minimal stubs for the JWT libraries used by the test cases.

namespace Microsoft.IdentityModel.Tokens
{
    public static class Base64UrlEncoder
    {
        public static string Decode(string arg) => null;
        public static byte[] DecodeBytes(string str) => null;
    }

    public class TokenValidationParameters
    {
        public bool ValidateIssuerSigningKey { get; set; }
        public SecurityKey IssuerSigningKey { get; set; }
    }

    public abstract class SecurityKey { }

    public class SymmetricSecurityKey : SecurityKey
    {
        public SymmetricSecurityKey(byte[] key) { }
    }

    public abstract class SecurityToken { }
}

namespace System.IdentityModel.Tokens.Jwt
{
    using Microsoft.IdentityModel.Tokens;
    using Stubs;

    public class JwtSecurityTokenHandler
    {
        public ClaimsPrincipal ValidateToken(string token, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
        {
            validatedToken = null;
            return null;
        }
    }
}

namespace Microsoft.IdentityModel.JsonWebTokens
{
    using Microsoft.IdentityModel.Tokens;

    public class JsonWebTokenHandler
    {
        public System.Threading.Tasks.Task<TokenValidationResult> ValidateTokenAsync(
            string token,
            TokenValidationParameters validationParameters)
        {
            return null;
        }
    }

    public class TokenValidationResult
    {
        public bool IsValid { get; set; }
    }
}

namespace Stubs
{
    public class ClaimsPrincipal
    {
        public string FindFirstValue(string type) => null;
    }

    public class JsonObject
    {
        public static JsonObject Parse(string json) => null;
        public string GetString(string name) => null;
        public string[] GetStrings(string name) => null;
    }

    public static class Hmac
    {
        public static byte[] Sign(byte[] key, string data) => null;
        public static bool FixedTimeEquals(byte[] a, byte[] b) => false;
    }
}

csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/Test.cs

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.JsonWebTokens;
using Stubs;

namespace JwtTests
{
    public class JwtPayload
    {
        public string Username { get; set; }
        public IList<string> Roles { get; set; }

        // BAD: the payload segment is base64-decoded and its claims are trusted
        // without ever 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 = JsonObject.Parse(json);
            return new JwtPayload
            {
                Username = doc.GetString("username"),
                Roles = doc.GetStrings("roles")
            };
        }
    }

    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
            var doc = JsonObject.Parse(json);
            return doc.GetString("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
            var doc = JsonObject.Parse(json);
            return doc.GetString("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 (e.g. to read the "kid").
        public string GetKeyId(string token)
        {
            var parts = token.Split('.');
            var header = Encoding.UTF8.GetString(Base64UrlEncoder.DecodeBytes(parts[0]));
            var doc = JsonObject.Parse(header);
            return doc.GetString("kid");
        }

        // GOOD: the signature segment is verified before the payload is decoded.
        public string GetRoleVerified(string token, byte[] key)
        {
            var parts = token.Split('.');
            var expected = Hmac.Sign(key, parts[0] + "." + parts[1]);
            var actual = Base64UrlEncoder.DecodeBytes(parts[2]);
            if (!Hmac.FixedTimeEquals(expected, actual))
            {
                throw new UnauthorizedAccessException();
            }
            var json = Base64UrlEncoder.Decode(parts[1]);
            var doc = JsonObject.Parse(json);
            return doc.GetString("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: 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 System.Threading.Tasks.Task<string> 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: async validation is not checked before decoding.
        public async System.Threading.Tasks.Task<string> 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]);
        }
    }
}

csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.expected

#select
| Test.cs:26:73:26:88 | access to local variable jwtPayloadBase64 | Test.cs:20:36:20:52 | access to array element : String | Test.cs:26:73:26:88 | access to local variable jwtPayloadBase64 | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:20:36:20:52 | access to array element | this token |
| Test.cs:43:73:43:79 | access to local variable payload | Test.cs:42:27:42:34 | access to array element : String | Test.cs:43:73:43:79 | access to local variable payload | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:42:27:42:34 | access to array element | this token |
| Test.cs:52:48:52:55 | access to array element | Test.cs:52:48:52:55 | access to array element | Test.cs:52:48:52:55 | access to array element | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:52:48:52:55 | access to array element | this token |
| Test.cs:60:48:60:55 | access to array element | Test.cs:60:48:60:55 | access to array element | Test.cs:60:48:60:55 | access to array element | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:60:48:60:55 | access to array element | this token |
| Test.cs:77:69:77:74 | access to local variable padded | Test.cs:69:38:69:48 | access to array element : String | Test.cs:77:69:77:74 | access to local variable padded | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:69:38:69:48 | access to array element | this token |
| Test.cs:141:44:141:51 | access to array element | Test.cs:141:44:141:51 | access to array element | Test.cs:141:44:141:51 | access to array element | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:141:44:141:51 | access to array element | this token |
| Test.cs:173:44:173:51 | access to array element | Test.cs:173:44:173:51 | access to array element | Test.cs:173:44:173:51 | access to array element | JWT payload segment from $@ is base64-decoded without verifying the token signature; its claims can be forged. | Test.cs:173:44:173:51 | access to array element | this token |
edges
| Test.cs:20:17:20:32 | access to local variable jwtPayloadBase64 : String | Test.cs:23:36:23:51 | access to local variable jwtPayloadBase64 : String | provenance |  |
| Test.cs:20:17:20:32 | access to local variable jwtPayloadBase64 : String | Test.cs:26:73:26:88 | access to local variable jwtPayloadBase64 | provenance |  |
| Test.cs:20:36:20:52 | access to array element : String | Test.cs:20:17:20:32 | access to local variable jwtPayloadBase64 : String | provenance |  |
| Test.cs:23:17:23:32 | access to local variable jwtPayloadBase64 : String | Test.cs:26:73:26:88 | access to local variable jwtPayloadBase64 | provenance |  |
| Test.cs:23:36:23:51 | access to local variable jwtPayloadBase64 : String | Test.cs:23:36:23:126 | call to method PadRight : String | provenance | MaD:2952 |
| Test.cs:23:36:23:126 | call to method PadRight : String | Test.cs:23:17:23:32 | access to local variable jwtPayloadBase64 : String | provenance |  |
| Test.cs:42:17:42:23 | access to local variable payload : String | Test.cs:43:73:43:79 | access to local variable payload | provenance |  |
| Test.cs:42:27:42:34 | access to array element : String | Test.cs:42:27:42:52 | call to method Replace : String | provenance | MaD:2956 |
| Test.cs:42:27:42:52 | call to method Replace : String | Test.cs:42:27:42:70 | call to method Replace : String | provenance | MaD:2956 |
| Test.cs:42:27:42:70 | call to method Replace : String | Test.cs:42:17:42:23 | access to local variable payload : String | provenance |  |
| Test.cs:69:38:69:48 | access to array element : String | Test.cs:74:52:74:58 | segment : String | provenance |  |
| Test.cs:74:52:74:58 | segment : String | Test.cs:76:26:76:32 | access to parameter segment : String | provenance |  |
| Test.cs:76:17:76:22 | access to local variable padded : String | Test.cs:77:69:77:74 | access to local variable padded | provenance |  |
| Test.cs:76:26:76:32 | access to parameter segment : String | Test.cs:76:26:76:93 | call to method PadRight : String | provenance | MaD:2952 |
| Test.cs:76:26:76:93 | call to method PadRight : String | Test.cs:76:17:76:22 | access to local variable padded : String | provenance |  |
nodes
| Test.cs:20:17:20:32 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String |
| Test.cs:20:36:20:52 | access to array element : String | semmle.label | access to array element : String |
| Test.cs:23:17:23:32 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String |
| Test.cs:23:36:23:51 | access to local variable jwtPayloadBase64 : String | semmle.label | access to local variable jwtPayloadBase64 : String |
| Test.cs:23:36:23:126 | call to method PadRight : String | semmle.label | call to method PadRight : String |
| Test.cs:26:73:26:88 | access to local variable jwtPayloadBase64 | semmle.label | access to local variable jwtPayloadBase64 |
| Test.cs:42:17:42:23 | access to local variable payload : String | semmle.label | access to local variable payload : String |
| Test.cs:42:27:42:34 | access to array element : String | semmle.label | access to array element : String |
| Test.cs:42:27:42:52 | call to method Replace : String | semmle.label | call to method Replace : String |
| Test.cs:42:27:42:70 | call to method Replace : String | semmle.label | call to method Replace : String |
| Test.cs:43:73:43:79 | access to local variable payload | semmle.label | access to local variable payload |
| Test.cs:52:48:52:55 | access to array element | semmle.label | access to array element |
| Test.cs:60:48:60:55 | access to array element | semmle.label | access to array element |
| Test.cs:69:38:69:48 | access to array element : String | semmle.label | access to array element : String |
| Test.cs:74:52:74:58 | segment : String | semmle.label | segment : String |
| Test.cs:76:17:76:22 | access to local variable padded : String | semmle.label | access to local variable padded : String |
| Test.cs:76:26:76:32 | access to parameter segment : String | semmle.label | access to parameter segment : String |
| Test.cs:76:26:76:93 | call to method PadRight : String | semmle.label | call to method PadRight : String |
| Test.cs:77:69:77:74 | access to local variable padded | semmle.label | access to local variable padded |
| Test.cs:128:44:128:51 | access to array element | semmle.label | access to array element |
| Test.cs:141:44:141:51 | access to array element | semmle.label | access to array element |
| Test.cs:159:44:159:51 | access to array element | semmle.label | access to array element |
| Test.cs:173:44:173:51 | access to array element | semmle.label | access to array element |
subpaths

csharp/test/security/CWE-345/UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.qlref

query: UnverifiedJwtPayloadDecode/UnverifiedJwtPayloadDecode.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

How to check it

  1. Port the files and run the test of the new directory. Compare the results with what the draft expects (its
    inline $ Alert and $ MISSING: Alert comments and its .expected file), and explain every difference in
    the pull request.
  2. Then run the other gates of the agent profile: format, compile with warnings as errors, query help, suite
    selection and id uniqueness.

Rules for the change

  • Add only the new query, its library file if it has one, its query help and its test directory.
  • Pull request title: [New Query - <id>] - <what it detects>.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions