> 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-ssrf-lab/lab-4.md).

# lab-4

## SSRF with Whitelist-Based Input Filter

**Difficulty:** Expert

### Lab Description

This lab has a stock check feature which fetches data from an internal system. The developer has deployed an anti-SSRF whitelist defence that must be bypassed.

**Objective:** Change the stock check URL to access the admin interface at `http://localhost/admin` and delete the user `carlos`.

### Root Cause

The application performs improper URL validation by using ad hoc string matching instead of parsing the URL with a standards-compliant parser. Different components — such as the validation logic and the HTTP client — interpret the same URL differently, allowing a malicious URL to pass the whitelist check while the outbound request is made to an unintended destination.

### Exploitation

1. Identify the URL parameter that the server uses to make outbound requests.
2. Confirm that the application enforces a hostname whitelist.
3. Craft a URL that appears to match the whitelist but exploits URL parsing ambiguities — such as the userinfo component (`user@host`), double URL encoding, or parser discrepancies between the validation layer and the HTTP client.
4. The whitelist check accepts the crafted URL.
5. The HTTP client interprets the URL differently and sends the request to the intended internal destination (e.g. `http://localhost/admin`).
6. Access the admin panel from the response, retrieve the delete endpoint, and send a final request to delete `carlos`.

### Lesson Learned

* Never validate URLs using simple string operations such as `contains()`, `startsWith()`, or `endsWith()`.
* Parse the URL once using a standards-compliant parser, then validate the actual hostname and resolved IP address.
* Ensure the same parsing and decoding logic is used for both validation and the outbound request — discrepancies between the two are what make this attack possible.
* Validate the final destination after any redirects.
* Prefer strict allowlists combined with network-level egress restrictions over relying solely on application-layer URL validation.


---

# 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-ssrf-lab/lab-4.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.
