top.location 强制跳转
从 iframe 内替换整个父窗口,并比较 sandbox allow-top-navigation 的行为差异。
按 sandbox 策略的行为
| 策略 | 预期结果 |
|---|---|
| 无 sandbox | 通过 |
sandbox="allow-scripts" | 阻止 |
sandbox="" (最严) | 阻止 |
Embed 代码
此代码使用专用嵌入页面。粘贴到您的服务后检查渲染或拦截行为。
<iframe src="https://xss-playground.com/embed/top-redirect?lang=zh" title="XSS Playground - top.location 强制跳转" width="600" height="420" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe>
执行
// 无日志
说明
- same-origin frame 可以通过
window.top.location修改顶层页面;现代浏览器通常只在用户交互后允许 cross-origin frame 这样做。SOP 会阻止读取,但不能完全替代此 navigation surface 的控制。 - 不授予 sandbox 的
allow-top-navigation即可阻止。仅使用sandbox="allow-scripts"也足以阻止。 - 攻击价值很高:用户在可信服务中点击后,整个标签页可能被替换成钓鱼站点。