JWTは誰でも復号(デコード)して中身を見ることができますか?
はい。一般的なJSON Web Token(JWS)は「署名」されているだけで「暗号化」されていません。ヘッダーとペイロードは単にBase64URLでエンコードされた文字列であり、秘密鍵がなくても誰でも平文として閲覧可能です。
Detailed Technical Explanation
Web開発で一般的に用いられるJWTはRFC 7515(JWS: JSON Web Signature)に基づいています。ドットで区切られたヘッダー、ペイロード、署名で構成され、署名は改ざん検知と送信元検証を行いますが、ペイロードの内容自体は秘匿されません。機密データを格納する場合はJWE(RFC 7516: JSON Web Encryption)を採用する必要があります。
Technical Example & Code
Base64URL文字列をデコードするだけで、トークン内のクレーム情報を誰でも閲覧できます。
const token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTYiLCJyb2xlIjoiYWRtaW4ifQ.signature";
const payloadB64 = token.split('.')[1];
const decodedClaims = JSON.parse(atob(payloadB64.replace(/-/g, '+').replace(/_/g, '/')));
console.log(decodedClaims);
// Output: { sub: "123456", role: "admin" }Why This Is the Case (Underlying Architectural Rationale)
"RFC 7519の設計思想は、検証可能なクレームを軽量に運ぶことです。暗号化と署名を分離することで、各APIサーバーが高負荷な復号処理を行わずにユーザーIDや有効期限を即座に参照できるよう設計されています。"
Common Misconception vs Reality
"JWTの署名があるため、トークン内のクレームは暗号化されて外部から隠蔽されている。"
暗号学的署名は完全性と改ざん検知を提供するのみであり、機密性は一切保証されません。パスワードや機密APIキーを標準のJWTペイロードに入れてはいけません。
Related Curious-Techie Resources
Ultimate Guide to JWT Authentication & Security →
Master token architecture, signature algorithms, refresh token rotation, and storage best practices.
Interactive ToolJWT Decoder & Inspector →
Paste any JWT to instantly view decoded headers, claims, and signature validity in browser memory.
Developer ReferenceJWT Claims Reference & Specifications →
Related Questions in the Q&A Knowledge Base
You should not store authentication JWTs in localStorage because any Cross-Site Scripting (XSS) vulnerability on your page allows malicious JavaScript to instantly read and exfiltrate the token. Storing tokens in HttpOnly, Secure, SameSite cookies protects them from JavaScript access.
Yes, the cryptographic signature of an expired JWT remains mathematically valid because signatures are computed solely over the header and payload data. However, compliant JWT libraries will reject the token during authentication because the expiration claim (`exp`) is explicitly checked after signature verification.
Authentication (AuthN) verifies who a user is (identity confirmation), while Authorization (AuthZ) determines what permissions or resources that authenticated user is allowed to access.
関連技術エコシステムと次の学習ステップ
関連技術解説記事
What Is a JSON Web Token (JWT)?
Direct definition and architectural breakdown of stateless token exchange.
JWT vs Session-Based Authentication: Architecture & Performance
Compare database session lookups with stateless JWT verification across scalability and revocation.
Troubleshooting: JWT Works in Postman but Fails in Browser
Diagnose and remediate CORS header stripping, HttpOnly cookie constraints, and preflight authorization failures.
実践ハンズオン診断ラボ
開発者向け規格・仕様リファレンス
次のステップへ進む
JWT Interactive Tampering & Validation Lab
Put your theoretical understanding into practice by tampering with claims and testing signature rejection in the live sandbox.