implementing-jwt-signing-and-verification
它能做什么
这个工具可以帮助你创建和校验一种名为 JWT 的安全令牌。它们用于确保只有获得授权的人才能访问网站和应用中的信息,从而防范黑客。
适用场景
- ✓为网站或应用设置安全机制时。
- ✓检查访问令牌是否正确时。
- ✓保护敏感数据免受未授权访问时。
技能链接
https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-jwt-signing-and-verification/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“验证这个 JWT 令牌,确认它是安全的且没有被篡改过。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会在创建令牌时使用加密方法对其签名,以确保其真实性。接收到令牌时,它会使用相同的加密方法检查令牌是否有效,以及是否被修改过。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
常见问题
什么是 JWT?
JWT 是 JSON Web Token 的缩写。它就像一张数字工牌,以安全且紧凑的方式向网站或应用证明你的身份。
为什么要使用 HS256、RS256 等不同的算法?
每种算法使用不同类型的密钥来签名和验证令牌。有的使用共享密钥(HS256),有的使用密钥对(一个公钥、一个私钥),在较大的系统中安全性更强(RS256、ES256、EdDSA)。
“算法混淆”或“none 算法”攻击是什么?
这些是黑客试图欺骗系统的手段。例如,让系统误以为令牌是用安全的方法签名的,或者发送一个没有签名的令牌来绕过安全机制。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 35k
- 排名
- #8065
- 许可证
- Apache-2.0
- 更新时间
- 2026/8/31
评论
- …
同一仓库的更多技能
abusing-dpapi-for-credential-access
35k为你的 AI 智能体提供针对特定任务的现成指令,让它完成得更好、更快。
abusing-shadow-credentials-for-privesc
35k教你的 AI 智能体写出清晰、结构良好的文本。
achieving-cmmc-level-2-compliance
35k帮助你的智能体搭建符合 CMMC Level 2 合规要求的环境。它会落实安全要求,并管理必要的文档。
acquiring-disk-image-with-dd-and-dcfldd
35k帮助你的智能体创建硬盘的精确副本。这能确保调查过程中信息不丢失、不被篡改。