API Parameter Pollution and Injection
What You'll Learn
You'll learn how attackers manipulate duplicate parameters, arrays, and nested objects to trick APIs into accepting malicious input or bypassing validation rules.
The Core Problem
APIs often receive parameters in various formats—single values, arrays, or nested JSON objects. API Parameter Pollution occurs when an attacker sends duplicate or conflicting parameters to confuse how the API processes them. Different servers and frameworks handle duplicates differently: some take the first value, others the last, and some concatenate them into an array.
API Parameter Injection happens when attackers abuse these behaviors to inject malicious payloads into queries, commands, or data structures that the API wasn't designed to handle.
How It Works
Think of it like giving contradictory instructions: "Send package to 123 Main St. Send package to 456 Elm St." Some systems follow the first instruction, others the last. Attackers exploit this inconsistency.
Common Attack Vectors
Duplicate Parameters:
/api/user?id=123&id=456
The API might validate the first ID (123) but use the second (456) in the database query.
Array Injection:
/api/delete?item=safe_id&item[]=../../etc/passwd
Validation expects a string but receives an array, potentially bypassing filters.
Nested Object Pollution:
{
"user": {"role": "customer"},
"user": {"role": "admin"}
}
The second object might override the first, escalating privileges.
Parameter Type Confusion:
Sending price=0 as an array price[]=0 or object price[cost]=0 can confuse validation logic that expects a simple integer.
Why It Matters
These attacks bypass input validation, access controls, and business logic checks because the validation layer sees one thing while the processing layer acts on another.
Key Takeaway: APIs must consistently handle all parameter formats—duplicates, arrays, and nested objects—and validate data at the exact point where it's used, not just at entry.