Repository navigation
Conversation
added 2 commits
November 13, 2026 11:01
upload.html disables Askama's auto-escaping (escape = "none"), and while
paste content already goes through a manual content_escaped() call, the
uploaded filename accessors (name(), display_name(), extension()) did not,
and are fully attacker-controlled (only '.replace(' ', '_')' is applied,
nothing HTML-related).
This allowed two independently confirmed exploitation paths against a
local build:
- Tag injection: a filename containing a tab character instead of a
space (the app only filters literal spaces) survives into the raw
HTML, e.g. "<svg\tonload=alert(1)>.txt" renders as a live <svg> element
with a real onload handler.
- Attribute breakout in the multi-file/gallery view: a filename like
'x" onmouseover="alert(1)" foo="' closes the existing title="..."
attribute early and injects a real onmouseover handler onto the
element - all major browsers recover from the resulting (technically
invalid) markup by starting a new attribute, so no whitespace is even
required for this variant.
Fix: add name_escaped()/display_name_escaped()/extension_escaped()
accessors on PastaFile using html_escape::encode_quoted_attribute (which
escapes &, <, >, ", and ') and use them at every render site in
upload.html and file_card.html, including the one spot embedding a
filename inside a single-quoted JS string literal.
Both exploitation paths were re-tested after the fix and confirmed
neutralized (payload now renders as inert escaped text).
IDs were generated as rand::thread_rng().gen::<u16>() as u64 - only 65,536 possible values. This undermines the 'Unlisted' privacy level, whose entire security model is 'can't be found unless you know the unique identifier': 65,536 is trivially enumerable by brute force. Confirmed empirically by decoding real-world slugs generated during testing (e.g. falcon-snail-wolf -> 37367), all well within the 16-bit range. It also meant two unrelated uploads could silently collide onto the same ID, since there was no uniqueness check at creation. Widen to u32 (~4.3 billion possible values), which still fits cleanly within the existing 6-character minimum hashid length, and add a collision-avoidance loop that re-rolls the ID if it happens to match an existing pasta, performed immediately after construction and before any ID-dependent work (encryption keyed by id, attachment file paths) happens. Verified: new slugs decode to values across the full u32 range (e.g. sloth-fox-cat-zebra-pigeon-wasp -> 3582195631), vs. the old scheme which could never exceed 65,535.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two security issues found while auditing a MicroBin instance, confirmed against a local build of this project.
1. Stored XSS via uploaded filenames
upload.htmldisables Askama's auto-escaping (escape = "none"). Paste content has a manualcontent_escaped()call, but the filename accessors (name(),display_name(),extension()) did not, and filenames are fully attacker-controlled (only.replace(' ', '_')is applied — nothing HTML-related).Two independently confirmed exploitation paths:
<svg[TAB]onload=alert(1)>.txtrenders as a live<svg>element with a workingonloadhandler.x" onmouseover="alert(1)" foo="closes the existingtitle="..."attribute early and injects a realonmouseoverhandler — browsers recover from the resulting (technically invalid per spec) markup by starting a new attribute, so no whitespace is even required for this variant.Fix: added
name_escaped()/display_name_escaped()/extension_escaped()accessors onPastaFileusinghtml_escape::encode_quoted_attribute(escapes&,<,>,", and'), used at every render site inupload.htmlandfile_card.html, including the one spot embedding a filename inside a single-quoted JS string literal. Both exploitation paths were re-tested after the fix and confirmed neutralized.2. Pasta ID keyspace was only 16 bits
Only 65,536 possible IDs. This undermines the "Unlisted" privacy level, whose entire security model is "can't be found unless you know the unique identifier" — 65,536 is trivially enumerable by brute force. Confirmed empirically by decoding real-world slugs (e.g.
falcon-snail-wolf->37367), all well within the 16-bit range. It also meant two unrelated uploads could silently collide onto the same ID, since there was no uniqueness check at creation.Fix: widened to
u32(~4.3 billion possible values — still fits cleanly within the existing 6-character minimum hashid length), and added a collision-avoidance loop that re-rolls the ID if it happens to match an existing pasta, performed immediately after construction and before any ID-dependent work (encryption keyed by id, attachment file paths) happens.Testing
cargo buildandcargo testpass.u32range (e.g.sloth-fox-cat-zebra-pigeon-wasp->3582195631), vs. the old scheme which could never exceed65535.