返回顶部
🇺🇸 English
🇨🇳 简体中文
🇨🇳 繁體中文
🇺🇸 English
🇯🇵 日本語
🇰🇷 한국어
🇫🇷 Français
🇩🇪 Deutsch
🇪🇸 Español
🇷🇺 Русский
J

JWT

Implement secure JWT authentication with proper validation, token lifecycle, and key management.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
1,155
下载量
2
收藏
概述
安装方式
版本历史

JWT

## Quick Reference | Topic | File | |-------|------| | Algorithm selection | `algorithms.md` | | Token lifecycle | `lifecycle.md` | | Validation checklist | `validation.md` | | Common attacks | `attacks.md` | ## Security Fundamentals - JWTs are signed, not encrypted—anyone can decode and read the payload; never store secrets in it - Always verify signature before trusting claims—decode without verify is useless for auth - The `alg: none` attack: reject tokens with algorithm "none"—some libraries accepted unsigned tokens - Use strong secrets: HS256 needs 256+ bit key; short secrets are brute-forceable ## Algorithm Choice - HS256 (HMAC): symmetric, same key signs and verifies—good for single service - RS256 (RSA): asymmetric, private key signs, public verifies—good for distributed systems - ES256 (ECDSA): smaller signatures than RSA, same security—preferred for size-sensitive cases - Never let the token dictate algorithm—verify against expected algorithm server-side ## Required Claims - `exp` (expiration): always set and verify—tokens without expiry live forever - `iat` (issued at): when token was created—useful for invalidation policies - `nbf` (not before): token not valid until this time—for scheduled access - Clock skew: allow 30-60 seconds leeway when verifying time claims ## Audience & Issuer - `iss` (issuer): who created the token—verify to prevent cross-service token theft - `aud` (audience): intended recipient—API should reject tokens for other audiences - `sub` (subject): who the token represents—typically user ID - Token confusion attack: without aud/iss validation, token for Service A works on Service B ## Token Lifecycle - Access tokens: short-lived (5-15 min)—limits damage if stolen - Refresh tokens: longer-lived, stored securely—used only to get new access tokens - Refresh token rotation: issue new refresh token on each use, invalidate old one - Revocation is hard—JWTs are stateless; use short expiry + refresh, or maintain blacklist ## Storage - httpOnly cookie: immune to XSS, but needs CSRF protection - localStorage: vulnerable to XSS, but simpler for SPAs - Memory only: most secure, but lost on page refresh - Never store in URL parameters—visible in logs, history, referrer headers ## Validation Checklist - Verify signature with correct algorithm (don't trust header's alg) - Check `exp` is in future (with clock skew tolerance) - Check `iat` is not unreasonably old (optional policy) - Verify `iss` matches expected issuer - Verify `aud` includes your service - Check `nbf` if present ## Common Mistakes - Storing sensitive data in payload—it's just base64, not encrypted - Huge payloads—JWTs go in headers; many servers limit header size to 8KB - No expiration—indefinite tokens are security nightmares - Same secret across environments—dev tokens work in production - Logging tokens—they're credentials; treat as passwords ## Key Rotation - Use `kid` (key ID) claim to identify which key signed the token - JWKS (JSON Web Key Set) endpoint for public key distribution - Overlap period: accept old key while transitioning to new - After rotation, old tokens still valid until they expire—plan accordingly ## Implementation - Use established libraries—don't implement JWT parsing yourself - Libraries: `jsonwebtoken` (Node), `PyJWT` (Python), `java-jwt` (Java), `golang-jwt` (Go) - Middleware should reject invalid tokens early—before any business logic

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 jwt-1776327734 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 jwt-1776327734 技能

通过命令行安装

skillhub install jwt-1776327734

下载 Zip 包

⬇ 下载 JWT v1.0.1

文件大小: 6.28 KB | 发布时间: 2026-4-17 13:46

v1.0.1 最新 2026-4-17 13:46
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部