JWT Token Safety: Inspect and Verify Without Uploading
In this article
To inspect and verify a JWT without uploading it, decode and validate it locally on your own machine using a command-line tool or a script. You never need to send the token to a third-party website, and doing so risks exposing a live credential.
What a JWT Actually Contains
A JSON Web Token (JWT) is a compact, URL-safe string with three parts separated by dots: header, payload, and signature. The header declares the signing algorithm (like HS256 or RS256) and token type. The payload carries claims—statements about the user and token metadata, such as sub (subject), exp (expiration time), iat (issued at), and iss (issuer). The signature is computed over the header and payload using a secret key (for HMAC algorithms) or a private key (for RSA/ECDSA).
Because the payload is only base64url-encoded, not encrypted, anyone can read it. That is why you should never paste a token into an online decoder if the token is still valid—the site operator could capture it. Even if the token expires in minutes, you are handing over a live credential to an unknown party.
Why Local Verification Matters
Verifying a JWT means checking two things: that the signature is valid (the token was not tampered with) and that the claims are acceptable (not expired, correct audience, etc.). Online tools that decode the payload are common, but they rarely verify the signature because they do not have your secret key. A token with a valid-looking payload but a forged signature would pass a naive decode, giving you false confidence.
Local verification with your own key is the only way to be certain. It also keeps the token on your machine, reducing the chance of interception or misuse. In a development or debugging context, you often have the secret or public key handy, so local validation is straightforward.
How to Inspect and Verify Locally (Step-by-Step)
You can use a command-line tool like jq plus standard Unix utilities, or a language-specific library. Here is a general approach that works on any system with Python:
- Copy the JWT string from your application logs or browser developer tools.
- Split the token by
.into three parts: header, payload, signature. - Decode the header and payload from base64url (replace
-with+and_with/, then add padding). - Inspect the decoded JSON for claims like
exp,iat,iss, andaud. - Verify the signature using the appropriate algorithm and key. For HS256, use the shared secret; for RS256, use the public key.
For example, using Python’s jwt library (PyJWT), you could run:
import jwt
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
secret = "your-secret-key"
decoded = jwt.decode(token, secret, algorithms=["HS256"])
print(decoded)
If the signature is invalid, the library raises an exception. If the token is expired, you will get a ExpiredSignatureError. This gives you both inspection and verification in one step.
Choosing the Right Tool for Your Environment
Your choice of tool depends on what you have installed and the token’s algorithm. For quick one-off checks, command-line tools like jwt-cli (a Node.js package) or jose (a Go tool) work well. For scripting and automation, use a library in your language: PyJWT for Python, jsonwebtoken for Node.js, jjwt for Java, or jose for Go. All of these verify signatures natively.
If you only need to see the payload and you are certain the token is expired or fake, you can decode it manually with a base64 decoder. But for any token that could still be valid, always use a tool that verifies the signature. Never rely on an online decoder for verification, because it cannot know your secret key.
Common Pitfalls and Misconceptions
A frequent mistake is assuming that base64 decoding is the same as verifying. Decoding only reveals the payload; it does not prove authenticity. Another pitfall is using the wrong key type—HS256 requires a symmetric secret, while RS256 requires a public key. Mixing them up will cause verification to fail even if the token is genuine.
Also, beware of algorithm confusion attacks. If your server accepts tokens signed with HS256 but you verify with an RSA public key, an attacker could forge a token by signing with that public key as if it were an HMAC secret. Always pin the allowed algorithms on the server side and in your local verification script.
Finally, do not ignore the exp claim. A token might have a valid signature but be expired. Always check the expiration time and other relevant claims after verifying the signature.
Comparing Online Decoders vs. Local Verification
Online JWT decoders are convenient because they require no setup. You paste the token and instantly see the header and payload. However, they have significant downsides:
- Security risk: You are sending a live credential to a third party.
- No signature verification: They cannot check the signature without your key.
- No claim validation: They do not tell you if the token is expired or has the right audience.
Local verification addresses all three. The token stays on your machine, you use your own key to verify the signature, and you can programmatically check claims. The only downside is the initial setup, but it pays off in security and accuracy.
Safety Tips for Handling JWTs
Treat a JWT like a password. Do not share it, do not paste it into random websites, and do not log it in plaintext. When inspecting tokens in logs, redact the signature portion. Use short expiration times to limit the damage if a token leaks. And always use HTTPS to protect tokens in transit.
If you must use an online tool, only do so with a token that is already expired or clearly a test token. But even then, you are training a habit that could lead to a mistake. The safest practice is to always verify locally.
Frequently Asked Questions
Can I decode a JWT without verifying the signature?
Yes, you can decode the header and payload by base64-decoding the first two parts. This is useful for inspecting claims, but it does not confirm the token is authentic. Always verify the signature before trusting the token.
What if I don’t have the secret key?
If you do not have the secret or public key, you cannot verify the signature. You can still decode the payload, but you must treat the token as untrusted. In a real application, the server that issued the token should have the key.
Is it safe to use online JWT decoders for expired tokens?
It is safer than using them for live tokens, but still not recommended. The token might contain sensitive information in the payload, and you are sending it to a third party. For any token, local verification is the secure choice.
How do I verify a JWT signed with RS256?
You need the public key from the token issuer. Use a library that supports RS256, such as PyJWT with the algorithms=["RS256"] parameter and the public key as the verification key. The library will handle the RSA signature check.
What does the exp claim mean?
The exp claim contains a Unix timestamp (seconds since 1970-01-01) after which the token is no longer valid. Verification libraries automatically reject tokens with an exp in the past. You should never accept an expired token.
Can I verify a JWT with a simple command-line tool?
Yes, tools like jwt-cli (npm) or jose (Go) let you verify tokens from the terminal. For example, jwt verify token --key secret will check the signature and show the payload. This is a fast, local alternative to writing a script.