Error 400 with Kentico Form

Francis Carroll asked on December 1, 2022 11:32

Hey,

I am running Kentico 13.0.83 using ASP .NET CORE and IIS 10.

I have been having issues with the base kentico forms on my website and i wanted to see if there is anyone that is experiencing this issue.

This issue gets thrown intermittently when the form is submitted and there is required fields that have not been filled in. I have tried copying the dancing goat core files and removing all additional js and css files and this still has not resolved the issue.

I then went and created a new project with the basic setup and the issue is still occuring.

I have also hotfixed the project to the latest version and there has been no change.

I appriciate any help or reommendations on this issue.

https://www.hri.ie/hri/hri/MicrosoftTeams-image%20(2).png

Recent Answers


Dmitry Bastron answered on December 2, 2022 09:03

Hi Francis,

This issue looks really strange. Are there any messages in the Kentico Event log app?

0 votesVote for this answer Mark as a Correct answer

Francis Carroll answered on December 2, 2022 09:12

Hey Dmitry,

Thanks for thaking the time to look at this.

I had a look at the event log and there is one issue that seems to be persistant since i set the site up yesterday.

Source:Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery

Event code:TokenDeserializeException

Description An exception was thrown while deserializing the token. Message: The antiforgery token could not be decrypted.

Exception type: Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException Stack trace: at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken) at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)

Message: The key {350b33cd-47a5-49a7-90b7-88575a9cf88e} was not found in the key ring. For more information go to http://aka.ms/dataprotectionwarning

Exception type: System.Security.Cryptography.CryptographicException Stack trace: at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on December 2, 2022 09:20

Ok, that looks like the source of your issue. Kentico forms are using Antiforgery Tokens to validate the form submission and defend against DOS attacks.

Is this problem only on your local machine? Or can you reproduce it in other environments? Do you use docker (there might be issue with it)? Does it work ok if you open in incognito or clear your cookies?

0 votesVote for this answer Mark as a Correct answer

Francis Carroll answered on December 2, 2022 09:25

So this issue is occuring on our UAT server, it is working fine on my local.

We are not using docker.

I have tried both clearing cookies and using incoginito and it remains the same.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on December 2, 2022 09:31

Ok, there are couple more things you could try. Please read through these 2 materials, perhaps adjusting hosting settings may help: blog article, github issue thread.

It could be that your app cannot access the keys required for antiforgery to work, something like that.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 2, 2022 09:38

Are you running on web farms? E.g. the front end apps are in a web farm? If yes, how are you handling and storing sessions? Also, I would recommend setting the same machine key on the servers. If you search for the error on Google, there are many StackOverflow threads on this topic too.

1 votesVote for this answer Mark as a Correct answer

Arjan van Hugten answered on December 2, 2022 11:18 (last edited on December 2, 2022 11:20)

We had this error for one of our customers as well. Are you using 'services.AddDataProtection' in your 'Startup.cs'? We solved this error by persisting the keys to azure blob storage instead of them being stored in a folder in our Azure App Service and being removed from time to time (e.g. after deployments).

services.AddDataProtection()
  .PersistKeysToAzureBlobStorage(azureStorageConnectionString, containerName, "dataprotection");
0 votesVote for this answer Mark as a Correct answer

Francis Carroll answered on December 7, 2022 14:00

Hey,

Thanks for all the responses!

I will take some time to go through them and i will reply here when i have an update.

We have another project that was in core and went live and didnt have this issue on the same enviroments which is what makes this confusing. I have compared the projects and there isnt any visible differences.

I am currently running on web farms and i will have a look into this.

I am not using services.AddDataProtection() currently in any of the projects.

Thanks!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.