JSON Web Token (JWT) (original) (raw)

Last Updated : 3 Jun, 2026

JSON Web Token (JWT) is a compact and secure method for transmitting information between parties as a JSON object. It is commonly used for authentication and authorization in web applications, allowing users to access protected resources without repeatedly providing credentials. Key features include:

JWT Structure

JWT mainly consists of 3 components, separated by dots(.):

Header. Payload. Signature

structure_of_a_json_web_token_jwt_

Structure of a JWT

The header contains metadata about the token, including the signing algorithm and token type.

{
"alg": "HS256",
"typ": "JWT"
}

where,

**Example

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

2. Payload

The payload contains the information about the user also known as a claim and some additional information including the timestamp at which it was issued and the expiry time of the token.

{
"userId": 123,
"role": "admin",
"exp": 1672531199
}

**Common claim types:

**Example:

eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNzA4MzQ1MTIzLCJleHAiOjE3MDgzNTUxMjN9

3. Signature

The signature ensures token integrity and is generated using the header, payload, and a secret key.

HMACSHA256(
base64UrlEncode(header) + "." + base64UrlEncode(payload),
secret
)

**Example:

SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

**Final JWT token:

After all these steps the final JWT token is generated by joining the Header, Payload and Signature via a dot. It looks like as it is shown below.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9****.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNzA4MzQ1MTIzLCJleHAiOjE3MDgzNTUxMjN9**.**SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

JWT Authentication Working

JWT is used for authentication. This is the whole flow of the Authentication process:

client

Here are the key steps:

**Note: JWTs are primarily used for authentication and secure data exchange in web applications and APIs.

Hand-On Lab: JWT

Below is a step‑by‑step hands‑on lab on JWT authentication bypass due to an unverified signature. We are using PortSwigger to work through this hands‑on lab. Access the lab at the following link:

JWT authentication bypass via unverified signature

Step 1: Understand the Lab and Set Up Burp Suite

image---2025-09-27T180038271

Step 2: Log In and Capture the Session Token

On the lab website, log in using the credentials wiener:peter.

image---2025-09-27T164105381

file

Step 3: Decode and Analyze the JWT

image---2025-09-27T164109986

Step 4: Test Admin Access

file

Step 5: Modify the JWT to Impersonate Administrator

jwt6

file

Step 6: Delete the User Carlos

file

/admin/delete?username=carlos

file

file

Security Considerations

When working with JWTs, keep these best practices in mind to ensure safe and reliable authentication:

Common Issues During Development with JWT