الانتقال إلى المحتوى
الأمان (Security)OAuth و OIDC و JWT· 8 دقائق للقراءة

A JWT Is Signed, Not Encrypted: Anyone Can Read Your Token

The signature proves who issued the token and that nobody changed it. It hides nothing: the claims are Base64url-encoded JSON that anyone can decode.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A tester files a bug: the access token the app keeps in local storage contains her test customer's email, phone number, date of birth and credit limit. A developer closes it as "not a bug", because the token is encrypted. She pastes it into a decoder and reads all of it back. No key, no password: the token was never encrypted, only signed.

The common misconception

The belief: a JWT is encrypted, so it's safe to put sensitive data in its payload. Only the server, which holds the key, can read it.

It's easy to believe because nothing about a token looks readable. It's a long run of random-looking characters, it's produced by a security library with a "signing key", and the server rejects it if anything is off. The spec adds to the confusion: RFC 7519 says JWT claims can be "digitally signed or integrity protected with a Message Authentication Code (MAC) and/or encrypted." So JWTs can be encrypted. But in what OWASP calls "its most common form", a JWT is only signed, and signing and encrypting are different jobs.

What actually happens

A signed JWT is three Base64url parts

OWASP's JSON Web Token Cheat Sheet shows the structure of a signed in one line: {base64url(json(header))}.{base64url(json(claims))}.{base64url(signature)}. That's the JWS compact serialization from RFC 7515. The header and the claims are plain JSON, run through url so they're safe in URLs and headers. The eyJ that starts almost every token is just how Base64 begins {", the opening of a JSON object.

The signature protects integrity, not secrecy

RFC 7515 describes a JWS as "content secured with digital signatures or Message Authentication Codes (MACs)." A signature lets the server check two things: the token came from someone holding the key, and not one byte has changed. OWASP draws the line clearly: a signed JWT "provides integrity and authenticity, but not confidentiality. The payload is only base64url encoded, not encrypted, so anyone who obtains the token can read every claim."

HTTPS doesn't keep the claims private either

TLS protects the token on the wire, and that's all. OWASP lists where the claims stay exposed: "in application logs, in browser storage, in referrer headers, and to any intermediary that terminates TLS." Add every script running on your page, and anyone the token is accidentally shared with. A JWT access token is also a : whoever holds it can use it until it expires.

Encryption is a different format: JWE

When claims really must be secret, the spec has . RFC 7516 says it "represents encrypted content", and its compact form has five parts, not three: a protected header, an encrypted key, an initialization vector, the ciphertext and an authentication tag. JWE alone doesn't prove who issued the token, so OWASP recommends signing first and encrypting the result. Its first advice, though, is simpler: "Prefer keeping sensitive data server-side behind an opaque reference token."

What the token carried

C# TokenIssuer.cs
using System.Security.Claims;using Microsoft.IdentityModel.JsonWebTokens;using Microsoft.IdentityModel.Tokens;public sealed class TokenIssuer(SigningCredentials signing){    public string Issue(Customer c) => new JsonWebTokenHandler().CreateToken(        new SecurityTokenDescriptor        {            Subject = new ClaimsIdentity(            [                new Claim("sub", c.Id.ToString()),                new Claim("email", c.Email),                new Claim("phone", c.Phone),                new Claim("date_of_birth", c.DateOfBirth.ToString("O")),                new Claim("credit_limit", c.CreditLimit.ToString()),            ]),            Expires = DateTime.UtcNow.AddMinutes(15),            SigningCredentials = signing, // signed, not encrypted        });}

We issued a token like the wrong version with a throwaway HS256 key, then decoded it the way any script in the browser could, with no key at all:

TypeScript readClaims.ts
export function readClaims(token: string): unknown {  const payload = token.split(".")[1] ?? "";  const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");  return JSON.parse(atob(base64));}

The real output for our test token:

JSON
{  "exp": 1793740500,  "iat": 1793739600,  "nbf": 1793739600,  "sub": "7d4c1a2e-5b8f-4e2a-9c61-3f0b8d2a6e45",  "email": "mona@example.com",  "phone": "+201000000000",  "date_of_birth": "1995-04-12",  "credit_limit": "50000"}

What the signature does give you is just as real: when we changed credit_limit to 900000 and kept the original signature, ValidateTokenAsync returned IsValid = false. Readable by anyone, changeable by no one. The fixed version carries only a stable user ID, the issuer, the audience and an expiry, so there's nothing worth reading.

Signed JWT (JWS)Encrypted JWT (JWE)
Who can read the claimsAnyone holding the tokenOnly the holder of the decryption key
Detects changesYesYes
Proves who issued itYesNot on its own; sign, then encrypt
Parts in compact form35
Typical useAccess and ID tokens with few claimsClaims a third party must read privately

How to apply it in your project

  1. Decode the tokens you issue todayTake an access token and an ID token from a test account, decode them, and list every claim. Assume anyone who sees the token can read the same list.
  2. Cut the payload to what authorization needsKeep a stable, non-personal user ID in sub, plus iss, aud, exp and any scopes or roles the API checks. Remove personal data and internal business values.
  3. Look up the rest on the serverFetch profile and account data by sub when a request needs it, or use opaque reference tokens, as OWASP prefers, for sessions that carry sensitive context.
  4. Use JWE only for claims that must travelIf another party must read private claims and can't ask your server, sign the token and then encrypt it as a JWE. Validate both layers on the receiving side.
  5. Harden validation while you're therePin the accepted algorithms, use a long random key for HS256 or an asymmetric key pair, and check issuer, audience and expiry on every request.

Key takeaways

  • A signed JWT is Base64url-encoded JSON plus a signature; anyone can read its claims.
  • The signature proves who issued the token and that it wasn't changed; it hides nothing.
  • HTTPS protects the token in transit only; logs, browser storage and scripts can still read it.
  • Keep personal and business data out of the payload; look it up on the server by sub.
  • Use JWE, signed then encrypted, only when private claims must travel to another party.

📚 المصادر

  1. RFC 7519: JSON Web Token (JWT)
  2. RFC 7515: JSON Web Signature (JWS)
  3. RFC 7516: JSON Web Encryption (JWE)
  4. RFC 8725: JSON Web Token Best Current Practices
  5. JSON Web Token Cheat Sheet — OWASP Cheat Sheet Series

التعليقات (0)