Summary
An XML encoding issue in Kirby's Xml::value() method allows specially crafted input to bypass CDATA value protection and inject additional XML structured data alongside valid CDATA blocks.
When site or plugin code uses Kirby utilities to generate XML from user input and that XML is consumed by another system that interprets the XML schema, an attacker may be able to manipulate that downstream system's behavior.
Affected context
This vulnerability arises in Kirby-based projects that:
- Use
Xml::value(),Xml::tag(),Xml::create()or theXmldata handler (Data::encode($string, 'xml')) to build XML from untrusted or semi-trusted data, and - Forward the generated XML to other components or external systems that interpret the XML structure (e.g., APIs, configuration processors, or integration endpoints).
The Kirby core itself does not invoke these methods in a way that exposes the bug by default; the risk exists primarily in custom site templates, controllers, or plugins that perform XML generation.
Exploit preconditions
- Attack surface: XML generation pathways using
Xml::value(),Xml::tag(),Xml::create()orData::encode(..., 'xml')with attacker-controlled or user-supplied input. - Required access: Ability to influence the data passed into these XML helper methods (e.g., form fields, query parameters, content fields stored in Kirby, or plugin configuration).
- Trigger point: The crafted string is processed by
Xml::value(), which incorrectly treats partially wrapped input as safe CDATA and outputs it without proper escaping. - Why exploitation is possible: The CDATA detection logic previously only checked for the presence of valid CDATA blocks and allowed passthrough when such a block existed, even if additional XML markup or structured data appeared outside those blocks. This breaks the intended trust boundary and allows XML injection.
Why this happens
The underlying issue is an improper sanitization and encoding of output values in XML context, aligning with CWE-91: XML Injection.
The Xml::value() method contains special logic to avoid double-escaping values that are already wrapped in <![CDATA[ ... ]]>. However, the implementation validated only that the input contained valid CDATA, not that the entire string was composed exclusively of one or more CDATA sections.
As a result, attackers could craft input that started or included a valid CDATA block while also appending or prepending additional XML markup or entities outside those blocks. Because the function treated such input as safe, the surrounding structured content was emitted verbatim into the XML output, bypassing the intended encoding layer.
Abstractly, this represents a flawed context-aware encoder: it conditionally skips escaping based on an incomplete structural check, allowing attacker-controlled content to cross the boundary from "data" into "XML structure."
Potential impact
- Injection of additional XML elements, attributes, or entity references into generated XML documents.
- Manipulation of downstream systems that interpret the XML schema, such as:
- Altering configuration values or flags encoded in XML.
- Influencing access control or routing decisions based on XML content.
- Tampering with data feeds, API requests, or integration payloads that rely on XML.
- Potential chaining with other XML-related weaknesses in downstream consumers (e.g., logic flaws, misrouting, or over-permissive XML mappers).
- Integrity impact on systems that treat the XML as authoritative configuration or business data.
General mitigation guidance
Effective mitigation focuses on robust, context-aware XML encoding and tight control over when raw CDATA is trusted:
- Ensure that XML helper methods only skip escaping when the entire value is verified as strictly composed of valid CDATA blocks, without any extra markup or text outside of them.
- Favor safe-by-default encoders that always escape special XML characters (
<,>,&,",') unless there is a compelling need to support raw CDATA, and that enforce strict structural checks whenever they detect CDATA wrappers. - Treat all user-supplied or external input as untrusted and encode it as pure data within XML elements or attributes, rather than allowing it to define or modify XML structure.
- Apply a clear separation between data and schema: only static, vetted code should define element and attribute names, while dynamic values are always encoded as content.
- Where possible, reduce the need for raw CDATA by normalizing or transforming inputs into safe representations (e.g., base64 or entity-escaped text) before embedding in XML.
- Use least-privilege design for downstream components consuming the XML so that injected XML has limited authority to alter critical application behavior.
How teams detect issues like this
Identification of this class of issue typically involves both code-centric and behavior-centric approaches:
- Static analysis and code review:
- Search for usage of
Xml::value(),Xml::tag(),Xml::create(), andData::encode(..., 'xml')where parameters may derive from request data, editable content, or other untrusted sources. - Inspect custom logic that conditionally disables escaping based on CDATA detection or patterns like
<
