You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stored XSS in cooking mode: step-image path is inserted into innerHTML with an escaper that keeps double quotes #548
Cooking mode builds each step card with innerHTML, and puts the step image path into src="…" after running it through an escaper that only encodes &, < and > — it uses textContent → innerHTML, which leaves " alone. The path comes from the recipe's folder and file names, which the server never URL-encodes. A folder name containing a double quote therefore breaks out of the attribute and runs script on the server's own origin.
The server-side template renders the same value correctly; only the JavaScript re-render is affected.
a6b0d21 (feat(cooking-mode): add cooking mode JS with carousel, swipe, and wake lock, merged in #263).
Reproduction
In the served folder:
mkdir 'x" onerror="alert(document.domain)" y="'cd'x" onerror="alert(document.domain)" y="'printf'Mix @flour{1%%cup}.\n\nBake for ~{20%%minutes}.\n'> Pancakes.cook
cp ../Breakfast/*.jpg Pancakes.1.jpg # any image, named for step 1
Open the recipe in the browser and press c (or click Cook). The card is rendered as
A recipe collection that is shared, synced from cook.md, or cloned from a repository is enough to deliver this; the user only has to open cooking mode. cook build web emits the same markup, so the static site is affected too.
Impact
Script runs on the server's origin, so it passes the CSRF write guard and can PUT/DELETE any recipe through the API (and, with #545, any file in the folder), read everything the user can, and keep running in the tab.
Suggested fix
Build the <img> with document.createElement + setAttribute (or escape " and ' as well; textContent/innerHTML is not an attribute escaper).
Percent-encode each path segment in get_image_path, which also fixes folder names containing #, ? or % not loading their images at all.
Regression test: a fixture folder with a " in its name, asserting the rendered src.
Activity
fix(web): stop step picture paths escaping cooking mode's img src