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

subresource-integrity

Skill này làm gì

Skill này kiểm tra các script và style bên ngoài trên trang web rồi thêm mã băm integrity cho chúng. Skill dành cho lập trình viên tải mã từ bên ngoài máy chủ của mình.

Khi nào nên dùng

  • ✓Khi một trang tải JavaScript hoặc CSS từ CDN mà không có thuộc tính integrity.
  • ✓Khi rà soát các template HTML có thẻ script hoặc link bên ngoài.
  • ✓Khi có người hỏi cách bảo vệ người truy cập nếu CDN bị xâm nhập.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/subresource-integrity/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/subresource-integrity/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

“Site của tôi tải script từ CDN. Làm sao để chắc rằng không ai có thể thay chúng bằng mã độc?”

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

Cách hoạt động

Agent tìm các file bên ngoài chưa có dấu vân tay và thêm cho chúng. Sau đó trình duyệt so sánh từng file tải về với dấu vân tay và chặn mọi file không khớp.

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.

Add Subresource Integrity to external scripts

When you load JavaScript from a CDN, you're trusting that CDN completely — if it's compromised, attackers can serve malicious JavaScript to all your users. SRI adds a cryptographic hash to the tag; the browser refuses to execute the script if the hash doesn't match the downloaded content, protecting users even if the CDN is compromised or the URL is hijacked.

Quick Reference

  • Add integrity="sha384-..." to <script> and <link> tags loading from CDNs
  • Always pair integrity with crossorigin="anonymous"
  • Generate hashes with openssl or online tools — CDN providers usually supply them
  • SRI blocks execution if the file hash doesn't match, preventing CDN compromise attacks

Check

Find all external <script> and <link rel=stylesheet> tags in this HTML that load from CDNs and don't have integrity attributes. List each one.

Fix

Add appropriate integrity and crossorigin attributes to external CDN resources. Generate the SHA-384 hashes for each resource.

Explain

Explain Subresource Integrity, how it protects against CDN compromise, how to generate SRI hashes, and its limitations.

Code Review

Review templates, server-rendered HTML, and shared components that output markup related to Add Subresource Integrity to external scripts. Flag exact elements, attributes, and routes where the rendered HTML violates the rule.


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

Rule page: https://frontendchecklist.io/rules/html/subresource-integrity

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

Mã băm subresource integrity là gì?

Đó là một đoạn mã ngắn mô tả chính xác nội dung của một file. Trình duyệt so sánh nó với file tải về trước khi chạy.

Tôi có cần điều này cho file do máy chủ của mình lưu trữ không?

Skill tập trung vào các file CDN bên ngoài. File do chính site lưu trữ không phải là mục tiêu chính ở đây.

Skill có nói về giới hạn của phương pháp này không?

Có. Skill cũng giải thích các giới hạn, để bạn biết kiểm tra này bảo vệ được gì và không bảo vệ được gì.

Chi tiết

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

Use when reviewing templates, rendered HTML, or shared components related to Add Subresource Integrity to external scripts. Validate the final browser-facing markup, not just the source framework abstraction.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3041
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ự