Am I affected?

type your saxy version to check

Description

Saxy's XML encoder writes the target and the content of a processing instruction into the output document verbatim, without validation or escaping. The encoder builds the construct by concatenating both fields between <? and ?>, so neither field is checked against the constraints the XML specification places on it.

Because ?> terminates a processing instruction, a target or content value containing that sequence closes the construct at a position the attacker chooses. Everything the attacker writes after it is emitted as ordinary markup at document level, which allows arbitrary elements, attributes, and further processing instructions to be injected into the serialized document. Appending a matching <? keeps the encoder's own terminator well-formed, so the result still parses and the injection is silent rather than a visible corruption. The target is additionally unconstrained by the XML Name production, which permits injection before the remainder of the processing instruction.

The result is XML injection into a serialized document: the tree the application asks Saxy to encode and the tree a downstream parser reads back are no longer the same. Character data, attribute values, and comments are all escaped by the encoder, so processing instructions are the one construct that passes user bytes through untouched. Since Saxy.XML.processing_instruction/2 is a documented public builder, an application inherits the flaw without misusing the API. The consequences depend on what consumes the XML: forged records in a feed or export read by another system, injected stylesheet or rendering directives, or active content where the output is served to a browser as XML or SVG.

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 ↗

≥ 0.7.0 < 1.7.0 affected
every other version: unaffected
cpe cpe:2.3:a:qcam:saxy:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.Saxy' · 'Elixir.Saxy.Encoder' · 'Elixir.Saxy.XML'
source files lib/saxy.ex · lib/saxy/encoder.ex · lib/saxy/xml.ex
routines 'Elixir.Saxy':encode!/2 · 'Elixir.Saxy':encode_to_iodata!/2 · 'Elixir.Saxy.Encoder':encode_to_iodata/2 · 'Elixir.Saxy.XML':processing_instruction/2

Affected — GitHub / qcam/saxy Repository ↗

≥ 7266632 < 4aeb80e affected
every other version: unaffected
cpe cpe:2.3:a:qcam:saxy:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.Saxy' · 'Elixir.Saxy.Encoder' · 'Elixir.Saxy.XML'
source files lib/saxy.ex · lib/saxy/encoder.ex · lib/saxy/xml.ex
routines 'Elixir.Saxy':encode!/2 · 'Elixir.Saxy':encode_to_iodata!/2 · 'Elixir.Saxy.Encoder':encode_to_iodata/2 · 'Elixir.Saxy.XML':processing_instruction/2

Workarounds

Do not place untrusted data in processing instructions. Where a dynamic value is unavoidable, validate it before building the node: reject any content containing ?>, and reject any target that does not match the XML Name production or that equals xml case-insensitively. Alternatively, carry the value in element content or an attribute instead, both of which the encoder escapes.

Configurations

The application must serialize a document containing a processing instruction whose target or content is derived from untrusted input, by passing a {:processing_instruction, name, content} node (typically built with Saxy.XML.processing_instruction/2) to Saxy.encode!/2 or Saxy.encode_to_iodata!/2. Applications that never place dynamic data in processing instructions are not affected.

References

Credits

Peter Ullrich Finder Reporter Remediation developer Coordinator
Cẩm Huỳnh Remediation reviewer
Jonatan Männchen / EEF Analyst

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
« All CVEs