本文へスキップ
Skillpedia
セキュリティ75k · #2753

avoid-eval

できること

このスキルは、evalやテキストをコードとして実行する他の方法の使用を、コードの中で確認します。よくあり深刻なタイプのWeb攻撃を防ぎたい開発者向けです。

使う場面

  • ✓コードにevalやnew Functionがあるとき。
  • ✓タイマーに、実行するテキスト文字列を渡しているとき。
  • ✓利用者からのデータを扱うコードをレビューしているとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/avoid-eval/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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の解析には何を使うべきですか?

evalの代わりに推奨されている、JSON.parseです。

詳細

作者による元の説明

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.

repo: thedaviddias/Front-End-Checklist

人気

GitHubのスター
75k
ランキング
#2753
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル