davsclaus opened a new pull request, #3336:
URL: https://github.com/apache/camel-kamelets/pull/3336

   Two new action Kamelets, the XML counterparts of `jslt-action` and 
`json-schema-validator-action`.
   
   ## `xslt-action`
   
   Transforms each XML message with an XSLT stylesheet, with the Camel 
`xslt-saxon` component.
   
   - Option: `template` (required): where to load the stylesheet from 
(`file://`, `classpath://`, `http(s)://`), as in `xj-template-action`.
   - Input: XML as text, bytes or a stream. A header whose name is an 
`xsl:param` of the stylesheet sets that parameter.
   - Output: the result as a String (XML, or plain text with `xsl:output 
method="text"`). No `Content-Type` is set; the other headers are kept.
   - Headers that start with `CamelXslt` are removed first, so a message cannot 
switch the stylesheet (`CamelXsltResourceUri` / `CamelXsltStylesheet`).
   - No `dataTypes` default: the stylesheet can write XML, text or JSON.
   
   Why `xslt-saxon` and not `xslt`: it runs XSLT 3.0 (the JDK's `xslt` 
component is XSLT 1.0 only), `secureProcessing` is on by default, and with the 
default `allowStAX` the body is read through Camel's StAX converter, which 
ignores the DOCTYPE of the message.
   
   The stylesheet is a bound property only, not inline text. All the other 
template actions take a location, and stylesheet text does not fit in an 
endpoint URI (`?`, `&`, `#` and newlines). The other ways to pass text inline 
were `allowTemplateFromHeader`, which compiles the stylesheet for every message 
and lets a header pick the stylesheet, or a `mem:` resource in the URI.
   
   ## `xml-schema-validator-action`
   
   Checks each XML message against an XML Schema (XSD), with the Camel 
`validator` component.
   
   - Option: `template` (required): where to load the XSD from, as in 
`json-schema-validator-action`.
   - Input: XML as text, bytes or a stream. Output: the same message, unchanged 
(text stays text, bytes stay bytes).
   - An invalid document, or a body that is not XML, fails the message with a 
`SchemaValidationException` that lists the errors (e.g. 
`cvc-datatype-valid.1.2.1: 'abc' is not a valid value for 'decimal'.`).
   - `dataTypes` as in `json-schema-validator-action` 
(`application-x-unchanged`).
   
   ## Security (the XML body is untrusted)
   
   Both Kamelets were checked with the Camel defaults, so the templates set no 
extra option:
   
   - `xslt-action`: the DOCTYPE of the message is not used. An external entity 
(`file:///etc/hosts`, an `http://` URL, an external parameter entity) is not 
read, and nested entities (a billion laughs) are not expanded: `&x;` gives 
nothing. I checked this for String, byte[] and InputStream bodies.
   - `xml-schema-validator-action`: an external entity fails the message 
(`'file' access is not allowed due to restriction set by the accessExternalDTD 
property`, and the same for `http`), and a billion laughs stops at the JDK's 
`jdk.xml.entityExpansionLimit`.
   - For the `http` cases, a local HTTP server got no request.
   - The stylesheet and the schema are operator-trusted bound properties. The 
description says that XSLT functions such as `document()` can read other 
resources, and that a message can set any stylesheet parameter with a header.
   
   ## Tests
   
   New `XmlIT` (package `xml`, no container or server, it checks the Camel log):
   
   - `xslt-action-test`: an XSLT 3.0 transformation with a parameter from a 
header; a byte[] body with the parameter default, where the `CamelXslt*` 
headers are ignored; `document()` from the classpath; XXE from a stream; a 
billion laughs; a body that is not XML.
   - `xml-schema-validator-action-test`: a valid String and a valid byte[] 
(unchanged); an invalid document (the errors are listed); XXE; a billion 
laughs; a body that is not XML.
   
   Local results (Camel 4.24.0-SNAPSHOT, JDK 25):
   - `./mvnw -o clean install -DskipITs`: OK.
   - `-Dit.test=XmlIT`: 2 tests, 2 passed (about 40 s).
   
   Both Kamelets are labelled `camel.apache.org/kamelet.verified: "true"`.
   
   Fixes #3330.
   
   ## Upgrade note
   
   ```
   * New Kamelets `xslt-action` (transforms XML with an XSLT 3.0 stylesheet, 
with Saxon) and `xml-schema-validator-action` (validates XML against an XML 
Schema and fails the messages that do not match).
   ```
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to