Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
---> System.Security.Cryptography.CryptographicException: The key {669d513e-a172-4851-b160-04b523abbc1e} was not found in the key ring.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)
We insert an anti-forgery token into the form using @Html.AntiForgeryToken()
and validate the request using the [ValidateAntiForgeryToken]
, however we occasionally get the error above when one user tries to submit.
How is the key generated? Why does the user affect the generation of the token?
Expected Behavior
When user submit a form, the request token is valid and the user request is accepted.
Steps To Reproduce
- Create a cshtml page
- Include an antiforgery token in the form using
@Html.AntiForgeryToken()
- Annotate the controller method with
[ValidateAntiForgeryToken]
- Make a post request with the token
Exceptions (if any)
An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
.NET Version
netcoreapp3.1
Anything else?
We have tried this with different users, different devices and different browsers.
Only this user has the issue, and it is correlated with the logs' timestamp.
I've checked the source code, and was wondering could it be due to special characters in the user name?