Skip to content

Commit

Permalink
Remove closure from JsonWebTokenHandler.ValidateSignature (#2169)
Browse files Browse the repository at this point in the history
The Any call on an exceptional path is closing over the jwtToken parameter, which means a display class gets allocated at the beginning of the method, whether that code path is taken or not.
  • Loading branch information
stephentoub authored Jul 26, 2023
1 parent 8e6e190 commit 4d1e7b0
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,8 @@ private static JsonWebToken ValidateSignature(JsonWebToken jwtToken, TokenValida
{
if (kidMatched)
{
var isKidInTVP = keysInTokenValidationParameters.Any(x => x.KeyId.Equals(jwtToken.Kid));
JsonWebToken localJwtToken = jwtToken; // avoid closure on non-exceptional path
var isKidInTVP = keysInTokenValidationParameters.Any(x => x.KeyId.Equals(localJwtToken.Kid));
var keyLocation = isKidInTVP ? "TokenValidationParameters" : "Configuration";
throw LogHelper.LogExceptionMessage(new SecurityTokenInvalidSignatureException(LogHelper.FormatInvariant(TokenLogMessages.IDX10511,
keysAttempted,
Expand Down

0 comments on commit 4d1e7b0

Please sign in to comment.