Skip to content

fix: validate origin and avoid innerHTML in tettst.html postMessage handler - #129

Open
hacktron-app-stg[bot] wants to merge 1 commit into
maekuss-patch-34from
hacktron/fix-a65c812f
Open

fix: validate origin and avoid innerHTML in tettst.html postMessage handler#129
hacktron-app-stg[bot] wants to merge 1 commit into
maekuss-patch-34from
hacktron/fix-a65c812f

Conversation

@hacktron-app-stg

Copy link
Copy Markdown

Vulnerability

tettst.html added a message event listener that was DOM-XSS vulnerable:

  • Missing origin check: it displayed event.origin but never validated it, so it accepted postMessage from any origin.
  • Dangerous sink: the untrusted event.data payload was assigned directly to document.getElementById('output').innerHTML, executing embedded markup/scripts (e.g. <img src=x onerror=alert(...)>).

An attacker page could open this page and postMessage a malicious HTML payload to run arbitrary JS in the victim page's context.

Fix

  • Added an ALLOWED_ORIGINS allow-list (defaulting to window.location.origin) and an early return when event.origin is not allowed, closing the missing-origin-validation root cause.
  • Replaced the innerHTML sink with textContent, so any received data is rendered as inert text rather than parsed as HTML — this alone defeats the XSS even for same-origin messages.
  • Updated the page's title/description and reproduction section, which previously advertised the insecure behavior, to reflect the secured implementation.

Why it's correct

Both layers of the taint path are addressed: attacker-controlled cross-origin messages are dropped before reaching the sink, and the sink itself no longer interprets HTML. There are no other callers/usages of the changed listener (single self-contained file).

Verification

  • Re-read the final diff; confirmed innerHTML is fully removed and replaced with textContent, and the origin guard uses !ALLOWED_ORIGINS.has(event.origin) (correct polarity).
  • Traced source→sink: event.origin guard blocks untrusted senders; textContent prevents markup execution even if a message passes the guard.
  • Repo has no test infrastructure (a single static HTML file), so no automated regression test was added.

Automated fix by Hacktron for finding: https://staging.hacktron.ai/testestesttest/findings/a65c812f-30a3-4588-86fa-a31804081168

…andler

The message listener accepted postMessage from any origin and wrote the
untrusted event.data payload into innerHTML, enabling DOM-based XSS. Add a
strict origin allow-list that drops untrusted senders and render received
data with textContent instead of innerHTML so payloads cannot execute.
@hacktron-app-stg
hacktron-app-stg Bot requested a review from maekuss August 5, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants