Attacker page — CSRF via postMessage

ATTACKER ORIGIN

This page runs on https://app.amir.baby… no — it runs on this origin () and talks to the target https://app.amir.baby, which is a different origin because the host names differ (same registrable domain, different host ⇒ cross-origin for postMessage).

The bug is on the receiving side. The sender may (and does) set targetOrigin correctly — that only controls where the message is delivered, it does not authenticate the sender. The victim page must verify event.origin itself. If it does not, any origin can drive a state-changing request that runs with the victim's session cookie.

Pre-flight

  1. Open the target in another tab and sign in as victim / password123: https://app.amir.baby/login
    The session cookie is host-only for https://app.amir.baby, so it is the victim's own browser session that will be abused — not a shared cookie.
  2. Come back to this page and run one of the PoCs below.
  3. Watch the victim's dashboard: the debug box shows the new password and the "last changed by" field proves the request was not made by the victim.

Run the PoC

1 · Popup, targeted origin

Opens https://app.amir.baby/dashboard in a popup and sends {action:"changePassword", newPassword:"hacked123"} with targetOrigin = "https://app.amir.baby" — i.e. the attacker is even correct here. The message still arrives, because the receiver never checks event.origin.

2 · Popup, wildcard origin

Same thing with targetOrigin = "*". The wildcard means "deliver to whatever origin the popup has" — it weakens the sender, it does not help the receiver.

3 · Hidden iframe

Embeds https://app.amir.baby/dashboard in an invisible iframe and sends the message to iframe.contentWindow. No popup, no visible UI, no user interaction — the classic "silent" variant. It works because the target sets no X-Frame-Options / frame-ancestors.

Log

The log lines are written by this page. The final verdict comes from the victim page: it answers with a changePasswordResult message, which is the only channel the attacker has — it cannot read anything cross-origin.

What a correct receiver would do

window.addEventListener('message', function (event) {
  if (event.origin !== 'https://app.amir.baby') return;   // <- the missing line
  if (event.data.action !== 'changePassword') return;
  /* … */
});