Skip to content

fix: escape counter metadata in the counters list HTML - #736

Closed
Ryuga-Hideki-L wants to merge 1 commit into
tosuapp:masterfrom
Ryuga-Hideki-L:fix/escape-counter-html
Closed

Ryuga-Hideki-L wants to merge 1 commit into
tosuapp:masterfrom
Ryuga-Hideki-L:fix/escape-counter-html

Conversation

@Ryuga-Hideki-L

Copy link
Copy Markdown
Contributor

Problem

rebuildJSON in packages/server/utils/counters.ts builds the counters list on /, /available and /api/counters/search/* by inserting counter metadata straight into HTML: name, author, version, folderName, downloadLink, author links and gallery asset URLs. These values come from a counter's metadata.txt (or its folder name) and from https://tosu.app/api.json. The dashboard then puts the search response in the page with innerHTML.

So a counter whose metadata contains markup can run scripts on the tosu dashboard origin, and from there call /api/counters/download/*, /api/counters/delete/*, settings endpoints and so on. A harmless " in a name also breaks the attribute it lands in.

Reproduction

static/evil/metadata.txt:

Name: <img src=x onerror=alert(1)>
Author: a"b<script>
Version: 1.0
Resolution: 300x200

Open the dashboard. On master the list contains

<h4 class="flexer"><img src=x onerror=alert(1)> v1.0</h4>
<div class="calu buttons-group flexer indent-left" n="<img src=x onerror=alert(1)>" a="a"b<script>" v="1.0">

and alert(1) runs.

Solution

Add a small escapeHTML helper in counters.ts and escape every metadata value that rebuildJSON inserts into text or attributes. The existing locals name and author (the HTML fragments) are renamed to nameBlock and authorBlock so the escaped values can use the plain names. The page reads n, a, l and v back through element.attributes.*.value, which returns the decoded text, so download, update, open and delete get the same strings as before.

After the fix the same counter renders as

<h4 class="flexer">&lt;img src=x onerror=alert(1)&gt; v1.0</h4>
<div class="calu buttons-group flexer indent-left" n="&lt;img src=x onerror=alert(1)&gt;" a="a&quot;b&lt;script&gt;" v="1.0">

Affected Files

  • packages/server/utils/counters.ts

Verification

  • Ran buildLocalCounters (through tsx) against a static folder with the metadata.txt above, before and after the change. Output is shown above.
  • prettier --check and eslint pass on the changed file. tsc --noEmit -p packages/server reports no errors in counters.ts.
  • I have not run it against a live osu! client, because the change only touches the dashboard HTML.

AI Declaration

The change was written with Anthropic Claude Opus 5.5 (claude-opus-5-5) and checked against the reproduction above.

Counter name, author, version, folder name and links from metadata.txt
or the remote counter list were inserted into the dashboard HTML as-is,
so a counter could inject markup and scripts into the tosu dashboard.
@KotRikD

KotRikD commented Nov 16, 2026

Copy link
Copy Markdown
Member

@codex review plz

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T23:05:47.462046Z 66e7f2c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66e7f2c143

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +205 to +206
? `${name} v${version}${externalHasSettings}`
: `${name}${externalHasSettings}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Insert escaped values with replacement callbacks

When metadata contains a dollar immediately before < or > (for example Name: Cash $<3), escaping produces Cash $&lt;3. Passing this as a String.replace replacement string interprets $& as the matched placeholder, so the heading becomes Cash {NAME}lt;3 and the button metadata is also corrupted. The same regression gives a Linux folder named $>overlay a {URL}gt;overlay preview path and {BUTTONS}gt;overlay action target, breaking previews and folder actions that previously worked. Use replacement callbacks for escaped values and subsequent HTML-fragment substitutions so their contents are inserted literally.

Useful? React with 👍 / 👎.

@GabuTheDev GabuTheDev added area:dashboard The web frontend of tosu. area:server The nodejs backend of tosu. ai-written Not human made :( labels Nov 17, 2026
@GabuTheDev

Copy link
Copy Markdown
Member

As security, this doesn't hold: a counter is already same-origin HTML/JS with access to the local API, so escaping its metadata prevents nothing.

Per our overlay rules the folder must be {Name} by {Author} and the folder is derived from the metadata name/author on download, so the name is effectively filename-constrained. " can't occur on Windows. Usernames practicaly never contain " either.
Only a Linux-only counter could legitimately have ", < or > in its folder name, which is niche enough that I don't think it's worth the change here.

The remaining concern is code readability: the description is misleading about what the change protects, so I'd rather not have it in the tree as-is. If a concrete case shows up down the line (e.g. a Linux overlay actually breaking), reopen and we can revisit.

@GabuTheDev GabuTheDev closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-written Not human made :( area:dashboard The web frontend of tosu. area:server The nodejs backend of tosu.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants