Skip to main content
MediumHost validationOWASP A08:2021CWE-345

How to fix: ASP.NET ViewState Without MAC Protection

An ASP.NET ViewState field was found without a corresponding __VIEWSTATEMAC field in the page markup, or with enableViewStateMac explicitly disabled. This check reads the rendered HTML only: a sibling __VIEWSTATEMAC field is one way ASP.NET represents a MAC, but some versions/configurations embed the MAC inside __VIEWSTATE itself instead, which cannot be confirmed without decoding the ViewState payload. Treat the no-sibling-field case as needing manual verification rather than a confirmed vulnerability; an explicit enableViewStateMac="false" in the markup is a confirmed misconfiguration.

Why it matters

Forged ViewState enables deserialization attacks against ASP.NET's ObjectStateFormatter. An attacker who knows the machineKey (or when no MAC is required) can craft a ViewState payload that executes arbitrary .NET code on the server.

ASP.NET's ViewState stores page state between requests. The MAC (Message Authentication Code) prevents tampering. Without it, an attacker can inject malicious serialized objects into the ViewState, exploiting .NET deserialization gadget chains.

How to fix it

  1. 1Never set EnableViewStateMac=false or ViewStateEncryptionMode=Never.
  2. 2Ensure <machineKey> is configured with a strong random validationKey.
  3. 3Consider enabling ViewState encryption: ViewStateEncryptionMode='Always'.
  4. 4Upgrade to .NET 4.5.2+ which enforces ViewState MAC by default.

Code examples

Web.config ViewState protection

XML
<configuration>
  <system.web>
    <!-- Always require MAC validation -->
    <pages enableViewStateMac="true" viewStateEncryptionMode="Always" />
    <machineKey
      validationKey="[strong-random-key]"
      decryptionKey="[strong-random-key]"
      validation="HMACSHA256"
      decryption="AES" />
  </system.web>
</configuration>

References

Detected automatically by VulnRadar. The check id is aspnet-viewstate-no-mac, stable across every scan so you can filter or diff on it.

See every host validation check

Questions

How severe is ASP.NET ViewState Without MAC Protection?
VulnRadar rates this medium severity in the host validation category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id aspnet-viewstate-no-mac, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does ASP.NET ViewState Without MAC Protection map to?
It maps to CWE-345. In the OWASP Top 10 it falls under A08:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for asp.net viewstate without mac protection

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

ASP.NET ViewState Without MAC Protection fix | VulnRadar