postMessage spoofing
Send forged messages to the parent via parent.postMessage. If the parent skips event.origin validation, it can trust attacker-crafted payloads.
Behavior by sandbox policy
| Policy | Expected result |
|---|---|
| No sandbox | works |
sandbox="allow-scripts" | works |
sandbox="" (strictest) | blocked |
Embed snippet
This snippet uses the dedicated embed page. Paste it into your own service and check rendering or blocking behavior.
<iframe src="https://xss-playground.com/embed/post-message?lang=en" title="XSS Playground - postMessage spoofing" width="600" height="420" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe>
실행
target origin
// 로그 없음
해설
- postMessage 는 cross-origin 통신용으로 의도된 API 입니다. SOP 가 막아 주지 않습니다. 부모 쪽에서 origin 검증 을 제대로 해야 합니다.
- 부모 페이지가
iframe-resizer, 결제 위젯, 유튜브 IFrame API 등을 위해 message 리스너를 두고 있다면, 그 리스너의 메시지 포맷을 흉내내서 보내는 게 흔한 공격 패턴입니다. - 차단 방법: 부모 쪽
event.origin정확히 검증 + 메시지 타입 / 스키마 검증. sandbox 에서는sandbox=""(빈 값) 여야 postMessage 까지 막힙니다. - 부모 message 리스너 fingerprinting 은 probe 페이지 에서 더 다양한 페이로드로 시도할 수 있습니다.