Skip to content

Fix case-sensitive JWT claim filtering bypass#1672

Merged
waldekmastykarz merged 1 commit into
dotnet:mainfrom
garrytrinder:fix/jwt-case-insensitive-claim-filtering
May 18, 2026
Merged

Fix case-sensitive JWT claim filtering bypass#1672
waldekmastykarz merged 1 commit into
dotnet:mainfrom
garrytrinder:fix/jwt-case-insensitive-claim-filtering

Conversation

@garrytrinder
Copy link
Copy Markdown
Collaborator

Summary

Fixes a security bypass in JwtIssuer.CreateSecurityToken where restricted JWT claims could be injected using mixed-case keys (e.g. SCP, ROLES) because Dictionary.Remove() uses case-sensitive matching by default.

Problem

The claim filtering logic used case-sensitive Remove() calls:

_ = claimsToAdd.Remove("scp");
_ = claimsToAdd.Remove("roles");

An attacker could bypass this by passing --claims "SCP:admin" or --claims "ROLES:SuperUser", resulting in a signed token containing elevated privileges.

Fix

Replace the mutable Remove() approach with a HashSet<string>(StringComparer.OrdinalIgnoreCase) containing all restricted claim names, then filter claims via .Where() before adding them to the identity. This:

  1. Blocks restricted claims regardless of casing
  2. Avoids mutating the input dictionary as a side effect

Use case-insensitive comparison when filtering restricted claims
in JwtIssuer to prevent bypass via mixed-case claim keys (e.g.
SCP, ROLES). Previously, Dictionary.Remove() used the default
case-sensitive comparer, allowing uppercase variants to survive
filtering.
Copilot AI review requested due to automatic review settings May 18, 2026 11:05
@garrytrinder garrytrinder requested a review from a team as a code owner May 18, 2026 11:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a security bypass in Dev Proxy’s JWT issuance path by ensuring restricted claim names cannot be injected via mixed-case keys when generating tokens.

Changes:

  • Replaces case-sensitive Dictionary.Remove() filtering with a case-insensitive restricted-claim set.
  • Filters custom claims via Where(...) to avoid mutating the input claims dictionary while blocking restricted keys (including scp/roles) regardless of casing.

@waldekmastykarz waldekmastykarz merged commit 7165255 into dotnet:main May 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants