Skip to content

fix(silent-refresh): only accept messages from the iframe or popup the lib opened - #1516

Open
Dominik-O22 wants to merge 1 commit into
manfredsteyer:masterfrom
Dominik-O22:fix/postmessage-source-check
Open

Dominik-O22 wants to merge 1 commit into
manfredsteyer:masterfrom
Dominik-O22:fix/postmessage-source-check

Conversation

@Dominik-O22

Copy link
Copy Markdown

The silent refresh and popup login listeners treat any message event as an auth response. Any window that can post to the app gets its message parsed by tryLogin: an embedded iframe, a browser extension, the session check iframe, or the page that opened the app. checkOrigin: true doesn't help, because it logs "wrong origin requested silent refresh!" and then carries on.

This also explains #827. The silent refresh listener stays registered after a refresh and picks up the popup's reply too, so the same code gets exchanged twice and the second call fails with invalid_grant.

Both listeners now drop messages whose e.source isn't the window the library opened:

  • Silent refresh accepts only the iframe with id silentRefreshIFrameName.
  • Popup login accepts only the popup window, whether window.open returned it or it came in through options.windowRef.
  • checkOrigin: true now returns on an origin mismatch.

silent-refresh.html posts through window.parent or window.opener, so e.source is that iframe or popup and existing setups keep working. The localStorage auth_hash fallback is unchanged.

Behaviour change: a custom redirect page that posts from a different window than the iframe or popup itself, for example window.top from a nested frame, will stop working.

Two tests cover the listeners. Both fail without the fix.

Fixes #1354, fixes #1409, fixes #1448

Reviewed with review-loop: 1 round with Claude Opus. Verdict: approved

Created with Claude Opus 5.5 in Claude Code.

…e lib opened

The silent refresh and popup login message listeners handled postMessage
events from any window as auth responses, and checkOrigin only logged a
mismatch. Check e.source against the silent refresh iframe or the login
popup, and make checkOrigin return on mismatch.

Fixes manfredsteyer#1354, fixes manfredsteyer#1409, fixes manfredsteyer#1448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant