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

API › API security

Information leaks: errors, URLs, logs and enumeration

An information leak in an API is excess visibility. Typical places: stack traces and SQL in errors, different responses for exists and does not exist, secrets in URLs and logs, forgotten versions. QA provokes errors and compares responses for an existing and a missing id or email by status, body and timing. Diagnostics stay in logs by request id. Choosing 404 over 403 depends on the product.

API · Security

Someone else's id gives 403, a non-existent one gives 404. What does this reveal to an attacker?

Much of the damage comes not from broken access but from information the API gives away between the lines. An error message with a class name and an SQL query, different responses for "exists" and "does not exist", a token in a query string, a password in logs. None of these opens data by itself, but each makes the next step easier. This lesson covers where an API gives away too much and how QA finds these places systematically.

How it is built

Information leaks belong to the class of "excess visibility": information useful for diagnostics is visible to those it was not meant for. In the OWASP API Top 10 2023 these are mostly API8 Security Misconfiguration (verbose errors, extra headers, open service endpoints) and API9 Improper Inventory Management (forgotten versions and documentation). Enumeration of accounts and resources sits next to them: it is not a separate item of the list but a consequence of different responses to different situations.

Why it is so. For a developer an error with a trace is convenient: you see what broke. Different responses for "not found" and "forbidden" are convenient for a client: it understands what to do. Both principles are normally right, and the problem is that at the trust boundary (a public API) they have to be limited deliberately. Diagnostics move to logs under a request id, and the client gets a general response.

Example: five places to look

1. Error messages. I provoke errors: broken JSON, a very long value, the ' character, an invalid id. I look at the body and the headers. Here is a response with defects:

HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Server: Apache-Coyote/1.1
X-Powered-By: Servlet/4.0 JSP/2.3

{ "error": "org.postgresql.util.PSQLException: ERROR: invalid input syntax
  for type integer: \"abc\"", "trace": "at com.shop.UserRepo.find(UserRepo.java:88)" }

There are three leaks: the exception class and the DBMS text, a stack trace with a file name, and in the headers the framework version (Server, X-Powered-By). A correct response is general, and the details live in logs under X-Request-Id:

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
X-Request-Id: 5b0e7c2a

{ "type": "https://api.shop.test/errors/validation",
  "title": "Invalid request", "status": 400,
  "detail": "id must be a number" }

An automated check looks for these signs in all error responses:

const LEAK = /stack|exception|\bat [\w$.<>]+ ?\(|SELECT |psql|jdbc|node_modules/i;

test('errors do not leak internals', async ({ request }) => {
  const probes = [
    request.get('/v1/users/abc'),
    request.post('/v1/users', { data: 'not json', headers: { 'Content-Type': 'application/json' } }),
    request.get('/v1/users', { params: { q: "'" } }),
  ];
  for (const res of await Promise.all(probes)) {
    expect(res.status()).toBeLessThan(500);
    expect(await res.text()).not.toMatch(LEAK);
    expect(res.headers()['x-powered-by']).toBeUndefined();
  }
});

The error the client sees

Typical

Diagnostics for the developer

Exception class, SQL, file path, server version. An attacker learns which DBMS you have and where the weak spot is.

Better

A response for the client

A short description, a stable code and a request id. The rest lives in logs, and only the team has access to it.

Figure 1. The same error source, a different visibility. The request id links the response to the log.

2. Enumeration. If the response differs for "exists" and "does not exist", it is extra information:

  • 403 for someone else's /invoices/1002 and 404 for a non-existent /invoices/999999 show which ids exist in the system. When the product requires hiding other people's resources, both cases give 404. This is a product decision: it is checked against the contract, not "fixed".
  • Login: "No such email" versus "Wrong password" lets one enumerate accounts. One phrase for both and a comparable response time are needed.
  • Password reset and registration: the same response for a known and an unknown email ("if the account exists, we sent an email").
test('login does not reveal which accounts exist', async ({ request }) => {
  const known = await request.post('/v1/login', {
    data: { email: 'real@example.test', password: 'wrong-password' },
  });
  const unknown = await request.post('/v1/login', {
    data: { email: 'nobody-7731@example.test', password: 'wrong-password' },
  });
  expect(known.status()).toBe(unknown.status());
  expect(await known.json()).toEqual(await unknown.json());
});

The test compares the status and the body. Response time can also reveal a difference (the hash is checked only for an existing account), but because of network noise it is checked over a large series of requests or with a separate tool, not with one expect.

3. Secrets in the URL. A token, key or password in the query (?api_key=...) ends up in proxy logs, browser history and, under a weak Referrer-Policy, the Referer header. Secrets go in Authorization or in a POST body. Also check that a password reset link is single-use and short-lived.

4. Logs and responses. A password, token or card number must be neither in a response (passwordHash, a full PAN) nor in request logs. A tester checks masking (**** 1111) and asks developers to show the logs or looks at them on a test environment.

5. Forgotten surfaces. A public Swagger UI in production, open /actuator and /debug, old API versions without protection (/v1 left after /v2 appeared) also give information and widen the attack surface. The list of endpoints is compared with the documentation.

Limits and alternatives

  • Hiding the difference between 403 and 404 is worth it when the very existence of a resource is sensitive (accounts, medical records). For public resources 403 may be an honest answer, and hiding only makes diagnostics harder for clients. The decision depends on the product.
  • Identical login responses hurt usability: the user does not know whether the email or the password was wrong. It is a deliberate compromise that a product usually accepts in favour of security.
  • The Server and X-Powered-By headers are not a vulnerability by themselves: they are noise that helps reconnaissance. They are removed as hygiene but not treated as a critical defect.
  • This check automates well for errors (leak patterns) and worse for enumeration (you need to know what counts as "exists").

Common mistakes

  • Checking only successful responses. Leaks live in errors, so they have to be provoked.
  • Treating a stack trace as "just a message". It reveals classes, libraries and paths that make a targeted attack easier.
  • Not comparing responses for "exists" and "does not exist". A difference in status, body or time is a leak channel.
  • Catching only "500". A leak can also be in a 400 with a detailed DBMS validation error text.
  • Copying a production token or password into a ticket or chat. It creates the very problem being tested.

Check yourself

Login returns 401 "Wrong password" for an existing email and 404 "User not found" for a non-existing one. What is wrong and how to fix it?

Answer

Different statuses and texts reveal which emails are registered, and passwords can then be guessed for them. The fix: the same status (usually 401) and the same general phrase for both cases, without a noticeable difference in response time.

A leak test looks for the word Exception in the response body, and no response contains it. Does that mean there are no leaks?

Answer

No. The test checks one sign in the responses you provoked. You also need to look at headers (Server, X-Powered-By), errors of different kinds (400, 404, 405, 415) and the difference between responses for existing and non-existing resources.

In an interview. Junior: Besides access, I check that errors do not reveal internals, that someone else's and a non-existent resource look the same, that secrets are not in the URL or in logs, and that responses have no extra fields. Middle/Senior: I deliberately provoke errors (broken JSON, a quote, a long value) and look at the body and headers for traces, SQL and versions. I compare responses for an existing and a non-existing id or email, because a difference in status, text or time gives enumeration. Diagnostics stay in logs under a request id, and the client sees a general response. I remember that 404 instead of 403 is a product decision, checked against the contract.

More articles in this chapter