cross-origin-security
它能做什么
这项技能检查网站如何处理跨源的请求和消息。适合希望阻止攻击者读取数据或代表用户执行操作的开发者。
适用场景
- ✓当网站监听来自其他窗口或 iframe 的消息时。
- ✓当已登录的路由上 CORS 设置允许任何来源时。
- ✓当重定向参数可以把用户发送到任意外部地址时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/cross-origin-security/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我网站的消息监听器和 CORS 设置,看看是否有任何可能让其他网站读取用户数据的地方。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查消息监听器是否在使用任何数据之前核实每条消息的来源,检查已认证路由上的 CORS 是否受到限制,以及重定向是否只能前往经过批准的目的地。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Handle cross-origin requests securely
The Same-Origin Policy is the browser's primary defense against malicious sites stealing data or performing actions on behalf of your users. Misconfiguring CORS or failing to validate postMessage origins can allow attackers to bypass this protection — reading private data, submitting forms as users, or injecting content into your pages.
Quick Reference
- Always verify event.origin before processing postMessage data
- Never set Access-Control-Allow-Origin: * for authenticated endpoints
- Validate and sanitize all data received from cross-origin messages
- Use SameSite cookies to prevent CSRF from cross-origin requests
- Reject unvalidated redirect targets such as
next,redirect, orcallbackUrl
Check
Check this code for insecure cross-origin patterns: missing origin validation in postMessage listeners, overly permissive CORS settings, and missing CSRF protections. Flag redirect parameters that accept arbitrary external URLs.
Fix
Add origin validation to postMessage listeners and review CORS configuration to ensure it's not overly permissive for authenticated routes. Reject or allow-list untrusted redirect destinations before navigating.
Explain
Explain the Same-Origin Policy, how CORS works, and how to securely use postMessage for cross-origin communication.
Code Review
Review scripts, client components, and browser execution paths related to Handle cross-origin requests securely. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser. Check login, logout, SSO, and return-to flows for open redirects.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/cross-origin-security
常见问题
什么是同源策略?
这项技能把它描述为浏览器抵御恶意网站读取或操纵用户数据的主要防线。
智能体会在消息中检查什么?
在使用任何数据之前,先验证消息的来源。
为什么重定向参数有风险?
这项技能说明,除非经过检查或批准,否则它们可能把用户带到任意外部网站。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Handle cross-origin requests securely. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2793
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。