Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

KB2418241, KB2416473, and KB2416451 all reference

After installing this patches on our Windows Server 2003 machines last Friday, we have been getting a significantly increased rate of errors of the sort:

System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not 
supplied or was invalid. ---> System.Web.HttpException: Validation of viewstate MAC
failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> 
configuration specifies the same validationKey and validation algorithm. AutoGenerate
cannot be used in a cluster. ---> System.Web.UI.ViewStateException: Invalid viewstate. 

The setup is as follows:

  • The web applications are running in a web cluster, with the NLB settings to Client Affinity: Single.
  • There are redirects between two separate web applications, and both of their machineKey elements are identical using explicit validationKey and decryptionKey elements.
  • The validation method is set to "SHA1" and the decryption method is set to "AES"

    (Furthermore, no redeployments of the applications have taken since well before the microsoft updates were installed).

These errors could of course be caused by actual CSRF attacks, but I find it unlikely given the volume and the spike corresponding with installation of the updates.

Are there any known issues with this update that could be causing this? (and even better, any known workarounds?)

share|improve this question
up vote 0 down vote accepted

This problem was indeed caused by the security update. The update changed the way things are validated by additionally signing the encrypted data. This included the AntiForgeryToken cookie.

If the user restarts their browser or otherwise clears all session cookies, the problem goes away.

This was also noted in a comment at

After installing the patch, I was quite freaked out to find requests to my site
failing  - 500s.  But only in one browser.  To sum up: If you have an MVC site, 
and are using Html.AntiForgeryToken() - any existing browser sessions will need 
to be closed and reopened so that the session cookie that was generated before 
the patch was applied, for that antiforgery token, can be killed.   Your existing 
users may need to be informed of this - I can't see anyway to change the name of that 

You can also run into this problem when upgrading from MVC 1 to MVC 2:

In both cases, a workaround if you can't force your users to restart their browser requires editing the application code and redeploying. You can edit the application so that when the exception occurs, you clear the AntiForgeryToken cookie from the incoming request, and then reissue the token cookie by calling Html.AntiForgeryToken(). However, in doing so, you must take care that you only do it in the appropriate places (e.g. the error page or other page that does not modify data) - otherwise, you lose all the protection from CSRF attacks, which is the whole reason of using the antiforgery token in the first place.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.