Resolving Deserialization of Untrusted Data (CWE ID 502) flaw

To Veracode support 

I am trying to resolve a medium CWE 502 flaw which the Veracode scan has reported on a scan of our asp.net web form application, targeting the .net 4.5.2 framework. The flaw is 

Deserialization of Untrusted Data (CWE ID 502)(1 flaw)

 

The issue is serialization of the view state which uses the LOS formatter. ASP.NET makes use of LosFormatter to serialize the viewstate and send it to the client as the hidden form field. Once the serialized viewstate is sent back to the server during a POST request.  The scan is reporting the error on deserialize as below highlighted.

var losFormatter = new System.Web.UI.LosFormatter();

var reader = new System.IO.StringReader(viewState);

object deSerialized = losFormatter.Deserialize(reader);

ParseViewStateGraph(deSerialized, 0, "", decoded);

 

Reading the article below from Microsoft, these formatters are to be avoided.

·      SoapFormatter

·      NetDataContractSerializer

·      LosFormatter

·      ObjectStateFormatter

 

https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide

I tried several alternative serilizers as JSON and XML but this using these has failed as the view state has been serialized natively in ASP.Net in the LosFormatter.  I am unsure how to proceed forward.

Please help recommend a solution or can this be mitigated against.


Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.