Security: Potential XSS via unescaped template variables injected into inline JavaScript#990
Conversation
The template disables autoescaping and injects user-influenced values (such as `cdx.url`, `top_url`, `coll`, and others) directly into JavaScript string literals. If any value contains quotes, backslashes, or script-breaking payloads, it can execute arbitrary JavaScript in the replay UI. Affected files: head_insert.html Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
|
You didn't remove the autoescape? And there's no test. Also note that there's some history behind this detail -- in 2021 Ilya checked in autoescape false and also added a comment in CHANGES.rst that he was fixing an xss pointed out by Sebastian. So that's a little weird. @ikreymer @sebastian-nagel |
|
While this should be fixed just for the principle of it, I couldn't find a straightforward way to exploit this from the frontend because the browser will encode I did verify that you can inject scripts via It looks like |
| wbinfo.proxy_magic = "{{ env.pywb_proxy_magic }}"; | ||
| wbinfo.static_prefix = "{{ static_prefix }}/"; | ||
| wbinfo.coll = {{ coll | tojson }}; | ||
| wbinfo.proxy_magic = {{ env.pywb_proxy_magic | tojson }}; |
There was a problem hiding this comment.
File "pywb/templates/head_insert.html", line 27, in top-level template code
wbinfo.proxy_magic = {{ env.pywb_proxy_magic | tojson }};
^^^^^^^^^^^^^^^^^^^^^^^^^
File "pywb/rewrite/templateview.py", line 269, in tojson
return json.dumps(obj)
^^^^^^^^^^^^^^^
TypeError: Undefined is not JSON serializable
Problem
The template disables autoescaping and injects user-influenced values (such as
cdx.url,top_url,coll, and others) directly into JavaScript string literals. If any value contains quotes, backslashes, or script-breaking payloads, it can execute arbitrary JavaScript in the replay UI.Severity:
highFile:
pywb/templates/head_insert.htmlSolution
Remove
autoescape falsefor script data paths and serialize all dynamic JS values using safe JSON encoding (for example|tojson) instead of manual quoted interpolation.Changes
pywb/templates/head_insert.html(modified)Testing