viewer/studio: escape texture preview URL and format in texture grid cards (VIEWER-STUDIO-TEXTURE-ESCAPE) #704

Merged
kirigayakazima merged 1 commit from upstream-pr/704 into main 2026-11-24 14:37:48 +00:00
kirigayakazima commented 2026-11-24 12:25:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-24T12:25:06Z.


Claimed in the coordination issue as: VIEWER-STUDIO-TEXTURE-ESCAPE https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131376751

What and why

In viewer/studio.html (renderTexturesGrid), escapeHtml was applied to t.name, while t.preview (src="...") and t.format (<span>...</span>) were interpolated raw into card.innerHTML in both the initial 80-card batch and the "show all" batch.

A hostile t.preview or t.format string containing quotes/markup (for example "><img src=x onerror=alert(1)>) broke out of the HTML attribute/element and injected elements/event handlers. Escaping both fields with escapeHtml(t.preview) and escapeHtml(t.format) in both batches aligns them with t.name and the model list in renderAccordionList.

Adds a synthetic regression test in tests/test_viewer_studio.cjs covering both preview and format across card 0 (initial batch) and card 80 ("show all" batch). No game files used.

Tested

Windows 11 x64, Node v24.19.0, Python 3.14.7, CPU only, synthetic inputs only (no game files). Commit 9280ce0370ecbfe935a445e8cb125d1bdb9bfccf.

  • node tests/test_viewer_studio.cjs:
    • before the fix in viewer/studio.html: new test fails with injected <img src=x onerror=alert(1)> tag in tagShape(...);
    • with the fix: 12/12 passed, 0 failed.
  • node tests/test_viewer_streaming.cjs: 57/57 passed, 0 failed.
  • python -I tests/test_viewer_cdn_integrity.py: 10 tests, OK.
  • python -I tests/test_ci_registration.py: 15 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py viewer/studio.html tests/test_viewer_studio.cjs and git diff --check: clean (exit 0).

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5472099714 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/704). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-24T12:25:06Z. --- Claimed in the coordination issue as: VIEWER-STUDIO-TEXTURE-ESCAPE https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131376751 ### What and why In `viewer/studio.html` (`renderTexturesGrid`), `escapeHtml` was applied to `t.name`, while `t.preview` (`src="..."`) and `t.format` (`<span>...</span>`) were interpolated raw into `card.innerHTML` in both the initial 80-card batch and the `"show all"` batch. A hostile `t.preview` or `t.format` string containing quotes/markup (for example `"><img src=x onerror=alert(1)>`) broke out of the HTML attribute/element and injected elements/event handlers. Escaping both fields with `escapeHtml(t.preview)` and `escapeHtml(t.format)` in both batches aligns them with `t.name` and the model list in `renderAccordionList`. Adds a synthetic regression test in `tests/test_viewer_studio.cjs` covering both `preview` and `format` across card 0 (initial batch) and card 80 (`"show all"` batch). No game files used. ### Tested Windows 11 x64, Node v24.19.0, Python 3.14.7, CPU only, synthetic inputs only (no game files). Commit `9280ce0370ecbfe935a445e8cb125d1bdb9bfccf`. - `node tests/test_viewer_studio.cjs`: - before the fix in `viewer/studio.html`: new test fails with injected `<img src=x onerror=alert(1)>` tag in `tagShape(...)`; - with the fix: **12/12 passed, 0 failed**. - `node tests/test_viewer_streaming.cjs`: **57/57 passed, 0 failed**. - `python -I tests/test_viewer_cdn_integrity.py`: **10 tests, OK**. - `python -I tests/test_ci_registration.py`: **15 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py viewer/studio.html tests/test_viewer_studio.cjs` and `git diff --check`: clean (exit `0`). GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
abnalstlll-byte commented 2026-11-24 12:29:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T12:29:16Z.

Review: APPROVED


Reviewed and verified VIEWER-STUDIO-TEXTURE-ESCAPE. Escaping \ .preview\ in the <img>\ src attribute and \ .format\ in the texture metadata card with \escapeHtml()\ closes markup injection vectors in both initial and show-all batches. Unit test in \ ests/test_viewer_studio.cjs\ confirms tag shape stability and unescaped payload rejection. Approved.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039198638 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/704#pullrequestreview-6039198638). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T12:29:16Z. **Review:** APPROVED --- Reviewed and verified VIEWER-STUDIO-TEXTURE-ESCAPE. Escaping \ .preview\ in the \<img>\ src attribute and \ .format\ in the texture metadata card with \escapeHtml()\ closes markup injection vectors in both initial and show-all batches. Unit test in \ ests/test_viewer_studio.cjs\ confirms tag shape stability and unescaped payload rejection. Approved.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!704
No description provided.