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

implementing-jwt-signing-and-verification

Skill này làm gì

Công cụ này giúp tạo và kiểm tra các token bảo mật gọi là JWT. Chúng được dùng để đảm bảo chỉ người được ủy quyền mới truy cập được thông tin trên website và ứng dụng, bảo vệ khỏi hacker.

Khi nào nên dùng

  • ✓Khi thiết lập bảo mật cho website hoặc ứng dụng.
  • ✓Khi kiểm tra xem các token truy cập có đúng không.
  • ✓Khi bảo vệ dữ liệu nhạy cảm khỏi truy cập trái phép.

Liên kết skill

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-jwt-signing-and-verification/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/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-jwt-signing-and-verification/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

“Xác minh token JWT này để đảm bảo nó an toàn và chưa bị sửa đổi.”

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

Cách hoạt động

Công cụ dùng phương pháp mật mã để ký token khi chúng được tạo, đảm bảo tính xác thực. Khi nhận được token, nó dùng cùng phương pháp đó để kiểm tra token có hợp lệ và chưa bị sửa đổi không.

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.

Implementing JWT Signing and Verification

Overview

JSON Web Tokens (JWT) defined in RFC 7519 are compact, URL-safe tokens used for authentication and authorization in web applications. This skill covers implementing secure JWT signing with HMAC-SHA256, RSA-PSS, and EdDSA algorithms, along with verification, token expiration, claims validation, and defense against common JWT attacks (algorithm confusion, none algorithm, key injection).

When to Use

  • When deploying or configuring implementing jwt signing and verification capabilities in your environment
  • When establishing security controls aligned to compliance requirements
  • When building or improving security architecture for this domain
  • When conducting security assessments that require this implementation

Prerequisites

  • Familiarity with cryptography concepts and tools
  • Access to a test or lab environment for safe execution
  • Python 3.8+ with required dependencies installed
  • Appropriate authorization for any testing activities

Objectives

  • Implement JWT signing with HS256, RS256, ES256, and EdDSA
  • Verify JWT signatures and validate standard claims
  • Implement token expiration, not-before, and audience validation
  • Defend against algorithm confusion and none algorithm attacks
  • Implement JWT key rotation with JWK Sets
  • Build a complete authentication middleware

Key Concepts

JWT Algorithms

Algorithm Type Key Security Level
HS256 Symmetric (HMAC) Shared secret 128-bit
RS256 Asymmetric (RSA) RSA key pair 112-bit
ES256 Asymmetric (ECDSA) P-256 key pair 128-bit
EdDSA Asymmetric (Ed25519) Ed25519 pair 128-bit

Common JWT Attacks

  • Algorithm confusion: Switching from RS256 to HS256, using public key as HMAC secret
  • None algorithm: Setting alg=none to bypass signature verification
  • Key injection: Embedding key in JWK header
  • Weak secrets: Brute-forcing short HMAC secrets
  • Token replay: Reusing valid tokens without expiration

Security Considerations

  • Always validate the algorithm header against an allowlist
  • Never accept alg=none in production
  • Use asymmetric algorithms (RS256, ES256) for distributed systems
  • Set short expiration times (15 min for access tokens)
  • Implement token refresh mechanism
  • Store secrets securely (not in source code)

Validation Criteria

  • JWT signing produces valid tokens for all algorithms
  • Signature verification rejects tampered tokens
  • Expired tokens are rejected
  • Algorithm confusion attack is prevented
  • None algorithm is rejected
  • JWK key rotation works correctly
  • Claims validation enforces all required claims
Câu hỏi thường gặp

JWT là gì?

JWT là viết tắt của JSON Web Token. Nó giống như huy hiệu kỹ thuật số chứng minh bạn là ai với một website hoặc ứng dụng, theo cách an toàn và gọn nhẹ.

Vì sao dùng các thuật toán khác nhau như HS256, RS256?

Mỗi thuật toán dùng một loại “khóa” bí mật khác nhau để ký và xác minh token. Một số dùng khóa bí mật chung (HS256), còn số khác dùng cặp khóa (công khai và riêng tư) để bảo mật cao hơn trong hệ thống lớn (RS256, ES256, EdDSA).

Các tấn công như “algorithm confusion” hoặc “none algorithm” là gì?

Đây là các nỗ lực của hacker để đánh lừa hệ thống. Ví dụ, làm cho hệ thống tưởng token được ký bằng phương pháp an toàn trong khi thực tế không, hoặc gửi token không có chữ ký để vượt qua bảo mật.

Chi tiết

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

Implements secure JWT (RFC 7519) signing and verification using HMAC-SHA256, RSA-PSS, ES256, and EdDSA, including token expiration, claims validation, and defenses against algorithm-confusion, none-algorithm, and key-injection attacks. Use when adding or hardening JWT-based authentication/authorization, or when auditing token verification code for common JWT vulnerabilities.

repo: mukul975/Anthropic-Cybersecurity-Skills

Độ phổ biến

Sao GitHub
35k
Vị trí xếp hạng
#8065
Giấy phép
Apache-2.0
Cập nhật
31/8/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ự