avoid-eval
它能做什么
这项技能检查代码中 eval 以及其他将文字当作代码执行的方式。适合希望防范一类常见且严重的网站攻击的开发者。
适用场景
- ✓当你在代码中发现 eval 或 new Function 时。
- ✓当定时器被传入一段文字字符串来执行时。
- ✓当你审查处理用户数据的代码时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/avoid-eval/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我的项目中搜索 eval 调用,并把它们替换为更安全的代码。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在代码中搜索 eval、new Function 以及以文字字符串作为参数的定时器,然后把它们替换为 JSON 解析、对象查找或函数引用。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Never use eval() or unsafe dynamic code execution
eval() and its equivalents are the root cause of some of the most severe XSS vulnerabilities. If any user-controlled string reaches eval(), an attacker can execute arbitrary JavaScript in your users' browsers — stealing sessions, making requests as the user, or redirecting to malicious sites. Content Security Policy (CSP) blocks eval() but not new Function(), and there is never a legitimate use case that can't be solved without it.
Quick Reference
- eval() executes arbitrary strings as code — any user input passed to it is a critical security hole
- new Function() is equally dangerous and not caught by CSP eval restrictions
- setTimeout('code', delay) and setInterval('code', delay) also evaluate strings — use function references instead
- Use JSON.parse() instead of eval() for parsing JSON
Check
Search this codebase for any use of eval(), new Function(), or setTimeout/setInterval with string arguments.
Fix
Replace eval() calls with safe alternatives: JSON.parse for data, object lookups for dynamic dispatch, and Function references for timers.
Explain
Explain why eval() is dangerous, how it enables XSS attacks, and what safe alternatives exist for each use case.
Code Review
Review scripts, client components, and browser execution paths related to Never use eval() or unsafe dynamic code execution. 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.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/avoid-eval
常见问题
eval 为什么危险?
这项技能说明,如果用户输入被传给 eval,攻击者就能在其他访客的浏览器中运行 JavaScript。
内容安全策略能阻止这种情况吗?
这项技能说明,CSP 会阻止 eval,但不会阻止 new Function,因此两者都需要从代码中移除。
解析 JSON 应该用什么?
应使用 JSON.parse,这项技能建议用它代替 eval。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Never use eval() or unsafe dynamic code execution. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2753
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。