> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-jwt-labs/lab-2.md).

# lab-2

## JWT Authentication Bypass via Flawed Signature Verification

**Difficulty:** Apprentice

### Lab Description

This lab uses a JWT-based mechanism for handling sessions. The server is insecurely configured to accept unsigned JWTs.

**Objective:** Modify your session token to gain access to the admin panel at `/admin`, then delete the user `carlos`.

**Credentials:** `wiener:peter`

### Root Cause

The JWT header contains an `alg` parameter that specifies the algorithm used to create the signature hash. If `alg` is set to `none` and the signature part is empty (leaving the format as `header.payload.`), this is still a structurally valid JWT. If the developer hasn't explicitly told the server to reject tokens with `alg: none` and an empty signature, the server simply decodes the header and payload and accepts the token — leading to session hijacking and account takeover without needing the secret key.

Secure flow:

```
Receive JWT
      │
      ▼
Reject if alg:none and signature is empty
      │
      ▼
Verify Signature
      │
      ▼
Signature Valid?
      │
  Yes │ No
      │
      ▼
Read Claims
      │
      ▼
isAdmin = true
      │
      ▼
Allow Admin
```

Vulnerable flow:

```
Receive JWT
      │
      ▼
Accept alg:none with empty signature
      │
      ▼
Decode JWT
      │
      ▼
Read Claims
      │
      ▼
isAdmin = true
      │
      ▼
Allow Admin
```

### Exploitation

1. Start the login process and capture all packets in Burp Suite.
2. Find `GET /my-account?id=wiener` and send it to Repeater.
3. Update the endpoint to `GET /admin`.
4. In the JWT payload, change `"sub"` to `"administrator"`.
5. In the JWT header, change `alg` to `none`.
6. Remove the signature portion of the token but **leave the trailing dot** — the format must remain `header.payload.`.
7. Send the request and open the response in the browser.
8. Click **Delete carlos** in the browser and capture the resulting request.
9. Send that request to Repeater and repeat steps 4–6.
10. Send the request — the user `carlos` is deleted.

### Lesson Learned

Servers must explicitly reject tokens with `alg: none` and an empty signature. Due to the obvious security implications, most modern JWT libraries disable the `none` algorithm by default — but it's important to verify this is the case and never assume it is.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-jwt-labs/lab-2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
