API Architectures & Attack Surface
API Security Fundamentals · API Security track
5 min read
In this module
What Makes APIs Different
Every modern application rides on APIs. Tap a button in a mobile app, fill in a web form, pair a smart device — somewhere behind the scenes an API call is humming away. Where a traditional web app has a server render HTML for your browser, an API just hands you the raw data and functionality. That directness is the whole point. It's also the whole problem.
An API is a contract. The client sends a structured request, the server processes it, a structured response comes back. Each API architecture writes that contract its own way, and each brings its own attack surface.
REST: The Dominant Architecture
REST (Representational State Transfer) is the most widely deployed API style by a country mile. It uses ordinary HTTP methods — GET, POST, PUT, DELETE — to operate on resources identified by URLs.
GET /api/v1/users/1842 HTTP/1.1Host: app.example.comAuthorization: Bearer eyJhbGciOiJSUzI1NiIs...Accept: application/jsonREST APIs are stateless by design. Each request carries everything the server needs to process it, which from a security angle means authentication tokens ride along on every single request.
Attack surface highlights: predictable URL patterns make enumeration trivial, HTTP verbs can be swapped to probe access controls, and responses routinely hand back more data than the client actually asked for.
GraphQL: A Single Endpoint, Infinite Queries
GraphQL collapses REST's many endpoints down to one. Clients send a query describing exactly the data they want, and the server returns that shape and nothing more.
query { user(id: "1842") { email role orders { total paymentMethod { lastFour } } }}That flexibility cuts both ways. Most GraphQL implementations leave introspection enabled by default, which means an attacker can query the full schema and map every type, field, and relationship in a single afternoon. Query batching slips multiple queries through one HTTP request, gleefully bypassing request-based rate limiting. And deeply nested queries can spiral into exponential database lookups, taking the service down with them.
gRPC: Speed at the Cost of Visibility
gRPC uses Protocol Buffers (protobuf) over HTTP/2 for high-performance service-to-service communication. Messages get serialised into a compact binary format instead of human-readable JSON.
service UserService { rpc GetUser (UserRequest) returns (UserResponse); rpc ListUsers (ListRequest) returns (stream UserResponse);}The binary format makes traditional WAF inspection a real headache. Security tools built around JSON or XML can't make sense of a protobuf payload without the schema definition. When the gRPC reflection service is enabled, it offers runtime service discovery — handy for clients, also a free map for attackers. Mutual TLS (mTLS) is recommended for service-to-service authentication, but nothing enforces it by default.
WebSockets: Persistent, Bidirectional Channels
WebSockets upgrade an HTTP connection into a persistent, full-duplex channel. After the handshake completes, messages flow in both directions without the cost of repeated HTTP requests.
GET /ws/chat HTTP/1.1Host: app.example.comUpgrade: websocketConnection: UpgradeOrigin: https://app.example.comWebSockets have no built-in authentication mechanism. Authentication must happen during the initial HTTP handshake or within application-level messages. Once the connection is open, there is no standard way to verify that subsequent messages are from the original authenticated user.
Cross-Site WebSocket Hijacking (CSWSH) shows up when the server doesn't validate the Origin header during the handshake. An attacker's page opens a WebSocket to the vulnerable server, and the browser obligingly attaches the victim's cookies. Per-message rate limiting matters here too, because WebSocket traffic sails right past HTTP-layer rate limiters.
SOAP: The Legacy Protocol
SOAP (Simple Object Access Protocol) wraps requests in XML envelopes and leans on WSDL files to describe available operations. New applications have largely moved on to REST and GraphQL, but SOAP is still alive and well inside enterprise and financial systems. The XML-heavy structure carries its own baggage: XML External Entity (XXE) injection and SOAP action spoofing both come with the territory.
Comparing the Attack Surface
Each tab below fetches the same user, 1842, from a different kind of API. Watch how one logical operation takes on completely different shapes. For each, find where the credential travels, then ask what a gateway counting requests per URL would actually be counting.
One user lookup, four architectures
A resource URL and a verb. The ID sits in the path.
Headers
{
"id": "1842",
"email": "alice@example.com",
"role": "user"
}Where controls apply
Each operation has its own method and URL, so a gateway can authenticate, rate-limit and log per route. What it can't check is ownership: whether this token's user has any business reading user 1842. That check belongs in the handler.
Why Architecture Matters for Security
Each architecture pushes the attack surface in a different direction. REST's predictability turns enumeration into a Sunday stroll. GraphQL's flexibility lets attackers cook up queries the developers never imagined. gRPC's binary format blinds the traditional security tooling that surrounds it. WebSockets snap the request-response model that most security controls quietly assume.
These architectural differences are the foundation of API security testing. Before you can find vulnerabilities, you have to understand how the target API is put together, what assumptions it makes, and where those assumptions buckle under pressure.