security-code-scan / security-code-scan

Vulnerability Patterns Detector for C# and VB.NET
https://security-code-scan.github.io
GNU Lesser General Public License v3.0
942 stars 162 forks source link

Warnings on deserialization where only one argument of two is tainted #44

Open JarLob opened 6 years ago

JarLob commented 6 years ago

For some deserializers like XmlSerializer and DataContractSerializer both type and serialized data have to be tainted to make it exploitable. Currently it gives false positives if only one is:

var deserializer = new XmlSerializer(typeof(MyType));
var my  = deserializer.Deserialize(input) as MyType;

It doesn't mean the MyType cannot be used as a gadget, the class should be investigated further.

JarLob commented 6 years ago

Also consider the example:

        public T Deserialize<T>(string xmlString)
        {
            var serializer = new XmlSerializer(typeof(T));
            StringReader reader = new StringReader(xmlString);
            return (T) serial.Deserialize(reader);
        }

It is tricky to call the function with non-hardcoded T, but can be done with reflection. Thus typeof(T) could be considered unsafe in Audit Mode only.