CVE-2021-23899

9.8 CRITICAL

📋 TL;DR

CVE-2021-23899 is a vulnerability in OWASP json-sanitizer versions before 1.2.2 where the sanitizer fails to properly escape closing SCRIPT tags and CDATA section delimiters. This allows attackers to inject arbitrary HTML or XML into embedding documents when processing crafted JSON input. Any application using vulnerable versions of OWASP json-sanitizer to sanitize JSON before embedding it in HTML/XML documents is affected.

💻 Affected Systems

Products:
  • OWASP json-sanitizer
Versions: All versions before 1.2.2
Operating Systems: All
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects applications that use json-sanitizer to process JSON that will be embedded in HTML or XML documents.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete compromise of web application security leading to cross-site scripting (XSS) attacks, data theft, session hijacking, and potential remote code execution depending on application context.

🟠

Likely Case

Cross-site scripting (XSS) attacks allowing attackers to steal user sessions, redirect users to malicious sites, or perform actions on behalf of authenticated users.

🟢

If Mitigated

Limited impact with proper output encoding and additional security layers, though injection vectors remain possible.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the application to embed sanitized JSON output in HTML/XML contexts. Proof-of-concept examples are available in the GitHub commit diff.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 1.2.2

Vendor Advisory: https://groups.google.com/g/json-sanitizer-support/c/dAW1AeNMoA0

Restart Required: No

Instructions:

1. Update json-sanitizer dependency to version 1.2.2 or later. 2. For Maven projects: Update pom.xml to <version>1.2.2</version>. 3. For Gradle projects: Update build.gradle to implementation 'com.google.json-sanitizer:json-sanitizer:1.2.2'. 4. Rebuild and redeploy application.

🔧 Temporary Workarounds

Input Validation and Output Encoding

all

Implement additional input validation and context-aware output encoding for JSON data before embedding in HTML/XML.

Content Security Policy

all

Implement strict Content Security Policy headers to mitigate XSS impact.

🧯 If You Can't Patch

  • Implement additional output encoding layers specifically for SCRIPT and CDATA delimiters
  • Isolate json-sanitizer usage to non-HTML/XML contexts only

🔍 How to Verify

Check if Vulnerable:

Check your project's dependency management file (pom.xml, build.gradle, package.json) for json-sanitizer version below 1.2.2.

Check Version:

For Maven: mvn dependency:tree | grep json-sanitizer; For Gradle: gradle dependencies | grep json-sanitizer

Verify Fix Applied:

Verify json-sanitizer version is 1.2.2 or higher in dependencies and test with known malicious JSON inputs containing SCRIPT and CDATA delimiters.

📡 Detection & Monitoring

Log Indicators:

  • Unusual patterns of JSON processing errors
  • Increased sanitization failures

Network Indicators:

  • HTTP requests containing crafted JSON with SCRIPT or CDATA patterns

SIEM Query:

web_requests WHERE request_body CONTAINS '</script>' OR request_body CONTAINS ']]>' AND uri_path CONTAINS 'json'

🔗 References

📤 Share & Export