Skip to content

Commit

Permalink
Handle the case where the token type validation delegate throws in Js…
Browse files Browse the repository at this point in the history
…onWebTokenHandler
  • Loading branch information
iNinja committed Nov 20, 2024
1 parent 058c87e commit 63ac325
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,28 @@ await ValidateJWSAsync(actorToken, actorParameters, configuration, callContext,
actorValidationResult = innerActorValidationResult;
}

ValidationResult<ValidatedTokenType> typeValidationResult = validationParameters.TokenTypeValidator(
jsonWebToken.Typ, jsonWebToken, validationParameters, callContext);
if (!typeValidationResult.IsValid)
ValidationResult<ValidatedTokenType> typeValidationResult;

try
{
StackFrame typeValidationFailureStackFrame = StackFrames.TypeValidationFailed ??= new StackFrame(true);
return typeValidationResult.UnwrapError().AddStackFrame(typeValidationFailureStackFrame);
typeValidationResult = validationParameters.TokenTypeValidator(
jsonWebToken.Typ, jsonWebToken, validationParameters, callContext);

if (!typeValidationResult.IsValid)
return typeValidationResult.UnwrapError().AddCurrentStackFrame();
}

#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
return new TokenTypeValidationError(
new MessageDetail(TokenLogMessages.IDX10275),
typeof(SecurityTokenInvalidTypeException),
ValidationError.GetCurrentStackFrame(),
jsonWebToken.Typ,
ValidationFailureType.TokenTypeValidatorThrew,
ex);
}

// The signature validation delegate is yet to be migrated to ValidationParameters.
Expand Down

0 comments on commit 63ac325

Please sign in to comment.