Skip to main content
Be Bitwise

Injection & Mass Assignment

API Vulnerability Classes · API Security track

6 min read

In this module

Untrusted Input in APIs

APIs receive structured data — JSON objects, query parameters, headers — and feed that data straight into queries, commands, and database updates. When input slips into those operations without validation or sanitisation, injection vulnerabilities crawl out. When APIs cheerfully accept more fields than they should, mass assignment lets attackers modify things they were never supposed to touch.

SQL Injection in APIs

SQL injection in APIs follows the same principle as the web-app version, but the input vectors look different. Instead of form fields, you're prodding JSON values, query parameters, and HTTP headers.

json
{
"username": "admin",
"password": "' OR '1'='1"
}

If the API builds its SQL by concatenating those values straight into a query, the attacker walks past authentication. Modern APIs lean on ORMs and parameterised queries more reliably than older web apps did, so vintage SQL injection is rarer than it used to be. The juicier cases tend to lurk in sorting, filtering, and search functionality, where dynamic query construction is harder to safely parameterise.

http
GET /api/v1/products?sort=name;DROP TABLE users-- HTTP/1.1

Testing for SQL Injection

In Burp Repeater, walk every parameter through the standard payloads:

c
' OR '1'='1
' UNION SELECT NULL,NULL--
1; WAITFOR DELAY '0:0:5'--

The time-delay payload above is SQL Server syntax. Each database has its own:

c
SQL Server: 1; WAITFOR DELAY '0:0:5'--
MySQL: 1 AND SLEEP(5)--
PostgreSQL: 1; SELECT pg_sleep(5)--
Oracle: 1 AND 1=DBMS_PIPE.RECEIVE_MESSAGE('a',5)--

Time-based blind injection works especially well against APIs. The delay is trivial to measure on the wire and you don't need any visible error messages to confirm the hit.

NoSQL Injection

NoSQL databases like MongoDB take structured query objects rather than SQL strings. Injection happens when user input lands directly inside query operators.

json
{
"username": "admin",
"password": { "$ne": "" }
}

The $ne (not equal) operator quietly rewrites the password check as "password is not empty", which matches any document with a non-empty password field. Other unsafe operators in the same family: $gt, $regex, and $where.

json
{
"username": { "$regex": "^a" },
"password": { "$gt": "" }
}
NoSQL Injection Vectors

NoSQL injection is not limited to MongoDB query operators. When APIs pass user input into aggregation pipelines, map-reduce functions, or $where clauses that execute JavaScript, the impact can extend to arbitrary code execution on the database server.

Mass Assignment

Mass assignment shows up when an API binds client-supplied data straight onto internal data models without filtering which fields are allowed. The attacker tucks additional fields into the request, ones that happen to map to sensitive properties on the database model.

Take a user-profile update endpoint:

http
PUT /api/v1/users/me HTTP/1.1
Content-Type: application/json
{
"name": "Alice",
"email": "alice@example.com",
"role": "admin",
"credit_balance": 99999
}

The user should only be able to update name and email. If the API blindly slaps every submitted field onto the user model, role and credit_balance get updated alongside them. The attacker has just promoted themselves to admin and topped up their balance for free.

Discovering Mass Assignment Targets

To find exploitable fields, line up what the API returns in GET responses against what it documents in its PUT/PATCH schema. Anything that appears in the response but isn't in the documented update schema is a candidate for mass assignment.

API documentation, OpenAPI specs, and over-helpful error messages that spill model field names are all gold for sniffing out mass-assignment targets.

HTTP Parameter Pollution

HTTP Parameter Pollution (HPP) leans on the fact that servers don't agree on how to handle duplicate parameters. Some frameworks take the first value, some take the last, some concatenate the lot.

http
POST /api/v1/transfer HTTP/1.1
Content-Type: application/x-www-form-urlencoded
amount=100&recipient=attacker&amount=10000

If the validation layer reads the first amount (100) and the backend reads the last (10000), the attacker transfers far more money than the validator ever signed off on. Things get especially nasty when an API gateway validates parameters differently from the backend service behind it.

Input Validation Best Practices

Solid API input validation comes back to a few principles:

Allowlisting over blocklisting: spell out exactly which fields are accepted, with expected types, lengths, and patterns. Reject anything that doesn't match, rather than playing whack-a-mole with known-bad patterns.

Schema validation: enforce strict JSON Schema or OpenAPI schema validation on every request body. That catches unexpected fields (killing mass assignment) and type mismatches in one go.

json
{
"type": "object",
"properties": {
"name": { "type": "string", "maxLength": 100 },
"email": { "type": "string", "format": "email" }
},
"required": ["name", "email"],
"additionalProperties": false
}

additionalProperties: false is the magic line. It rejects any field not explicitly defined in the schema.

Parameterised queries: never build database queries with string concatenation. Use parameterised queries or prepared statements for SQL, and validated query builders for NoSQL.

Separate read and write models: keep distinct data-transfer objects for input (what the client can send) and output (what the API returns). That gives you a structural barrier against mass assignment even when a developer forgets to filter individual fields.

These injection and mass-assignment flaws often combine with BOLA. An attacker who can read another user's data via BOLA and then modify it via mass assignment turns a data read into a full account takeover. In the next lesson we'll look at how rate-limiting failures let these attacks run at scale.