-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The pragma escapes what Jinja sees. The bug is in what Jinja doesn't see.\n\nThe file is `src/pyload/webui/app/themes/modern/templates/js/packages.js`. It sits inside `templates/`, the directory Flask's Jinja2 environment loads. pyLoad renders it on first request and serves the rendered text to the browser as JavaScript. Inside it, the `{{ ... }}` blocks Jinja interpolates are all server-side URL helpers and i18n strings, the kind a Flask router resolves once at render time:\n\n```js\n$.post({\n url: \"{{url_for('json.package_order')}}\",\n dataType: 'json',\n contentType: 'application/json',\n data: JSON.stringify({ pack_id: ui.item.data('pid'), pos: newIndex }),\n ...\n});\n```\n\nThere are seventeen of these in the modern theme's `packages.js`. Each is a static reference to a Flask endpoint, or a translated string like `{{_('Delete Link')}}`. None of them carry attacker-controlled data. They render to the same value on every request to every operator.\n\nThe `{% autoescape true %}` block at the top of the file tells Jinja to apply `Markup`-style HTML escaping to those `{{ ... }}` interpolations as the file is served. Setting it true is the safer default in modern Flask. The pyLoad developer who created this file in April set it correctly.\n\nThe XSS does not pass through Jinja. The XSS passes through the JavaScript that Jinja delivered.\n\nInside the same file, the method `Package.createLinks(data)` runs in the browser when an operator clicks a package row to expand it. It receives the JSON response of `$.get(\"{{url_for('json.package')}}\", {id: this.id})`. The response is the list of links the operator's pyLoad instance is downloading inside that package. The pre-patch implementation, removed wholesale on May 10 in commit `2391fce`, assembles each link's row by string concatenation:\n\n```js\ncreateLinks(data) {\n const ul = $(`#sort_children_${this.id}`);\n ul.html(\"\");\n data.links.forEach(link => {\n link.id = link.fid;\n const li = document.createElement(\"li\");\n $(li).css(\"margin-left\", 0);\n\n link.icon = this.getLinkIcon(link.status);\n\n const html = `\n \n \n \n \n ${link.name}\n
\n
\n ${link.statusmsg} ${link.error} \n ${link.format_size}\n ${link.plugin}  \n   \n \n
`;\n\n const div = document.createElement(\"div\");\n $(div).attr(\"id\", `file_${link.id}`);\n $(div).css(\"padding-left\", \"30px\");\n $(div).css(\"cursor\", \"grab\");\n $(div).addClass(\"child\");\n $(div).html(html);\n\n jQuery.data(li, \"lid\", link.id);\n li.appendChild(div);\n ul[0].appendChild(li);\n });\n ...\n}\n```\n\nThe six `${link.…}` substitutions are JavaScript template-literal interpolations. They happen in V8, not Jinja. They paste fields of the JSON response into one string. The string is then handed to jQuery's `.html(html)`, which assigns to `innerHTML`, which parses the string as HTML and inserts the resulting DOM.\n\nThe parser, when it reaches `filename\n...\n```\n\n`$(div).html(html)` parses it. The parser produces an `` element whose `href` is `https://x` and whose attributes include `onmouseover` carrying Alice's script. The first time the operator's mouse crosses the link, the handler fires. The fetch goes out from the operator's browser with the operator's session cookie. The pyLoad backend sees an authenticated admin request from its own UI and honors it. Alice's user record changes role to `0`, the admin role. The next time Alice signs in, she is an operator.\n\nThe CVSS vector recorded for CVE-2026-45348 is `AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:N`. The `PR:L` is Alice. The `S:C` is the scope change from her user session to the operator's admin session. The `UI:R` is the operator moving their mouse.\n\n## The patch does not escape. The patch removes the primitive.\n\nThe fix is commit [`2391fce`](https://github.com/pyload/pyload/commit/2391fced2632aa85d03384a42d01fc2062faebf4), authored by GammaC0de on May 10, 2026. It does not add a sanitizer function. It does not call `encodeURIComponent` on `link.url`. It does not switch the surrounding HTML's single-quoted attributes to double-quoted ones and call that done. It rewrites `createLinks` to stop assembling HTML as a string at all:\n\n```diff\n- const html = `\n- ...\n- ${link.name}\n- ...`;\n- const div = document.createElement(\"div\");\n- $(div).attr(\"id\", `file_${link.id}`);\n- $(div).addClass(\"child\");\n- $(div).html(html);\n+ const $firstRow = $('
').append(\n+ $('', { class: `child_status` }).append(\n+ $('', {\n+ class: this.getLinkIcon(link.status),\n+ style: 'margin-right: 2px; color: #337ab7;'\n+ })\n+ ),\n+ $('', {\n+ style: 'font-size: 16px; font-weight: bold;'\n+ }).append(\n+ $('', {href: link.url}).text(link.name || '').click((e) => {e.preventDefault();})\n+ )\n+ );\n```\n\nThe new code constructs the DOM as jQuery objects. `$('', {href: link.url})` sets the href through `setAttribute`, which assigns the string literally without invoking the HTML parser on its contents. `.text(link.name || '')` sets the anchor's text via `textContent`, which also never invokes the HTML parser. Status, error, size, and plugin all go through `.text()`. The static decoration (the trash and repeat glyphs, the row container's classes and styles) is built from object literals jQuery owns end to end.\n\nNo string assembled from attacker-controlled values reaches `innerHTML`. The primitive that made the bug possible is gone. The same commit applies the same rewrite to the pyplex theme's `packages.js`, where the identical pattern existed verbatim with different style colors. Both themes had the same bug because both themes were generated from the same shape. The fix replaces the shape.\n\nAdding `_.escape(link.url)` to the pre-patch template literal would have closed the demonstrated case. It would have also left the template-literal-to-innerHTML primitive in the codebase for the next field someone forgets to wrap. The author chose to remove the primitive instead.\n\n## The pragma's coverage and the sink's coverage are not the same set.\n\npyLoad's modern theme has the safety primitive a Flask developer reaches for: the `autoescape` block, set true, at the top of the file. The primitive is real; Jinja honors it; the seventeen Jinja interpolations in the file render exactly as the pragma promises. The developer understood what XSS is. The developer set the pragma to its safer value.\n\nThe pragma's interpreter is Jinja. Jinja runs once, when the file is rendered into JavaScript. The dangerous interpreter is the browser's HTML parser, invoked by `$(div).html(html)`, on a string assembled by the browser's JavaScript runtime, from data that arrives over an async XHR Jinja was never involved in. The pragma's coverage is a set of bytes the server transformed. The sink's coverage is a set of bytes the browser later assembled. The two sets do not intersect.\n\nThis is the shape we are filing under [`escape-was-for-the-other-engine`](/patterns/escape-was-for-the-other-engine): a server-side safety primitive correctly covering one rendering pipeline, while the same file emits a second rendering pipeline (client-side template literal interpolation into innerHTML, on data that arrives by separate channel) the primitive cannot see. The primitive does not run there. The developer reads the pragma as \"this file is escaped\" and is right about the engine the pragma names.\n\nA pyLoad maintainer can do everything Flask's documentation tells them to do, set `autoescape` true, prefer `Markup` over `|safe`, audit every `{{ }}` for source, and still ship this bug. The framework's primitive is for the framework's interpreter. JavaScript template literals are not Jinja. Browser `innerHTML` is not Jinja.\n\nThe wave of GitHub security advisories pyLoad closed in April and May, the one this CVE belongs to, runs at nine. The fix authored alongside this one rewrites the file's twin in the pyplex theme. The April commit that originally added these files closed two more advisories on the same day it created them. The pattern that produced this bug, server-rendered Jinja files emitting client-side templating against authenticated JSON APIs, is the architecture, not the bug. The pragma cannot reach across it. No pragma can.\n\nPatch: [pyload/pyload@2391fce](https://github.com/pyload/pyload/commit/2391fced2632aa85d03384a42d01fc2062faebf4)\nAdvisory: [GHSA-fcjq-435v-jx94](https://github.com/advisories/GHSA-fcjq-435v-jx94)","closing_line":"The pragma escapes what Jinja renders. The bug runs in what Jinja never sees.","hook_md":"The first line of pyLoad's downloads-view JavaScript template reads `{% autoescape true %}`. The pragma tells Jinja2 to HTML-escape every `{{ ... }}` interpolation rendered into the file before the file leaves the server. The file has seventeen such interpolations. None of them carry the bug.\n\nThe bug lives in expressions of the form `${link.url}`. Those are JavaScript template literals. Jinja does not parse `${...}`. They interpolate, at runtime in the operator's browser, the JSON response of an async `$.get` against an API endpoint a low-privilege user controls.\n\nCVE-2026-45348 is the gap between the template engine the safety pragma was written for and the template engine that handed the attacker the sink.","post_id":548,"slug":"pyload-cve-2026-45348-the-autoescape-was-for-jinja","title":"CVE-2026-45348: pyLoad Wrapped the Vulnerable File in Jinja's Autoescape Pragma","type":"initial","unreadable_sentence":"The pragma escapes what Jinja renders. The bug runs in what Jinja never sees."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaqHDWwAKCRDeZjl4jgkQ JqivAP9EfxGGBLAovNzaMihIWJ3o0e5hzZl+aMat+GYhhvAPaAEAgOBm87bBLOz0 EUx8cBLZqWfzvqXQbw/Y6plHP/NnZAI= =WS69 -----END PGP SIGNATURE-----