Chuyển đến nội dung
Skillpedia
Bảo mật75k · #2753

avoid-eval

Skill này làm gì

Skill này kiểm tra code xem có dùng eval hay các cách khác để chạy văn bản như code không. Skill dành cho lập trình viên muốn ngăn một kiểu tấn công website phổ biến và nghiêm trọng.

Khi nào nên dùng

  • ✓Khi bạn thấy eval hoặc new Function trong code.
  • ✓Khi một bộ hẹn giờ nhận vào một chuỗi văn bản để chạy.
  • ✓Khi bạn rà soát code xử lý dữ liệu từ người dùng.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/avoid-eval/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy tìm các lời gọi eval trong dự án của tôi và thay bằng code an toàn hơn.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm eval, new Function và các bộ hẹn giờ nhận chuỗi văn bản, rồi thay bằng phân tích JSON, tra cứu đối tượng hoặc tham chiếu hàm.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Vì sao eval nguy hiểm?

Skill nói nếu dữ liệu người dùng đi vào eval, kẻ tấn công có thể chạy JavaScript trên trình duyệt của người xem khác.

Chính sách bảo mật nội dung có ngăn được không?

Skill nói CSP chặn được eval nhưng không chặn new Function, nên cả hai đều cần gỡ khỏi code.

Tôi nên dùng gì để phân tích JSON?

JSON.parse, cách mà skill khuyên dùng thay cho eval.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2753
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự