Skip to content

Commit

Permalink
Set the SigningKey in JsonWebToken only after the signature has been …
Browse files Browse the repository at this point in the history
…validated. Added test to prevent regressions. (#3111)
  • Loading branch information
iNinja authored Jan 31, 2025
1 parent 580af5e commit e527252
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ internal static ValidationResult<SecurityKey> ValidateSignature(

if (key is not null)
{
jwtToken.SigningKey = key;

// If the key is found, validate the signature.
return ValidateSignatureWithKey(jwtToken, key, validationParameters, callContext);
}
Expand Down Expand Up @@ -314,7 +312,11 @@ private static ValidationResult<SecurityKey> ValidateSignatureWithKey(
ValidateSignature);

if (valid)
{
jsonWebToken.SigningKey = key;

return key;
}
else
return new SignatureValidationError(
new MessageDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void ValidateSignature(JsonWebTokenHandlerValidateSignatureTheoryData the

Exception exception = validationError.GetException();
theoryData.ExpectedException.ProcessException(exception, context);

if (jsonWebToken is not null)
Assert.Null(jsonWebToken.SigningKey);
}

TestUtilities.AssertFailIfErrors(context);
Expand Down

0 comments on commit e527252

Please sign in to comment.