Dev.to Security 🔐 Cybersecurity 👁 0 📖 4 min read

Decoding JWTs in the Browser: Read Your Token Without Sending It Anywhere

Subtitle: Every online JWT decoder asks you to paste in a live access token. Mine decodes it in your browser with 15 lines of JavaScript — here is the code, and the one thing decoding can never tell you. You know the

Subtitle: Every online JWT decoder asks you to paste in a live access token. Mine decodes it in your browser with 15 lines of JavaScript — here is the code, and the one thing decoding can never tell you.

You know the moment: your API returns a 401, you suspect the token expired, and you need to see what is inside it. So you open an online JWT decoder, paste in a live access token — a token that authenticates as you — and read the result. It works in seconds. But stop and think about what just happened: you handed a working credential to a server you do not control.

I built the JWT Decoder on Toolenix so that never happens. It decodes the header and payload of a token entirely in your browser. Nothing is uploaded, nothing is stored. Here is how it works.

The core idea: a JWT is just two chunks of Base64

A JSON Web Token looks like three blocks of gibberish separated by dots — header.payload.signature. The first two blocks are not encrypted. They are Base64URL-encoded JSON, which means decoding them is just a character swap and a built-in browser function away:

function base64UrlDecode(str) {
  const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
  const padded = base64.padEnd(
    base64.length + ((4 - (base64.length % 4)) % 4),
    "="
  );
  return atob(padded);
}

function decodeJWT(token) {
  const [header, payload] = token.split(".");
  return {
    header: JSON.parse(base64UrlDecode(header)),
    payload: JSON.parse(base64UrlDecode(payload)),
  };
}

Base64URL is Base64 with two characters swapped (- instead of +, _ instead of /) and the = padding stripped, so it survives safely inside a URL. The function above reverses those two swaps, restores the padding, and lets atob() — built into every browser — do the decoding. split(".") takes the first two parts; the signature is deliberately ignored, because decoding never needs it. Try it in your console with the standard example token:

const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";

decodeJWT(token);
// { header: { alg: "HS256", typ: "JWT" },
//   payload: { sub: "1234567890", name: "John Doe", iat: 1516239022 } }

That iat value, 1516239022, is a Unix timestamp — 18 January 2018. Every time-based claim in a JWT is a number like this: seconds since 1 January 1970.

The check that actually solves the 401: has it expired?

Nine times out of ten, you are decoding a token for one reason — to find out whether it is dead. The exp claim answers that in one comparison:

function isExpired(payload) {
  return payload.exp !== undefined && payload.exp * 1000 < Date.now();
}

Multiply by 1,000 because JavaScript dates work in milliseconds while JWT timestamps are in seconds — the single easiest bug to write in this whole area, and the one that makes a live token look expired or a dead one look fine. If exp is in the past, the token is dead, whatever else it says. That one line is the difference between guessing at a 401 and knowing.

The details that make it feel like a real tool

Decoding itself is a few lines. The behaviour around it is what makes people come back:

  • Expiry in plain language — the raw timestamp is shown next to a readable date and a live-or-expired verdict, because nobody wants to convert epoch seconds in their head.
  • Every claim, readable — the full header and payload as formatted JSON, so iss, aud, and sub are all visible at a glance.
  • Copy in one click — navigator.clipboard.writeText() on the decoded JSON, because nobody wants to select a nested object by hand.
  • Instant feedback — decoding runs as you paste, so the claims appear before you finish reaching for the mouse.
  • Private by construction — there is no server endpoint to call. The page is static; the work happens in your browser.

The honest limits

Decoding is not verifying, and that distinction is the whole security model of JWTs. Decoding reads the claims; it does not check the signature and it does not prove the token is genuine. Anyone can create a token with any claims they like and sign it with a key nobody trusts — the decoded payload will look perfectly plausible. Never trust decoded claims until your server has verified the signature against the issuer's key. And never put a secret in a payload: the payload is readable by design, so anything inside it is public to whoever holds the token.

Two more limits worth knowing. If the header says "alg": "none", the token is unsigned and must never be trusted. And not every token has a readable payload at all: a JWE token (JSON Web Encryption) has five parts instead of three, and its payload is encrypted — it cannot be decoded without the decryption key. If you paste a five-part token and get nothing readable, that is expected. The token is doing its job.

One small technical note: plain atob() handles ASCII payloads fine, but a name with non-ASCII characters needs a UTF-8-safe decode — the decodeURIComponent wrapper the live tool uses — or the characters come back garbled.

Why client-side wins for tools like this

  • Privacy: an access token is a live credential. Decoding it in your browser means it never travels anywhere it could be logged, replayed, or stolen.
  • Speed: no upload, no queue, no round-trip. atob on a token takes microseconds.
  • Cost: static hosting. No server to scale, no bandwidth bill for other people's tokens.
  • Reliability: nothing to go down. If the page loads, the tool works — even offline after the first load.

Try it

The decoder is live at toolenix.com/tools/jwt-decoder — free, no sign-up, and your tokens never leave your browser. The whole site is built on the same idea: 113 tools, all client-side.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.