🛡️ 点击劫持防护测试工具

📌 说明: 此页面用于测试网站的点击劫持防护配置是否生效。 如果配置正确,下方的 iframe 将无法加载受保护的页面。

测试1:尝试嵌入本站页面

如果看到错误消息或空白 iframe,说明防护 ✓ 生效

如果能正常显示页面内容,说明防护 ✗ 未生效

测试2:检查响应头

打开浏览器开发者工具(F12)→ Network(网络)标签 → 刷新页面 → 查看主文档的响应头

应该包含以下响应头:

X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

测试3:使用命令行测试

在终端中运行以下命令来检查响应头:

curl -I http://localhost:5173

或者测试生产环境:

curl -I https://your-domain.com

测试4:预期结果

浏览器控制台应显示类似错误:

Refused to display 'http://localhost:5173/' in a frame
because it set 'X-Frame-Options' to 'sameorigin'.

或者:

Refused to frame 'http://localhost:5173/' because an ancestor
violates the following Content Security Policy directive:
"frame-ancestors 'self'".

✅ 配置检查清单