postMessage spoofing
Send forged messages to the parent via parent.postMessage. If the parent skips event.origin validation, it can trust attacker-crafted payloads.
按 sandbox 策略的行为
| 策略 | 预期结果 |
|---|---|
| 无 sandbox | 通过 |
sandbox="allow-scripts" | 通过 |
sandbox="" (最严) | 阻止 |
Embed 代码
此代码使用专用嵌入页面。粘贴到您的服务后检查渲染或拦截行为。
<iframe src="https://xss-playground.com/embed/post-message?lang=zh" 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 페이지 에서 더 다양한 페이로드로 시도할 수 있습니다.