Resources

What are the Best API Security Practices to Keep Data Safe?

What are the Best API Security Practices to Keep Data Safe?

Most API security advice fails because it starts with tools. Start with a list of every API you run, then fix who can read which record, and only then think about scanners and gateways.

Teams that buy the tool first usually end up protecting the three APIs they remember and missing the fourth that a contractor deployed two years ago.

Nobody monitors that fourth one, and attackers find it first.

Where does API security start?

With an inventory. You cannot protect an endpoint you do not know exists, and the OWASP API Security Top 10 (2023 edition) lists improper inventory management as its own risk for exactly that reason.

The usual culprits are old API versions that never got switched off, test endpoints that reached production, and undocumented routes added for one partner. People call these zombie or shadow APIs. A scan of the source code and the API documentation turns up most of them, and a security consultant can do that pass if nobody on the team has time.

Cloud deployments make the problem worse because it takes one pipeline change to publish a new route, and cloud application security only works if the list of routes is current. Keep the registry next to the code, with an owner and a deprecation date for each entry. Searching your own API articles is a fine way to refresh what each interface is meant to do.

Four checks every API request passes in order: gateway, authentication, authorization and input validation, with authorization highlighted

Token handling

An API key identifies a project. It does not identify a person, and it cannot say what that person may do. Treat keys as a convenience for rate limiting and billing, not as authentication.

For user-level access, use OAuth 2.0 with short-lived access tokens and narrow scopes. If the tokens are JWTs, validate all of it: the signature, the allowed algorithm (reject “none”), the issuer, the audience and the expiry. Half-validated JWTs are a classic bug, because a library will happily decode a token it never verified.

Rotate keys on a schedule and keep them out of repositories and mobile app bundles.

Is an API key enough to authenticate callers?

No. It is a shared secret, anyone holding it is that caller, and you cannot revoke one person without cutting off everyone who uses the same key.

A gateway will not fix broken authorization

This is the part most checklists skip, and it is where the real damage happens. Broken object level authorization sits at number one in the OWASP API Security Top 10 for 2023. A caller is logged in, fully authenticated, and simply changes an ID in the URL from 1041 to 1042 to read someone else’s order.

A gateway cannot catch that.

It sees a valid token and a well-formed request, and it has no idea who owns order 1042. The check has to live in the application code, on every handler that takes an identifier, and it has to compare the record’s owner with the caller. Tests that try one user’s token against another user’s records catch most of these before release.

YouTube player

An API gateway is still worth running. It terminates TLS, applies rate limits, rejects oversized requests and gives you one place to log. Vendors such as Checkmarx sell scanning on top of that, which helps find the missing checks. It does not write them.

Unrestricted resource consumption is also on the 2023 list, so rate limits belong on expensive endpoints like search and export, not only on login. Validate input against a schema and reject fields you did not define, because mass assignment bugs come from APIs that accept more than they expose.

For survey data on how organisations run their APIs, RapidAPI’s state of enterprise APIs report is one place to look. I would treat any single vendor’s attack statistics with some suspicion, since each one counts different things.

Does a web application firewall cover API traffic?

Partly. It blocks known bad patterns such as SQL injection strings, but it cannot tell a legitimate request for someone else’s record from a legitimate request for your own, which is the more common API flaw. Plenty of teams run one and still leak data through plain authorization gaps, so put the WAF in as a layer and keep the ownership checks in code.

Exceptions

Not all of this applies to every API. A small internal service with one consumer does not need a central OAuth server, and mutual TLS between two services you also own may cost more in certificate handling than the risk justifies. The same goes for a full zero-trust rollout on a prototype that has no customer data. Scale the controls to what a leak would cost, and be honest about what that is. A public weather endpoint and a billing API are not the same problem.

Machine-learning traffic monitoring is something I would skip until you have logs worth analysing. Well, it depends on volume, but a team without basic request logging gains nothing from it.

What you cannot skip, at any size, is the inventory and the per-record ownership check.

Everything else can wait for the second quarter.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.