API testing
API testing probes endpoints, documentation, mass assignment, and parameter pollution that can be exploited in REST APIs.
Material
API testing verifies how REST endpoints behave outside the main UI paths. It looks for hidden endpoints leaked through documentation, parameters the server processes even though they should be ignored, and body values the user is allowed to write freely.
How it works
Every endpoint has three surfaces to test: the path and HTTP method, the query string and headers, and the JSON body. Applications often validate exactly the fields the web form sends, yet accept extra fields from other clients such as mobile apps or scripts.
POST /api/users HTTP/1.1
Host: target.website
Content-Type: application/json
{
"username": "budi",
"email": "budi@example.com",
"role": "admin",
"isAdmin": true
}A server that copies the whole JSON object into the user document stores role admin along with every other submitted attribute. A 201 response whose body shows role admin is direct proof that free-form attribute writing works.
GET /api/products?category=tools&category=admin HTTP/1.1
Host: target.website
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{"items":[{"name":"Kunci pas","category":"tools"}],"applied":"tools"}Repeating one parameter with different values creates a discrepancy between layers. The frontend usually sends the first value while the framework or proxy may read the last one, and any difference in interpretation can be turned into an access control bypass.
Attack forms
- Mass assignment: the client sends role, balance, or price fields that never existed in the form, and the server accepts them unfiltered.
- Undocumented endpoints: an old API map, a health check, an admin path, or an internal route left running in production.
- Parameter pollution: one parameter is repeated with different values so the server picks the one the client did not expect.
- _method override: an endpoint that rejects POST accepts PUT or PATCH through a special parameter, so the method check is bypassed.
- Weak per-object authorization: an id or filter parameter that is not ownership-checked opens a path to another user's data.
Prevention
- Apply a field allowlist when constructing objects: copy only the attributes present in the schema, not the whole payload.
- Validate the body schema and reject unknown properties during deserialization.
- Normalize the query string so every parameter carries a single value before business logic runs.
- Remove unused documentation and endpoints from production builds, and run automated API checks in the pipeline.
- Enforce per-object authorization rather than only authentication at the endpoint level.
const ALLOWED = ["username", "email", "password"];
function createUser(body) {
const payload = {};
for (const key of ALLOWED) {
if (Object.prototype.hasOwnProperty.call(body, key)) {
payload[key] = body[key];
}
}
return db.users.insertOne(payload);
}An OpenAPI document is a very useful map for an attacker, so treat every schema file as something deliberately published. Endpoints nobody uses ought to be removed, not merely hidden.
Labs in this topic
Labs run on a domain separate from this site, so a payload cannot reach your account session.
Labs for this category land in Phase 2. The material is readable now.
Challenges in this category
Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.