# XSLT engine for johnmcm.com The WebAssembly module behind the InfoPath Form Viewer (/infopath-viewer), which draws each InfoPath view by applying the view's XSLT to the form's data, and the File Opener, which lays out XML files by the XSL stylesheet they name (with the stylesheets it imports, chosen by the person). Version `xslt@2` added the import loader; `xslt@1` is kept, as served files are never changed in place. The site uses its own engine rather than the browser's `XSLTProcessor` so that views come out the same in every browser, and keep working once Chrome removes its built-in XSLT support. libxslt, libexslt and libxml2 behind a few plain C functions (`src/xslt.c`), built by `Dockerfile` with the Emscripten image pinned by digest and both source tarballs by SHA-256. Run `build.ps1` with Docker Desktop running; the module, its worker and the licence notices go to `frontend/vendor/local/xslt@2/`. | Library | Version | SHA-256 of the release tarball | Licence | Source | |---|---|---|---|---| | libxslt (with libexslt) | 1.1.45 | `9acfe68419c4d06a45c550321b3212762d92f41465062ca4ea19e632ee5d216e` | MIT | https://download.gnome.org/sources/libxslt/1.1/ | | libxml2 | 2.15.4 | `98087fd181d9070724f3fbc65c7377db03038eb92bd882374daff44940138821` | MIT | https://download.gnome.org/sources/libxml2/2.15/ | Both are built unmodified. ## Files - `src/xslt.c`: the C functions (`xt_transform`, `xt_result`, `xt_result_len`, `xt_error`, `xt_release`, and `xt_add_file`, `xt_clear_files`, `xt_set_match_names`, `xt_missing` for imports) and the security set-up below. - `src/run.mjs`: `transform(module, xml, xsl, maxOut, { stylePath, files, byName })` returning `{ ok, output }` or `{ ok: false, error, code, missing }`; used by the worker and by `tests/xslt.test.mjs` and `tests/xml-stylesheet.test.mjs` in Node. - `src/worker.mjs`: the module worker the page talks to (`src/app/infopath-viewer/xslt-engine.ts`), which stops it after a time limit. ## Nothing is fetched or written The view and the data come from an untrusted file, so: - the module is built with no file system (`-sFILESYSTEM=0`) and no dynamic code (`-sDYNAMIC_EXECUTION=0`); libxml2 2.15 has no network code at all; - documents are parsed with no external entities or DTDs (`XML_PARSE_NO_XXE`, `XML_PARSE_NONET`, and an external entity loader that refuses everything) and with libxml2's entity amplification limits on; - libxslt's document loader serves `xsl:import` and `xsl:include` only from the stylesheets the page hands over with the transform (`xt_add_file`; the File Opener passes the .xsl files the person chose), found by the path the href resolves to from the importing stylesheet's own path, or by file name when the person chose loose files and exactly one has that name; at most 64 loads and 16 imports deep. The names asked for and not handed over are listed (`xt_missing`) for the page to ask for. Every other load is refused: `document()` reads nothing (`document('')` still selects the stylesheet itself, which libxslt copies), and nothing on the network; - libxslt's security preferences forbid writing files, creating folders and reading or writing the network, and allow reading only the stylesheet's own name (for `document('')`) and the stylesheets handed over; any other read is refused; - of libexslt, only common (`exsl:node-set`, which InfoPath's `msxsl:node-set` is rewritten to), math, sets, strings and dates are registered: not dyn (`dyn:evaluate`), func or saxon; - work is capped: template depth 1000, 20,000 variables, 20 million template steps, 200 million XPath operations, 512 MB of memory and 16 MB of output. The page also ends the worker if a transform runs past 20 seconds. The InfoPath-specific rewriting (InfoPath's extension functions, imports and `document()` calls taken out) and the cleaning of the output (DOMPurify, a sandboxed frame with its own content security policy) are TypeScript in `frontend/src/app/infopath-viewer/`. Licence notices: `LICENSE-libxslt.txt` and `LICENSE-libxml2.txt` are the upstream `Copyright` files from the tarballs above (libxslt's covers libexslt too). They are also copied next to the built module in `vendor/local/xslt@2/`.