eXtensible Stylesheet Language Transformation (XSLT) is a language enabling the transformation of XML documents. For instance, it can select specific nodes from an XML document and change the XML structure.
XSLT Injection
As the name suggests, XSLT injection occurs whenever user input is inserted into XSL data before output generation by the XSLT processor. This enables an attacker to inject additional XSL elements into the XSL data, which the XSLT processor will execute during output generation.
XSLT
We will use the following sample XML document to explore how XSLT works:
XSLT can be used to define a data format which is subsequently enriched with data from the XML document. XSLT data is structured similarly to XML. However, it contains XSL elements within nodes prefixed with the xsl
-prefix. The following are some commonly used XSL elements:
<xsl:template>
: This element indicates an XSL template. It can contain amatch
attribute that contains a path in the XML document that the template applies to<xsl:value-of>
: This element extracts the value of the XML node specified in theselect
attribute<xsl:for-each>
: This element enables looping over all XML nodes specified in theselect
attribute
For instance, a simple XSLT document used to output all fruits contained within the XML document as well as their color, may look like this:
Combining the sample XML document with the above XSLT data results in the following output:
Here are all the fruits:
Apple (Red)
Banana (Yellow)
Strawberry (Red)