# JSON Web Token

## **What are JWTs?**

* Standardized format for sending **cryptographically signed JSON data** between systems.
* Commonly used for **authentication, session handling, and access control**.
* **Stores all necessary data client-side**, making it ideal for **distributed systems** (multiple back-end servers).

## **JWT Format**

A JWT has **3 parts** separated by dots (`.`):

{% code overflow="wrap" %}

```
eyJraWQiOiI5MTM2ZGRiMy1jYjBhLTRhMTktYTA3ZS1lYWRmNWE0NGM4YjUiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTY0ODAzNzE2NCwibmFtZSI6IkNhcmxvcyBNb250b3lhIiwic3ViIjoiY2FybG9zIiwicm9sZSI6ImJsb2dfYXV0aG9yIiwiZW1haWwiOiJjYXJsb3NAY2FybG9zLW1vbnRveWEubmV0IiwiaWF0IjoxNTE2MjM5MDIyfQ.SYZBPIBg2CRjXAJ8vCER0LA_ENjII1JakvNQoP-Hw6GG1zfl4JyngsZReIfqRvIAEi5L4HV0q7_9qGhQZvy9ZdxEJbwTxRs_6Lb-fZTDpW6lKYNdMyjw45_alSCZ1fypsMWz_2mTpQzil0lOtps5Ei_z7mM7M8gCwe_AGpI53JxduQOaB5HkT5gVrv9cKu9CsW5MS6ZbqYXpGyOG5ehoxqm8DL5tFYaW3lB50ELxi0KsuTKEbD0t5BCl0aCR2MBJWAbN-xeLwEenaqBiwPVvKixYleeDQiBEIylFdNNIMviKRgXiYuAvMziVPbwSgkZVHeEdF5MQP1Oe2Spac-6IfA
```

{% endcode %}

1. **Header** – Contains metadata (e.g., algorithm used for signing).
   * Example: `{"alg": "HS256", "typ": "JWT"}`
2. **Payload** – Contains **claims** (user data and token info).
   * Example: `{"sub": "user123", "name": "Alice", "exp": 1735689600}`
3. **Signature** – Ensures data integrity (prevents tampering).

## **Key Features**

* **Base64URL-encoded** (not encrypted by default).
* **Stateless** (server doesn’t store session data).
* **Security relies on the signature** (if signature is weak/absent, tokens can be forged).

## How do vulnerabilities to JWT attacks arise?

### 1. Exploiting flawed JWT signature verification <a href="#exploiting-flawed-jwt-signature-verification" id="exploiting-flawed-jwt-signature-verification"></a>

### 2. Brute-forcing secret keys <a href="#exploiting-flawed-jwt-signature-verification" id="exploiting-flawed-jwt-signature-verification"></a>

### 3. JWT header parameter injections (jwk, jku, kid, cty, x5c) <a href="#exploiting-flawed-jwt-signature-verification" id="exploiting-flawed-jwt-signature-verification"></a>

### 4. JWT algorithm confusion <a href="#exploiting-flawed-jwt-signature-verification" id="exploiting-flawed-jwt-signature-verification"></a>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n0m4dsec.gitbook.io/sec-book/web-vulnerabilities/advanced-topics/json-web-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
