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

new-tab

它能做什么

这项技能检查在新标签页中打开的链接,确保它们带有能阻止常见标签页劫持攻击的安全属性。适用于检查 HTML 或 JSX 代码的开发者。

适用场景

  • ✓当你请智能体为安全性检查在新标签页中打开的链接的时候。
  • ✓当你在检查会在新标签页中打开外部链接的代码的时候。
  • ✓当你添加 lint 规则,使每个在新标签页中打开的链接都能被自动检查的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/new-tab/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 AI

“请帮我检查网站上每个在新标签页中打开的链接,是否都有正确的安全属性。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会找到在新标签页中打开的 a 元素,并检查每个元素是否带有 rel noopener noreferrer,至少要有 noopener。它会补上缺少的属性,并可以建议添加 lint 规则,防止以后出现遗漏。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

External Link Security

A malicious site opened via target='_blank' can use window.opener.location to silently redirect your original tab to a phishing page — the user switches back and sees a fake login screen on what appears to be your domain.

Quick Reference

  • Always add rel="noopener noreferrer" to any <a target="_blank"> link
  • noopener prevents the new tab from accessing window.opener and redirecting your page
  • noreferrer additionally suppresses the Referer header sent to the destination site
  • Modern browsers (Chrome 88+, Firefox 79+) implicitly add noopener for cross-origin _blank links, but explicit markup is required for older browsers and same-origin links
  • ESLint rule jsx-a11y/anchor-is-valid and eslint-plugin-security can enforce this automatically

Check

Find all anchor elements with target='_blank' in the HTML and JSX source. Verify each one includes rel='noopener noreferrer' (or at minimum rel='noopener'). Flag any external links opening in a new tab that are missing this attribute.

Fix

Add rel='noopener noreferrer' to all <a target='_blank'> elements. In React/JSX this is rel="noopener noreferrer". Configure an ESLint rule to prevent this from recurring.

Explain

Explain the reverse tabnapping attack enabled by window.opener, how rel='noopener' and rel='noreferrer' prevent it, and the difference between the two values.

Code Review

Review server config, headers, forms, and integration points related to External Link Security. Flag exact responses, cookies, or browser behaviors that violate the rule, and verify them against the effective production-like response.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/security/new-tab

常见问题

什么是反向标签页劫持?

这是一种攻击方式:新标签页利用 window.opener 悄悄把你原来的标签页导向一个假页面。

noreferrer 有什么作用?

它会阻止浏览器把 Referer 标头发送给目标网站。

现代浏览器不是已经能保护我吗?

有些浏览器对跨域链接已有保护,但这项技能指出,对于旧浏览器和同源链接,仍需要明确的标记。

详情

作者的原始描述

Use when reviewing HTML or JSX for anchor elements with target='_blank' to verify rel='noopener noreferrer' is present.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能