> 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-1.md).

# lab-1

## JWT Authentication Bypass via Unverified Signature

**Difficulty:** Apprentice

### Lab Description

This lab uses a JWT-based mechanism for handling sessions. Due to an implementation flaw, the server doesn't verify the signature of any JWTs it receives.

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

**Credentials:** `wiener:peter`

### Root Cause

If a developer fails to distinguish between `decode()` and `verify()` in their JWT library and only applies `decode()`, the JWT signature is never validated. The server trusts user-controlled claims directly from the payload without any cryptographic verification, leading to a complete authentication bypass.

Secure flow:

```
Receive JWT
      │
      ▼
Verify Signature
      │
      ▼
Signature Valid?
      │
  Yes │ No
      │
      ▼
Read Claims
      │
      ▼
isAdmin = true
      │
      ▼
Allow Admin
```

Vulnerable flow:

```
Receive JWT
      │
      ▼
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. Send the request and open the response in the browser.
6. Click **Delete carlos** in the browser and capture the resulting request.
7. Send that request to Repeater, update `"sub"` to `"administrator"` in the JWT again, and send.
8. The user `carlos` is deleted.

### Lesson Learned

Always use `verify()` — not just `decode()` — when processing JWTs. The verification step checks that `sign(payload, secret) == signature` on the received token. Never blindly trust a decoded, user-controlled payload without first confirming the signature is valid.


---

# 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-1.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.
