Technology - Non SAP

API Security Essentials

APIs are the connectors of the modern web. They power mobile apps, system integrations, cloud platforms, and nearly every digital product in use today. And because they handle so much data and business logic, they are also one of the most targeted attack surfaces.

This post covers the security essentials — what every developer, architect, and technical consultant needs to understand when building or working with APIs.

🔗 Before you read this

API security sits on top of two foundations covered in earlier posts on this site. If you are new to APIs, start with REST API Design Principles for how APIs are structured, and How HTTPS Works for how data is protected in transit. This post builds on both.

Why API security is different

Traditional web security protects what users see — login pages, forms, sessions. API security protects what systems talk to each other — endpoints, tokens, data payloads.

APIs are harder to secure because:

  • They are designed to be accessible — often publicly exposed by intent
  • They expose business logic directly, not just a user interface
  • They carry structured data (JSON, XML) that is easy to parse and exploit
  • They are often consumed by many clients — mobile apps, third-party services, internal systems — each with different trust levels
  • Old or undocumented API versions frequently stay live and unpatched

The three questions every API must answer

Before getting into specific mechanisms, every API security decision comes back to three questions:

QuestionSecurity concernMechanism
Who are you?Authentication — confirming identityAPI keys, OAuth tokens, JWT
What are you allowed to do?Authorisation — controlling accessScopes, roles, permissions
How much can you do?Rate limiting — preventing abuseRequest quotas, throttling

Most API security failures come down to one of these three being missing, weak, or incorrectly implemented.

Authentication — proving who you are

API Keys

An API key is a long, randomly generated string passed with every request. The server checks the key and either allows or rejects the request.

AspectDetail
How it is sentUsually in a request header: x-api-key: abc123xyz or as a query parameter (less secure)
Best forServer-to-server calls, internal integrations, simple public APIs
WeaknessA stolen key gives full access until it is revoked — no user identity, no expiry by default
Best practiceRotate keys regularly, use different keys per environment, never hardcode in source code

API key authentication flow diagram showing client sending API key in request header and server responding with 200 OK or 401 Unauthorized

OAuth 2.0 and Bearer Tokens

OAuth 2.0 is the standard for delegated access — letting a user or system grant an application access to resources without sharing a password.

Instead of a static API key, OAuth issues a short-lived access token (called a Bearer token). The client sends this token with every request.

AspectDetail
How it is sentAuthorization header: Authorization: Bearer
Token formatUsually JWT (JSON Web Token) — a self-contained token carrying identity and permissions
ExpiryTokens are short-lived — typically minutes to hours — reducing the impact of theft
Refresh tokensA long-lived refresh token is used to get a new access token without re-authenticating
Best forUser-facing APIs, third-party integrations, SAP BTP service-to-service calls

💡 JWT in plain English

A JWT (JSON Web Token) is a Base64-encoded string with three parts: a header (algorithm), a payload (claims like user ID and roles), and a signature. The server does not need to look up a session — it verifies the signature and reads the claims directly from the token. This is why JWT-based APIs scale well.

What not to do

Bad practiceWhy it is a problem
Sending API keys as URL parametersURLs appear in server logs, browser history and referrer headers — the key gets exposed
Hardcoding credentials in source codeAnyone with repository access — including public GitHub repos — can read them
Using long-lived tokens with no expiryA stolen token works forever until manually revoked
No token validation on the serverTrusting the token blindly without checking signature, expiry and issuer

Authorisation — controlling what is allowed

Authentication confirms who you are. Authorisation decides what you can do. Both are required. A common mistake is implementing authentication well but leaving authorisation weak.

ConceptWhat it meansExample
AuthenticationYou are who you say you areToken verified — this is user 42
AuthorisationYou are allowed to do this specific thingUser 42 can read /orders/101 but not /orders/999
Broken authorisationAuth passes but object-level access is not checkedUser 42 changes the ID to /orders/999 and gets someone else’s data

⚠️ The most common API vulnerability

Broken Object Level Authorisation (BOLA) has been the number one API vulnerability on the OWASP list since 2019. It happens when an API returns data for any ID it receives without checking whether the requesting user owns or has access to that object. Always check access on the server side, for every request, every time.

Rate limiting — preventing abuse

Rate limiting restricts how many requests a client can make in a given time window. Without it, an API is vulnerable to brute-force attacks, credential stuffing, and resource exhaustion.

Rate limit typeWhat it controlsExample
Per API key / tokenRequests per minute or hour per client100 requests per minute per key
Per IP addressRequests from a single IPBlocks mass automated requests from one source
Per endpointRestricts specific sensitive endpoints more tightlyLogin endpoint: 5 attempts per minute
GlobalTotal requests across all clientsProtects infrastructure from DDoS

When a rate limit is hit, the API should return HTTP 429 Too Many Requests with a Retry-After header telling the client when to try again.

Rate limiting diagram showing multiple clients hitting an API gateway with some requests returning 200 OK and excess requests returning 429 Too Many Requests

Input validation — never trust what comes in

Every piece of data an API receives from outside must be treated as untrusted. Input validation is the process of checking that data is in the expected format, type, length, and range before processing it.

What to validateWhy it matters
Data typeExpecting a number, receiving a string with SQL — SQL injection attack
Field lengthExtremely long inputs can crash systems or overflow buffers
Allowed valuesA field expecting ‘active’ or ‘inactive’ should reject anything else
File uploadsFile type, size and content must all be validated — not just the extension
Nested objectsAttackers can inject unexpected fields to manipulate business logic (mass assignment)

💡 Validate on the server, always

Client-side validation (in a browser or app) is for user experience only. It can be bypassed by anyone with basic tools. The server must always validate inputs independently, regardless of what the client claims to have checked.

OWASP API Security Top 10 — 2023

OWASP (Open Web Application Security Project) publishes a list of the most critical API security vulnerabilities. The current version was published in 2023 and reflects how APIs are actually being attacked today.

OWASP API Security Top 10 2023 list showing all ten vulnerabilities from Broken Object Level Authorization to Unsafe Consumption of APIs

#VulnerabilityWhat it meansReal-world impact
1Broken Object Level AuthorisationAPI returns data for any ID without checking if the requester owns itAttacker reads or modifies another user’s data
2Broken AuthenticationWeak tokens, missing expiry, no brute-force protectionAccount takeover, unauthorised access
3Broken Object Property Level AuthorisationAPI exposes or allows modification of fields the user should not accessData leakage or privilege escalation
4Unrestricted Resource ConsumptionNo limits on request size, frequency or compute — allows resource exhaustionAPI becomes slow or unavailable (DoS)
5Broken Function Level AuthorisationAdmin or privileged endpoints accessible by regular usersUnauthorised actions, data deletion
6Unrestricted Access to Sensitive FlowsCritical workflows (password reset, OTP) have no abuse protectionAccount takeover, fraud
7Server-Side Request Forgery (SSRF)API fetches remote URLs from user input — attacker targets internal systemsAccess to internal infrastructure
8Security MisconfigurationOpen CORS, default passwords, debug mode on, missing headers, verbose errorsBroad attack surface, data exposure
9Improper Inventory ManagementOld API versions, undocumented endpoints and shadow APIs left runningUnpatched vulnerabilities exploited
10Unsafe Consumption of APIsTrusting data from third-party APIs without validation or sanitisationCompromise via supply chain attack

Source: OWASP API Security Top 10 2023

Security checklist for any API

Whether you are building a new API or reviewing an existing one, these are the things to check:

AreaCheck
TransportAll traffic uses HTTPS — no HTTP endpoints in production
AuthenticationEvery endpoint requires a valid token or key — no unauthenticated access to data
AuthorisationObject-level access is checked server-side on every request
Token handlingTokens are short-lived, signed, and validated on every call
Rate limitingLimits are in place, especially on auth endpoints
Input validationAll inputs validated for type, length and allowed values server-side
Error messagesErrors return useful messages to the client but no internal stack traces or system details
API inventoryAll API versions and endpoints are documented — old versions are retired, not just abandoned
SecretsNo API keys or credentials in source code, URLs or logs
DependenciesThird-party APIs and libraries are treated as untrusted — validated before use

API security in the SAP context

If you work with SAP systems, these same principles apply directly.

SAP scenarioSecurity principle in play
SAP BTP service-to-service callsOAuth 2.0 client credentials flow — short-lived tokens, no shared passwords
OData API calls from Fiori appsBearer token from the user’s session — authorisation checked via SAP roles
Integration Suite (CPI) flowsHTTPS for all connections, credential store for API keys and passwords
External API consumptionThird-party APIs treated as untrusted — validate responses before processing
API versioning in ODataV2 vs V4 are distinct paths — old versions must be explicitly managed

The essentials at a glance

ConceptOne-line summary
HTTPSAll API traffic must be encrypted in transit — non-negotiable
API KeysStatic credentials for server-to-server auth — rotate regularly, never expose in URLs or code
OAuth / BearerShort-lived tokens for delegated access — the standard for modern APIs
JWTSelf-contained token carrying identity and permissions — verify signature and expiry always
AuthenticationWho are you — verify identity on every request
AuthorisationWhat can you do — check object-level access server-side, every time
Rate LimitingHow much can you do — return 429 when limits are exceeded
Input ValidationNever trust incoming data — validate type, length and values server-side
OWASP Top 10The industry reference for API vulnerabilities — BOLA is #1 since 2019
API InventoryKnow what is running — old versions are attack surface

What to take away

API security is not a feature you add at the end of a project. It is a set of decisions you make from the start — in how you design endpoints, how you issue and validate tokens, how you restrict access, and how you handle input.

The good news: the principles are not complicated. Most API breaches come from well-known, avoidable mistakes — weak authentication, missing authorisation checks, no rate limiting. Getting the essentials right puts you ahead of most.

🔗 Related posts on this site

REST API Design Principleshow APIs are structured before security is applied. How HTTPS Works — the transport layer that all secure API calls depend on.

Published on rakeshnarayan.com — Articles

URL: https://rakeshnarayan.com/articles/api-security-essentials/