CVE-2021-23899: Arbitrary code injection in json-sanitizer

Summary

16/06/2021
Yes i
Critical
9.8

CVE-2021-23899: Arbitrary code injection in json-sanitizer. Affects com.mikesamuel:json-sanitizer versions < 1.2.2. Fixed in 1.2.2. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The json-sanitizer package, provided by com.mikesamuel, is a Maven ecosystem package used for sanitizing JSON data. It ensures that JSON input is safe to embed in HTML or XML documents. The package is designed to prevent cross-site scripting (XSS) attacks by removing potentially harmful content from JSON strings. However, prior to version 1.2.2, the package had a vulnerability that allowed for arbitrary code injection.

Vulnerability Detail

The vulnerability in json-sanitizer (before version 1.2.2) arises from the package emitting closing SCRIPT tags and CDATA section delimiters for crafted input. This flaw enables an attacker to inject arbitrary HTML or XML into embedding documents. By exploiting this vulnerability, an attacker can execute malicious code within the context of the embedding document, potentially leading to various security risks such as cross-site scripting attacks, data theft, or unauthorized access.

How To Fix

Minimum fixed version

1.2.2

This is the first release that contains the fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, developers can manually sanitize the JSON input using alternative methods or libraries that are not affected by this vulnerability. One possible approach is to use a custom sanitization function that removes any potentially harmful content from the JSON string before embedding it in HTML or XML documents. Here's an example of a basic sanitization function in Java:

import org.apache.commons.text.StringEscapeUtils;

public class JsonSanitizer {
  public static String sanitize(String json) {
    // Remove potentially harmful content
    String sanitizedJson = StringEscapeUtils.escapeHtml4(json);
    return sanitizedJson;
  }
}

Conclusion

The json-sanitizer package, prior to version 1.2.2, is vulnerable to arbitrary code injection. This can be exploited by attackers to inject malicious HTML or XML into embedding documents, potentially leading to various security risks. To mitigate this vulnerability, it is crucial to upgrade the package to version 1.2.2 or later. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for com.mikesamuel:json-sanitizer →

Share this vulnerability

FAQ

This vulnerability allows an attacker to inject arbitrary HTML or XML into embedding documents, potentially leading to cross-site scripting attacks, data theft, or unauthorized access.

Versions of json-sanitizer prior to 1.2.2 are affected by this vulnerability.

At the time of this report, there are no known public exploits specifically targeting this vulnerability. However, it is important to promptly update the package to mitigate any potential risks.

Yes, the vulnerability can be fixed by upgrading the json-sanitizer package to version 1.2.2 or later.

Yes, as a temporary workaround, you can manually sanitize the JSON input using alternative methods or libraries that are not affected by this vulnerability. The provided code snippet demonstrates a basic sanitization function in Java.

Related vulnerabilities

Recent vulnerabilities recorded for com.mikesamuel:json-sanitizer.

How To Fix

Minimum fixed version

1.2.2

This is the first release that contains the fix.

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback