Picture a housing society app. Asha in flat B-204 logs in and opens her maintenance bill. The app calls an endpoint that fetches bill number 88213. Out of curiosity, she changes the number to 88214 in a proxy tool, and the API returns her neighbour’s bill, with name, phone number and outstanding amount. Her login worked perfectly. The system knew exactly who she was. It simply never asked whether she was allowed to see that bill.

That gap between knowing who someone is and deciding what they may do is the difference between authentication and authorisation, and it is where many of the most damaging API flaws live.

Two separate checks

Authentication answers “who are you?” It verifies identity using something like a password, an OTP, a biometric, a certificate or a token issued after one of these. Authorisation answers “are you allowed to do this, to this particular thing?” It applies after identity is known, and it must be checked on every request, for every resource.

In most modern APIs, authentication happens once at login, and the client receives a token. The client then sends that token with each request, usually in the Authorization header using the Bearer scheme. Tokens are often JSON Web Tokens (JWTs), which carry claims such as the user’s ID, roles and an expiry time, signed so the server can detect tampering. With OAuth 2.0, an authorisation server issues access tokens, often short-lived, and sometimes refresh tokens used to obtain new ones.

The status codes reflect the split. A missing, expired or invalid token should produce 401. A valid token belonging to someone who lacks permission should produce 403, or 404 if the API prefers not to confirm that the resource exists.

Testing authentication

Authentication tests check that the door is locked and that the key behaves as designed:

  • Every protected endpoint rejects requests with no token. It is common for one forgotten endpoint, often an export or report, to be left open.
  • Expired tokens are rejected, and the expiry time in practice matches the documented one.
  • A token whose contents have been altered fails signature verification.
  • After logout or password change, old tokens stop working if the design says they should. Stateless JWTs make this harder, so it is worth confirming what the design actually promises.
  • Login is protected against repeated guessing, through lockout, rate limiting or CAPTCHA, as specified.
  • Tokens issued for one environment or client do not work on another.

Testing authorisation, where the real risk sits

The OWASP API Security Top 10 (2023 edition) puts Broken Object Level Authorisation in first place, which is exactly the housing society bug: the API accepts an object identifier from the client and fails to check that the caller owns or may access that object. The same list includes Broken Function Level Authorisation, where an ordinary user can call an admin function, and Broken Object Property Level Authorisation, where a user can read or change fields they should not, such as setting their own account’s credit limit through an update request.

These bugs share a feature that makes them invisible to ordinary functional testing: every test written from a single user’s point of view passes. To find them, tests need at least two identities and must deliberately cross the boundary between them.

A practical authorisation matrix

A simple, systematic method is to build a matrix of actors against operations. For the society app, the actors might be resident A, resident B, a committee treasurer, and an unauthenticated caller. The operations are the endpoints. For each cell, write the expected result.

OperationResident A (owner)Resident BTreasurerNo token
View A’s billAllowedDeniedAllowed401
Pay A’s billAllowedDeniedDenied401
Change A’s bill amountDeniedDeniedAllowed401
List all residents’ duesDeniedDeniedAllowed401

Each cell becomes an automated API test: create the data as one user, then attempt the operation with each other user’s token, and check the expected outcome. The “Denied” cells are the valuable ones, and they are precisely the cases a single-user test suite never runs. Note also that “denied” must mean nothing changed, not merely that an error message appeared after the update was already saved.

Some further variations worth covering:

  • Identifiers in different places. Object IDs can appear in the path, the query string, the request body and even headers. Each place needs the same ownership check.
  • Indirect access. Listing endpoints, search, exports and file downloads often bypass the checks applied on the main “get by ID” endpoint.
  • Fields in update requests. Send fields the user should not control, such as role, status or owner ID, and confirm they are ignored or rejected.
  • Multi-tenant systems. In B2B SaaS, the same checks apply across companies, and a leak between tenants is usually far more serious than one between users.

Making it part of normal automation

The practical obstacle is usually test setup, not the checks themselves. An automation framework needs a reliable way to obtain tokens for several test users with different roles, ideally by calling the login or token API directly rather than through the UI, and caching tokens until they near expiry. Once that exists, each new endpoint can be added to the matrix with a few lines of configuration.

Hiding identifiers by making them random UUIDs instead of sequential numbers is sometimes offered as the fix. It makes guessing harder, but IDs leak through URLs, logs, shared links and other responses. Unpredictable IDs are a reasonable extra layer; the server-side ownership check is the actual control, and it is what the tests must prove. For organisations handling personal data in India, this matters beyond engineering, since the Digital Personal Data Protection Act, 2023 places duties on organisations to protect personal data with reasonable security safeguards.

Written by the RP Strativa Team. The housing society app, users and identifiers are illustrative.

Leave a Reply

Trending