Why this matters
Deserializing untrusted data can allow attackers to execute arbitrary code. Always validate and sanitize serialized inputs before processing.
Deserializing untrusted data can allow attackers to execute arbitrary code. Always validate and sanitize serialized inputs before processing.
Deserializing untrusted data can allow attackers to execute arbitrary code. Always validate and sanitize serialized inputs before processing.
Side-by-side examples engineers can pattern-match during review.
public class Example : Controller
{
[HttpPost]
public ActionResult Deserialize(HttpPostedFileBase inputFile)
{
ExpectedType expectedObject = null;
var formatter = new BinaryFormatter();
expectedObject = (ExpectedType)formatter.Deserialize(inputFile.InputStream);
}
}public class Example : Controller
{
[HttpPost]
public ActionResult Deserialize(HttpPostedFileBase inputFile)
{
ExpectedType expectedObject = null;
JsonSerializer serializer = new JsonSerializer(typeof(expectedObject));
expectedObject = (ExpectedType)serializer.Deserialize(inputFile.InputStream);
}
}public class Example : Controller
{
[HttpPost]
public ActionResult Deserialize(HttpPostedFileBase inputFile)
{
ExpectedType expectedObject = null;
var formatter = new BinaryFormatter();
expectedObject = (ExpectedType)formatter.Deserialize(inputFile.InputStream);
}
}public class Example : Controller
{
[HttpPost]
public ActionResult Deserialize(HttpPostedFileBase inputFile)
{
ExpectedType expectedObject = null;
JsonSerializer serializer = new JsonSerializer(typeof(expectedObject));
expectedObject = (ExpectedType)serializer.Deserialize(inputFile.InputStream);
}
}From the same buckets as this rule.