Decode a JWT locally: why you shouldn't paste tokens into websites

•4 min read
Image for Decode a JWT locally: why you shouldn't paste tokens into websites

A bearer access token can be enough to act as its holder. Pasting one into a debugging website gives that page’s code access to the credential, even if the page looks like a harmless JSON formatter.

I use synthetic tokens for demonstrations. For production diagnostics, I prefer a trusted local tool and the smallest amount of token data needed to answer the question.

The browser-based JWT decoder on this site decodes tokens locally. That reduces the need to send a token to a decoding endpoint. It does not remove the need to trust the page and the code running in it.

TL;DR

  • Treat bearer access tokens as credentials.
  • Decoding a signed JWT reveals data; it does not establish trust.
  • Verify signatures and enforce issuer, audience and lifetime in the API.
  • Use an offline local script for sensitive diagnostics when policy allows them.

A signed JWT is usually readable

A common signed JWT uses the compact JWS form:

base64url(header).base64url(payload).base64url(signature)

The header and payload are encoded, not encrypted. Anyone holding that token can usually read its claims. Encryption uses a different representation, such as a compact JWE with five segments.

Claims can reveal user identifiers, tenants and application roles. An ID token is not interchangeable with an API access token, and not every access token is a JWT. Start by identifying what your identity provider actually issued.

For a signed JWT, the signature protects the encoded header and payload against undetected changes when a verifier uses the correct trusted key. It does not hide their contents.

Local processing has a trust boundary

The decoder on this site performs decoding and supported signature operations in the browser. Its saved preference covers time display; it does not intentionally persist the token or verification key in local storage.

That is a bounded implementation statement, not a claim that a hosted page is equivalent to an isolated offline application. The site loads third-party code. Browser extensions, compromised dependencies and clipboard tools can also access data in ways a “local processing” label does not prevent.

Use a synthetic token in any hosted decoder unless your policy explicitly permits more. Never provide a production symmetric signing secret to a web page. With an HMAC algorithm, that secret can grant the ability to create tokens.

The “clear” button removes the current input. It cannot revoke a token or erase copies held by a clipboard manager, extension or screenshot.

Decode offline with Node.js

Save this as decode-jwt.mjs on a trusted machine with a supported Node.js version. It reads standard input, not a token passed on the command line.

import { readFileSync } from "node:fs";

const token = readFileSync(0, "utf8").trim();
const parts = token.split(".");

if (
  parts.length !== 3 ||
  !parts.every((part) => /^[A-Za-z0-9_-]+$/.test(part))
) {
  throw new Error("Expected a compact signed JWT with three base64url segments.");
}

for (const [index, label] of ["header", "payload"].entries()) {
  const json = Buffer.from(parts[index], "base64url").toString("utf8");
  console.log(`${label}:`);
  console.log(JSON.stringify(JSON.parse(json), null, 2));
}

console.error("Decoded only. Signature and claims have NOT been validated.");

With a synthetic token stored in a local test fixture, run this in PowerShell:

Get-Content -Raw .\synthetic-token.txt | node .\decode-jwt.mjs

The script uses no network requests or external packages. Malformed input raises an error instead of producing an empty object that looks successful.

Standard input avoids putting the credential into a process argument. It does not protect output from terminal logging. Follow your diagnostic policy, do not create production-token fixtures and remove sensitive temporary material when finished.

Decoding explains a failure; validation decides access

An API should validate the signature using trusted key material and an explicitly allowed algorithm. It must also enforce the expected issuer and audience and apply its lifetime rules, including expiry and not-before handling.

Reading exp does not enforce expiry. A displayed role claim is not authorization. A successful signature check is also insufficient if the token belongs to another API.

Treat alg, kid and URL-like header values as untrusted input. Do not let an arbitrary token select a key source or an algorithm policy your application would otherwise reject.

In ASP.NET Core, use the authentication middleware and a maintained token-validation library with the identity provider’s documented configuration. Do not promote the decoding script into authentication code.

If a live token was exposed, stop treating it as private

Follow your incident process and the identity provider’s revocation options. Ending a session or revoking a refresh token may not immediately invalidate an already issued access token; behavior depends on the system.

Review the exposure and rotate signing credentials only if those credentials were exposed, according to your operational procedures. Clearing a text box is not remediation.

Debugging should explain why authentication failed without creating a second authentication problem. Start with a synthetic token and move to sensitive material only when the evidence and policy require it.

Thank you for reading.

-Bruno

Author's note: I wrote the recipe and cooked the food, AI just helped with the plating.

Read more