QA Interview Hub · Knowledge base · Quizzes · Українська

API › API security

Excessive data, mass assignment, injections, rate limiting

A server exposes excessive data when it serializes a model as is, and accepts forbidden fields (mass assignment) when it binds a request body onto a model. Tests read the raw JSON, not the screen, and recheck state with a separate GET, since 200 does not prove a field was ignored. Injections must not give 500, and a rate limit gives 429 with Retry-After.

API · Security

PATCH of a profile got an extra role: admin field and it was saved. How do you find it before production?

The UI shows a name and an email, and the profile looks tidy. But the raw JSON response contains passwordHash and internalRiskScore, and PATCH /users/me with an extra field "role": "admin" makes the user an admin. None of it is visible on screen, so a manual check through the browser misses it. This lesson covers the risks where the server returns or accepts more than intended, plus the checks for injections and limits.

How it is built

In the 2023 edition of the OWASP API Security Top 10, "excessive data" and mass assignment are merged into API3 Broken Object Property Level Authorization: access to the object is allowed, but the server does not distinguish which of its fields may be read and changed. Next to it stand API4 Unrestricted Resource Consumption (no limits) and injections as a class of input validation errors. They share one cause: the server works with the whole object instead of describing explicitly what belongs to the contract.

Excessive data exposure. The handler fetches a model from the database and serializes it as is, counting on the frontend to show only what is needed. This is what arrives on the network:

{
  "id": 7,
  "name": "Ivan",
  "email": "ivan@example.test",
  "passwordHash": "$2b$10$...",
  "isAdmin": false,
  "internalRiskScore": 0.82,
  "card": "4111111111111111"
}

Mass assignment. The framework automatically copies the fields of the request body onto the model. If the model has a role field, the client can send it:

PATCH /v1/users/me HTTP/1.1
Authorization: Bearer <user token>
Content-Type: application/json

{ "name": "Ivan", "role": "admin", "isVerified": true, "balance": 1000000 }

The whole object versus an explicit list of fields

Typical

The model directly

The response returns every field of the model, the request writes every field of the body. Each new database field automatically becomes part of the API, including internal ones.

Better

Explicit DTOs or schemas

A separate list of fields for the response and for writing. An unknown field is ignored or gives 400. A new database field does not reach the API until it is added deliberately.

Figure 1. Both problems have one source: the API contract equals the database structure. The fix is also one: describe the contract separately.

Why it is so. Serializing a model "as is" and binding a body onto a model save code, so they are on by default. The price is deferred: every field added to the model later becomes readable and writable without any security decision.

Example: what to check and how

1. Excessive data. I read the raw JSON, not the screen, and compare the list of fields with the contract. The simplest way is a schema with additionalProperties: false: then every new field breaks the test and forces a decision. Separately I search by name: password, hash, token, secret, a full card number.

2. Mass assignment. I send fields the client must not be able to change and check with GET that they did not change:

test('PATCH /users/me ignores fields the client must not set', async ({ request }) => {
  const before = await (await request.get('/v1/users/me')).json();

  const res = await request.patch('/v1/users/me', {
    data: { name: 'Ivan', role: 'admin', isVerified: true, balance: 1000000 },
  });
  expect([200, 400, 422]).toContain(res.status());

  const after = await (await request.get('/v1/users/me')).json();
  expect(after.role).toBe(before.role);
  expect(after.isVerified).toBe(before.isVerified);
  expect(after.balance).toBe(before.balance);
});

Three answers are acceptable: 200 with the field ignored, 400 or 422. One thing is not: the value changed. Checking the status is not enough, because 200 does not say whether the field was saved, so the test reads the state after the request.

3. Injections. SQL, NoSQL or command injection through parameters. For QA a basic set is enough: quotes, boolean conditions, special characters, NoSQL operators and very long strings in fields and query:

const payloads = ["'", "' OR 1=1--", '"; DROP TABLE users;--', '{"$ne": null}', 'A'.repeat(100000)];

for (const p of payloads) {
  test('search survives payload ' + p.slice(0, 12), async ({ request }) => {
    const res = await request.get('/v1/users', { params: { q: p } });
    expect(res.status()).toBeLessThan(500);
    const text = await res.text();
    expect(text).not.toMatch(/SQL|syntax error|stack|Exception/i);
  });
}

Expected: 4xx or a correct result (for a search it is just "nothing found"), no 500 and no SQL fragments in the body. It is a quick check for obvious errors, not a replacement for a pentest: parameterized queries in the code are only found by a code review.

4. Rate limiting. Without limits an API can be flooded, and four-digit SMS codes can be brute-forced. I check that after the threshold comes 429 with Retry-After:

test('login is rate limited per account', async ({ request }) => {
  const statuses: number[] = [];
  for (let i = 0; i < 20; i++) {
    const res = await request.post('/v1/login', {
      data: { email: 'user@example.test', password: 'wrong-' + i },
    });
    statuses.push(res.status());
  }
  expect(statuses).toContain(429);
  const limited = await request.post('/v1/login', {
    data: { email: 'user@example.test', password: 'wrong-x' },
  });
  expect(limited.headers()['retry-after']).toBeTruthy();
});

Limits and alternatives

  • A limit may apply per IP, per account or per API key, and these are different risks: an IP-only limit is bypassed by a distributed attack, an account-only limit does not stop guessing across many accounts with one password. Check both dimensions if they are declared.
  • In a limit test it is important not to lock the test account for other tests. Use a separate user and clear the lock after the run.
  • Page and file size are resources too: limit=100000 or uploading 2 GB must not take the service down. Expected: a cap on the maximum (page of 100 instead of 100000) or 400/413.
  • For injections, tools (ZAP, sqlmap) find more than a manual set, but they are noisy and create data. Run them on a test environment, not on production.

Common mistakes

  • Looking at the response in the UI. An extra field is not visible on screen but is in the JSON.
  • Checking only the status after mass assignment. 200 does not mean the field was ignored, so the state is read with a separate GET.
  • Accepting any response to an injection. A 500 with a DBMS error is a defect and a leak at once.
  • Testing a limit with one request. A limit triggers on a series, so check the sequence and the Retry-After header.
  • Bringing production down with load for the sake of "checking the limit". These tests run on a separate environment.

Check yourself

PATCH /users/me with "role": "admin" returns 200 and the body shows "role": "user". Is it a bug?

Answer

Probably not: the server ignored the field, which is an acceptable reaction. But the response could have been built from the input, so check with a separate GET /users/me and, if possible, by behaviour (whether admin functions are available).

For a search ?q=%27 (a quote) the server returns 500 with a stack trace. Which two problems are here?

Answer

First: unhandled input leads to an internal error, so validation or query parameterization is missing. Second: the body reveals internal details (a class, a query, a file path). Correct: 200 with an empty result or 400, an error without internal details.

In an interview. Junior: I look at the raw JSON for extra sensitive fields, try mass assignment by adding role or balance to the body, and basic injections in string fields. I also check rate limiting: after the limit there must be a 429. Middle/Senior: The cause of the first two is that the contract equals the model structure, so I look for explicit response and write schemas with additionalProperties: false. After mass assignment I read the state with a separate GET instead of trusting the status. For limits I check IP, account, page size and that the response contains Retry-After.

More articles in this chapter