~/deadhead.blog web · api · mobile · bug bounty
All posts

The postMessage listener that trusted everyone

No origin check, innerHTML sink, public page. Accepted as Medium. I argued for High and lost.

XSS · 3 min read

An HR self-service portal. Almost every route needs a login, but the home page returns 200 to anyone, and the portal template injects this on every page:

var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";

eventer(messageEvent, (e) => {
    if (e.data && e.data.text)
        document.getElementById('widget-title-label').innerHTML = e.data.text;
});

No e.origin check, and innerHTML where textContent would do. Either one is a bug on its own. Together it's unauthenticated script execution in an authenticated session.

The split is what makes it work: I reach the sink with no account because the page is public, and the victim brings the cookies. Neither side needs what the other has. The script lands in the portal origin, so it reads any same-origin route that session can reach.

Delivery#

const w = window.open('https://portal.example.com/');

setTimeout(() => {
  w.postMessage({ text: '<img src=x onerror="alert(origin)">' }, '*');
}, 3000);

What actually costs time here:

Prove the sink with alert(origin) before building anything on top of it. If that doesn't fire, nothing downstream matters.

Finding more of them#

addEventListener\(['"]message['"]
onmessage\s*=
\.origin

Read each listener and ask two things in order: is e.origin checked, and where does e.data end up.

Sink What you get
innerHTML, outerHTML, insertAdjacentHTML HTML injection, script via an event handler
document.write Same, and it can clobber the page
eval, Function, setTimeout(string) Direct execution
location, location.href Redirect, javascript: if unfiltered
localStorage / sessionStorage Stored payload that fires on a later page

getEventListeners(window) in Chrome lists them without reading a bundle. Weak checks count too: e.origin.indexOf('portal.example.com') > -1 matches portal.example.com.attacker.net. Compare the whole string.

Template-injected bugs are worth enumerating across every site built from that template. This handler sat on prod, a UAT box, and an unrelated travel portal. It also tells the vendor to fix the template rather than the page.

Severity#

I scored it 8.2: AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N. Accepted as 5.4 Medium.

I filed a reconsideration. The XSS could read a live chat widget's session identifier out of the page, and that identifier re-minted a valid chat token with no authentication, so the label overwrite was really a foothold into an employee's support conversation. Reasonable argument.

It didn't move the score, and the reason is in my own text:

My reconsideration, verbatim

"Happy to provide the full request/response pairs, the idempotency proof across multiple days, and the transcript-read PoC on request."

I described the chain and offered the evidence instead of attaching it. Nobody re-scoring a closed report is going to open a correspondence to collect proof I already had on disk. Attach it or don't bother.

Fix#

const ALLOWED = ['https://portal.example.com'];

eventer(messageEvent, (e) => {
    if (!ALLOWED.includes(e.origin)) return;   // exact match, not indexOf/startsWith
    if (e.data && e.data.text)
        document.getElementById('widget-title-label').textContent = e.data.text;
});

Reported under a VDP and accepted. Target isn't named and the identifiers are genericised: "accepted" isn't permission to publish.