Access control

Public API Security: Authentication and Access Control

Protect internet-facing APIs with clear identities, resource-level checks, safe defaults, and abuse controls.

Published: 19 September 2026 · APISAST

Updated: 19 September 2026

Define what “public” means

Public API security starts by separating an internet-reachable endpoint from an endpoint that allows anonymous access. A public weather feed may allow anonymous reads; an account endpoint can be publicly reachable while requiring a token on every request. Record which operations are anonymous, which identify an application, and which act for a user. Make these decisions explicit in the API contract and access policy.

Choose an identity that matches the action

An API key can identify an application for quota and reporting, but it is usually a poor substitute for user authorization. Use OAuth2 access tokens when a client needs delegated access. Give service clients their own identities and narrow permissions. Keep credentials out of URLs, examples, and browser-visible source. Rotate them and revoke compromised credentials quickly.

The OAuth2 and JWT authentication guide explains token validation and OpenAPI security schemes.

Authorize every resource request

Check that a valid caller can perform the requested action on the specific object. This applies to reads, writes, exports, and nested resources. Avoid relying on hard-to-guess IDs or a role check without a tenant and ownership check. For list endpoints, apply authorization before pagination and filtering so a page count or search result cannot reveal another tenant’s records.

Test with two users who have different permissions. Attempt to read and change each other’s objects, including through bulk operations and alternate routes. A static OpenAPI scan can identify missing declared security, but it cannot determine whether these runtime checks are correct.

Limit abuse and document failure states

Apply rate limits by a verified identity, with a stricter policy for login, reset, and expensive searches. Use bounded request bodies and collection pages. Return clear 401, 403, and 429 responses; avoid disclosing whether a private account exists through error wording. Log access decisions and anomalies without recording access tokens.

Make anonymous access an explicit decision

List each endpoint that may be called without credentials and the exact data it can return. A health endpoint and a public product catalogue may be appropriate, while account details and exports are not. If an operation overrides a global OpenAPI security requirement with an empty requirement, document why. Review anonymous operations whenever a field is added: a harmless catalogue response can become sensitive if it begins to include supplier contacts or internal prices.

For protected routes, record which identity is expected and whether it represents a person, an application, or another service. Use a separate test for each class of caller. An API key may support metering for a public integration, but a key shared by every end user cannot establish which user owns a private record. This distinction keeps authentication, authorization, and quota decisions from being conflated.

Review ownership on every data path

A permission check on GET /documents/{id} is insufficient if a search, export, or attachment route exposes the same document. Map sensitive resources to every operation that reads or modifies them. Apply tenant and object ownership constraints in the data query, and recheck them for bulk updates. Return a response that does not reveal private object existence where doing so would leak information.

Test with one object owned by each of two users, a shared object, and an anonymous caller. Attempt direct IDs, list filters, pagination cursors, and nested routes. Record the expected 401 or 403 outcome for each case and make it part of CI. APISAST can identify missing declared authentication on an OpenAPI operation, but only these tests can establish whether object-level authorization works.

Give integrators a safe recovery path

Document what a client should do when a token expires, a permission changes, or a quota is exhausted. A 401 may prompt token renewal; a 403 needs a permission change or a different identity; a 429 asks the client to slow down. Make those cases distinguishable without revealing internal policy logic. Include request IDs in server logs so support can diagnose a failure without asking customers to send credentials.

Publish examples with placeholders rather than real tokens. Bound request bodies and list responses, document the maximum size, and encourage clients to back off with jitter. Review error and retry behaviour from the perspective of a small integration that has no direct access to your platform team. Clear documentation reduces accidental abuse and makes genuine attacks easier to separate from client mistakes.

Review credential lifecycle as part of the public interface. Give an integration a way to create, rotate, and revoke its own keys without sharing an administrator's personal account. Show the key's last use and allowed scope where the product supports it. If a credential leaks, the owner should be able to disable it promptly and understand which clients will fail. For user-delegated access, document consent and token renewal clearly so a partner does not copy long-lived access tokens into configuration files.

Keep the public documentation in step with the actual gateway. A developer who reads a documented 429 or 403 should be able to reproduce and handle that response in a test environment. Compare the deployed route list with OpenAPI regularly; an undocumented public route can escape the review process entirely.

Use the specification as a review checklist

Declare security schemes and operation requirements in OpenAPI. Document the actual error responses, pagination parameters, and rate limit headers. Run the API security scanner to find missing declarations and risky design signals, then verify enforcement with integration tests and monitoring. The API SAST overview explains where contract checks fit in the process.

More API security guides