Am I affected?
Description
XML injection in the Saxy XML encoder. Saxy.Encoder.cdata/1 serializes a {:cdata, characters} node by wrapping the supplied characters between <![CDATA[ and ]]> and passing the payload through byte for byte. The encoder's character-data and attribute-value paths escape the XML metacharacters <, >, &, ", and ', but the CDATA path applies no neutralization at all. XML provides no character escaping mechanism inside a CDATA section, so the only correct way to represent a ]]> substring is to split the section and rejoin it as ]]]]><![CDATA[>. Saxy neither performs that split nor rejects the substring.
An application that renders untrusted text as CDATA, by building the node with Saxy.XML.cdata/1 and serializing it with Saxy.encode!/2 or Saxy.encode_to_iodata!/2, therefore lets an attacker terminate the section at a position of their choosing. Everything supplied after the ]]> is emitted outside any CDATA context and is parsed as markup, so a single attacker-controlled text field becomes attacker-controlled document structure: arbitrary sibling elements and attributes that the application never built. Downstream consumers of the serialized document accept the injected markup as genuine. Services that generate SOAP envelopes, RSS or Atom feeds, sitemaps, SVG, or XML exports from user-supplied content can have trusted fields forged or overridden. Applications that never place untrusted text in a CDATA node are not affected.
This issue affects saxy: from 0.7.0 before 1.7.0.
Weaknesses & attack patterns
Weakness
CWE-91
·
XML Injection
in catalog →
MITRE ↗
Attack patterns
CAPEC-250
·
XML Injection
MITRE ↗
Affected — Hex / saxy Hex.pm ↗ Repository ↗
modules · source files · routines
Affected — GitHub / qcam/saxy Repository ↗
modules · source files · routines
Workarounds
Render untrusted text as ordinary character data instead of CDATA, by passing a plain string or Saxy.XML.characters/1 to the element builder. That encoder path escapes the XML metacharacters and preserves the same text content.
If a CDATA section is required, split the terminator in application code before building the node: replace every occurrence of ]]> in the untrusted text with ]]]]><![CDATA[> and pass the result to Saxy.XML.cdata/1. Once the encoder wraps that payload, the output is the standard split encoding.
References
Credits
CVSS breakdown
CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:L/SA:N