WAF vs API gateway: routing is not filtering

An API gateway and a web application firewall both sit in front of an application and both can refuse a request, so they are compared as if one could stand in for the other. They cannot. A gateway organises API traffic: which service, which caller, how often. A web application firewall judges what one request contains. Neither fixes the code behind them.

Section Comparisons Updated Questions two tools

Quick facts

API gatewayWeb application firewall
What it isA reverse proxy that routes requests to APIs, load balances and applies per-route policy (Kong Gateway docs)A filter that judges each HTTP request against rules before the application handles it
Knows aboutRoutes, consumers, API keys, upstream servicesMethod, path, headers, body, and the pattern across requests
Typical policyAuthentication, rate limiting by key or IP, routing, header changes (NGINX reverse proxy guide)Refuse requests the application should never handle
Does not doJudge whether a well-formed request is hostile; decide whether this user may see this recordRoute, authenticate consumers, or fix an authorisation check in code
Rate limitingNative; limit_req in NGINX uses the leaky bucket method (NGINX docs)Limits applied per domain, alongside the filter

This page describes two classes of tool using the documentation of open gateways such as Kong and NGINX, and the OWASP API Security Top 10 (2023). It does not rank products. The short version: a gateway is where API traffic is organised; a WAF is where individual requests are judged. Sites with an API often want the first and sometimes the second, and neither is a stand-in for the other.

What an API gateway is for

Kong describes its gateway as a reverse proxy that manages, configures and routes requests to your APIs, with load balancing across upstream services, a library of authentication plugins and rate limiting by IP address, API key or consumer. NGINX, used as a gateway, does the forwarding with proxy_pass and can change the headers it passes on with proxy_set_header. Both descriptions come from the vendors' own documentation, linked above, and they agree on the shape of the job.

That job is organisational. Many services sit behind one address; the gateway decides which service a path belongs to, whether the caller presented a credential, and how often that caller may come back. It is a reverse proxy with a policy layer, and it is the natural home for anything that is a property of a route or a consumer rather than of the bytes in one request.

Notice what is missing from that list. A gateway checks that a key is valid. It does not, by itself, know whether the holder of that key may read the record named in the URL. That question belongs to the application, and the next section is about why it matters.

What the OWASP API list asks of each

The 2023 list is useful here because it names the code-level and the traffic-level problems separately, and the split maps onto the two tools unevenly.

Authorisation problems live in the application. API1:2023 Broken Object Level Authorization says every endpoint that receives an object ID and acts on the object should perform an object-level authorisation check, and that comparing the session user's ID with the ID parameter is not a sufficient solution. A gateway has the key and the route; it does not have the record. A WAF has the request, and a request for object 1041 from a valid user looks the same as a request for object 1042. See IDOR for what this looks like from the outside, and endpoint security for the checks that stay in code.

Resource consumption is where the gateway earns its place. API4:2023 Unrestricted Resource Consumption recommends limiting how often a client can interact with the API in a defined period, enforcing maximum sizes for incoming data, and tuning limits to business needs, with stricter policies for some endpoints. Per-key and per-route limits are exactly the vocabulary of a gateway. How to pick the key is covered in rate limiting by IP, user or key.

The remaining items, authentication, property-level and function-level authorisation, inventory, sit across both tools and the code. The full list with notes is on the API security page; none of it is solved by placing any single box in front of the application.

Where they overlap

Both sit in front of the application, both can refuse a request, and both can limit rate. That is the whole overlap, and it is why the comparison comes up.

The refusals differ in reason. A gateway refuses because of who is asking or how often: no key, wrong key, over quota. A WAF refuses because of what is being asked: a request carrying something the application should never receive, whoever sent it. A caller with a perfectly valid key can still send a request a WAF would flag, and a harmless anonymous request can still be refused by a gateway because the route needs a credential.

Rate limiting is shared ground rather than a clash. A per-consumer quota is a gateway concern because the gateway knows the consumer. A limit on an anonymous form or a login path, where there is no consumer yet, is closer to filtering. Where both exist, count and refuse in one place and keep the other as a backstop; two limits tuned independently produce confusing 429 responses that nobody can attribute. The general mechanics are in rate limiting.

Where a WAF helps and where it does not

A WAF sees every request in full: method, path, headers, body, and how that request sits among the others from the same source. It does not see the database, the user's permissions or the intent of the caller. What follows is limited to that view.

  • It helps with requests the API never needs to handle. Malformed input, injection-shaped parameters, probing for paths that do not exist. A gateway passes these along to the service if the key is valid.
  • It helps where there is no consumer to key on. Public endpoints, sign-up and login forms, anything reachable without a credential.
  • It does not fix authorisation. A request that is valid in every visible respect and wrong only because of whose record it names passes through a WAF, as it does through a gateway. The repair is in the code.
  • It does not understand your business rules. An abuse that consists of ordinary calls in an unwanted order is a business logic problem, invisible to a filter that judges requests one at a time.
  • It does not replace the gateway. Bridge WAF is a request filter with three modes; it does not route to services or manage consumers and keys, and it is not presented as a substitute for a gateway.

The three modes are off, monitor and block. Start in monitor: the filter records what it would refuse and refuses nothing, so a legitimate client that happens to resemble an attack shows up in the log before it shows up as a support ticket. Move to block when the log is quiet for the traffic you care about. The procedure is in WAF monitor mode. For API clients this matters more than for browsers, because an integration that gets refused rarely reports it politely; it just stops working.

Which to reach for

  • Many services behind one address, callers with keys. You want a gateway first. Routing, authentication and quotas are its job.
  • A single application with a public API and a form-heavy front end. A request filter may be the first thing you need; a gateway can come when the number of services grows.
  • Both exist. Put the filter in front, so refused requests never reach gateway counters, and let the gateway handle identity. Order matters less than knowing which layer owns which decision.
  • The problem is an object ID that can be changed. Neither. Fix the check in code, then use either tool to make probing noisier.

Offerings that bundle the filter with bot and API defences are weighed against it in WAF vs WAAP, and the other pairs are collected under comparisons. Bridge WAF is the filtering layer of Bridge CDN.

Questions

Is a WAF the same as an API gateway?

No. An API gateway is a reverse proxy that routes requests to APIs and applies policy such as authentication and rate limiting per route or consumer. A WAF judges the content of each request against rules. They can sit in the same path, but they answer different questions.

Can an API gateway replace a WAF?

Not as a general rule. A gateway checks credentials and quotas; it does not usually judge whether a request from a valid caller carries something the application should never receive. Some gateways accept plugins that add filtering, which is a separate capability worth checking in that product's documentation.

Does a WAF fix broken object level authorization?

No. OWASP says every endpoint that acts on an object ID should perform an object-level authorisation check. A request naming someone else's record looks like any other valid request, so the fix belongs in the application code.

Where should rate limiting live: gateway or WAF?

Per-consumer quotas belong at the gateway, which knows the consumer. Limits on anonymous paths such as login and sign-up forms fit a request filter. If both exist, avoid two independently tuned limits on the same route, since the resulting 429 responses are hard to attribute.

Should I start a WAF in block mode in front of an API?

Start in monitor mode. The filter records what it would refuse without refusing anything, so an integration that resembles an attack shows up in the log first. Switch to block once the log is quiet for the traffic you care about.