跳到正文
Skillpedia
安全75k · #2793

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/cross-origin-security/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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, or callbackUrl

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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2793
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能