HTTP and API Security Interview Questions: Practice Quiz

Reviewed by Mark Dickie · Last updated

6 questions on this page you can answer and see marked on the spot. Go to the first one

API security is the set of checks that stop an unauthorized caller from reading or changing data through an HTTP endpoint. Interviewers start with authentication and authorization, then move to token handling, input validation, and rate limiting. Most candidates lose points by mixing up authentication (who is calling) with authorization (what that caller may touch), so be ready to show the difference with a concrete request.

Which API security topics come up in interviews?

TopicWhat to be able to explainConcrete failure to name
OAuth 2.0 with PKCEWhy a public client sends a code verifier with the authorization codeAn intercepted code redeemed by a malicious app
JWT validationChecking the signature, alg, exp, aud and iss before trusting any claimAccepting alg set to none, or skipping the audience check
Broken object-level authorization (BOLA)Checking ownership on every object ID, not only that the user is logged inGET /orders/8812 returns another customer's order
CORSPreflight OPTIONS requests, and why credentials cannot pair with a wildcard originReflecting any Origin header with Access-Control-Allow-Credentials set to true
Rate limitingPer-client limits and the 429 response with Retry-AfterCredential stuffing against /login with no throttle

How should you practise these before the interview?

  1. Capture the request your browser sends after login, then name the header that carries the token and where the server should reject it.
  2. Take one endpoint from any sample API, swap in another user's resource ID, and note whether the server returns 403 or 200.
  3. Decode a JWT by hand, change the alg header, and check whether your validator still accepts the token.

The quiz below draws on the same topics.

Key facts

  • Tarmac has 30 HTTP & APIs interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 2,497 job postings asking for HTTP & APIs in November 2026.
  • Roles asking for HTTP & APIs advertise a median base salary of £75,000, across 489 job postings as of November 2026.
  • Tarmac last reviewed these HTTP & APIs interview questions on 16 November 2026.

At a glance

Questions10 shown · 30 in the bank
Difficulty1–5 of 5
FormatsTrue / false, Multiple choice, Fill in the blank, Flashcard, Multiple answer, Short answer, Code output, Ordering, Find the bug

What you'll review

  1. rate limiting
  2. cors

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

Rate limiting protects an API only from malicious (intentional) abuse and provides no benefit against accidental denial-of-service caused by buggy clients.#

Options

Show answer

This is false. Rate limiting protects an API from both malicious abuse and accidental overloads. A buggy client caught in an infinite retry loop can cause the same denial-of-service effect as a deliberate attack. By capping request rates for all callers, rate limiting preserves API availability no matter the cause of excessive traffic.

Why:

Rate limiting is effective against both intentional attacks (e.g., DDoS, credential stuffing) AND accidental overloads (e.g., a buggy client stuck in an infinite retry loop). By capping request rates for any caller, the API remains available regardless of whether excessive traffic is deliberate or unintentional.

A client sends too many requests to a REST API and the server enforces rate limiting. Which HTTP status code should the server return to indicate the client has exceeded its rate limit?#

Options

Show answer

The correct status code is 429 Too Many Requests (defined in RFC 6585). This code specifically signals that the client has exceeded the server's rate limit. It is often paired with a Retry-After header so the client knows when it may resume sending requests. Codes like 503 indicate server-side unavailability, not a client-side quota breach.

Why:

HTTP 429 Too Many Requests is the standard status code (defined in RFC 6585) used when a client has sent more requests than the server's rate limit allows. 400 signals a malformed request, 401 signals missing/invalid authentication, and 503 signals that the server itself is temporarily unavailable — none of these correctly convey rate-limiting semantics. Servers typically also include a Retry-After header alongside 429 to tell clients when they may try again.

Rate limiting can be implemented using different algorithms. The _____ algorithm maintains a counter per fixed time window and resets it when the window expires, while the _____ algorithm smooths out request bursts by processing requests at a constant outgoing rate.#

Show answer

Rate limiting can be implemented using different algorithms. The fixed window algorithm maintains a counter per fixed time window and resets it when the window expires, while the leaky bucket algorithm smooths out request bursts by processing requests at a constant outgoing rate.

Why:

The fixed window algorithm divides time into fixed intervals (e.g., every 60 seconds), keeps a request counter per window, and rejects requests once the counter exceeds the limit. It is simple but can allow burst traffic at window boundaries. The leaky bucket algorithm queues incoming requests and drains them at a steady rate, effectively smoothing out bursts and enforcing a consistent throughput. Other common algorithms include the sliding window log, sliding window counter, and token bucket.

What does the Access-Control-Allow-Origin response header control in CORS?#

Show answer

It tells the browser which origin may read the response to a cross-origin request. The browser compares the page's origin to the header value (where * means any origin is allowed). If the origin is not permitted, the browser blocks the script from accessing the response. For simple requests the request still reaches the server; for non-simple requests the browser first sends a preflight OPTIONS request and withholds the actual request if the origin is not allowed. CORS is a browser-enforced mechanism, not server-side authentication.

Why:

CORS is enforced by the browser, not by the server. The Access-Control-Allow-Origin header tells the browser which requesting origin may access the response; when the origin is not permitted the browser blocks the response from the script. For simple cross-origin requests the server still receives and processes the request, but for non-simple requests the browser sends a preflight OPTIONS request first — if that preflight response does not allow the origin, the actual request is never sent. This is why CORS is not a substitute for server-side access control and does not protect endpoints from direct calls such as curl.

An API gateway applies rate limiting to protect backend services. Which of the following HTTP response headers are standard or widely-accepted conventions for communicating rate-limit information to clients?#

Options

Pick every one that applies.

Show answer

The standard/widely-accepted rate-limit response headers are X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, and Retry-After. The first three are the de-facto industry convention (used by GitHub, Stripe, etc.) for exposing quota details, while Retry-After is an official IETF header (RFC 9110) paired with 429 Too Many Requests to tell clients when they may retry. X-Throttle-Queue-Depth is not a recognised standard.

Why:

X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset are the de-facto industry standard headers (used by GitHub, Twitter/X, Stripe, etc.) for conveying the rate-limit quota, remaining calls, and window-reset time respectively. Retry-After is an official IETF header (RFC 7231 / 9110) returned with 429 Too Many Requests to tell clients when to retry. X-Throttle-Queue-Depth is not a recognised standard or widely-adopted convention — it was a distractor.

A distributed API gateway runs on 10 identical nodes behind a load balancer. A rate limit of 100 requests per minute per user is enforced with a local in-memory counter on each node. The load balancer spreads each user's requests across all 10 nodes (no sticky sessions or user-based hashing).#

Show answer

Each node keeps its own independent counter, and the counters are never shared, so a user whose requests are spread across all 10 nodes can make up to 100 requests per minute to each node. The effective global limit becomes about 1,000 requests per minute instead of 100. A fix is a centralised shared store such as Redis, where every node updates one counter per user atomically (for example, INCR with its expiry set inside a Lua script), or a token-bucket or sliding-window algorithm whose state lives in that shared store.

Why:

With a local counter on each node and the load balancer spreading one user's requests across all 10 nodes, each node admits up to 100 requests on its own, so the effective limit becomes roughly 10 times the intended 100 per minute. The root flaw is that no node can see the requests another node has already admitted. The fix is to move the count into shared state that all nodes read and update together, such as Redis, and to make the update atomic: INCR and EXPIRE are separate commands, so they must be combined in a Lua script or transaction to avoid a crash leaving a key without a TTL. Sticky routing or hashing by user would also make local counters accurate, but the prompt fixes the routing as spread, so a shared store is the required approach.

A high-traffic public REST API is experiencing abuse from scrapers and is being rate-limited at the gateway. Which of the following strategies are correct and effective approaches to enforce rate limiting in a distributed, multi-instance deployment?#

Options

Pick every one that applies.

Show answer

The correct strategies are: shared Redis INCR with TTL for fixed-window counting, atomic Lua-script token buckets on Redis, and sliding-window logs using Redis sorted sets. All three coordinate state across distributed instances and avoid race conditions. Local in-memory counters with gossip allow over-serving, and IP-only limiting is easily defeated by IP rotation.

Why:

Shared Redis INCR with TTL, atomic Lua-script token buckets on Redis, and sliding-window logs using Redis sorted sets are correct. A shared Redis instance ensures all gateway nodes see the same counter state. Using INCR with TTL provides a simple fixed-window counter without race conditions. A Lua script on Redis executes atomically, making token bucket check-and-decrement safe. Sliding window logs with sorted sets give high-accuracy limiting. Local in-memory counters with lazy gossip is incorrect because it allows significant over-serving before corrections propagate. IP-based limiting is incorrect as a long-term strategy because it is trivially bypassed by rotating IPs, and shared IPs (NAT, CDN egress) unfairly throttle legitimate users.

A Node.js API gateway uses the following sliding-window rate-limiter logic. Given that the current Unix timestamp is 1000 seconds and the client has prior request timestamps of [994, 996, 998, 999] stored in a sorted set, what does the function log when a new request arrives at t = 1000 with a 5-second window and a limit of 4 requests?#

function checkRateLimit(timestamps, now, windowSecs, limit) {
  const windowStart = now - windowSecs; // 1000 - 5 = 995
  const recent = timestamps.filter(t => t > windowStart);

  if (recent.length >= limit) {
    const retryAfter = windowSecs - (now - recent[0]);
    console.log(`429 Too Many Requests. Retry-After: ${retryAfter}s`);
  } else {
    recent.push(now);
    console.log(`200 OK. Requests in window: ${recent.length}`);
  }
}

checkRateLimit([994, 996, 998, 999], 1000, 5, 4);

Options

Show answer
200 OK. Requests in window: 4
Why:

windowStart = now - windowSecs = 1000 - 5 = 995. The filter t > 995 (strictly greater than) drops 994 (which equals 995 − 1, not strictly greater) and keeps [996, 998, 999] — that is 3 entries. Since 3 < 4 (the limit), the if branch is not taken; the else branch runs, pushes 1000 onto recent making its length 4, and logs 200 OK. Requests in window: 4. The output 429 Too Many Requests. Retry-After: 1s would be the output only if all four prior timestamps were in-window (i.e., recent.length >= 4 before the push), but that is not the case here because 994 is excluded by the strict > comparison.

A page at https://app.example.com runs fetch('https://api.example.com/items/42', { method: 'PUT', headers: { 'Authorization': 'Bearer t', 'Content-Type': 'application/json' }, body: '{}' }). Put the browser's CORS-related steps in the order they occur, from first to last, for a cross-origin request that the server correctly permits.#

Put these in order

Show answer

The CORS sequence for a non-simple cross-origin request starts with the script's fetch call, which triggers a preflight OPTIONS request. The server's preflight approval is validated and cached before the browser sends the real request. Finally, the browser checks the actual response's Access-Control-Allow-Origin header before exposing it to JavaScript.

Why:

The browser first classifies the call: a PUT with an Authorization header and a JSON content type is not a simple request, so the fetch triggers a preflight. The preflight OPTIONS (carrying Origin, Access-Control-Request-Method and Access-Control-Request-Headers) must be sent before anything else. The server replies with the allow-origin, allow-methods, and allow-headers grants, plus max-age. The browser then validates that reply against the origin, method and headers and caches it; only after approval does it send the actual PUT, which carries Origin. Last, the browser checks the actual response's Access-Control-Allow-Origin before handing the body to script. Each step depends on the previous one, so the order is a strict total order.

A browser client calls this API with fetch(url, { credentials: 'include' }) and needs to read the response. The middleware is meant to allow credentialed cross-origin requests from any origin. Which line is the bug? Give the 1-based line number.#

function cors(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Credentials', 'true');
  if (req.method === 'OPTIONS') {
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
    return res.end();
  }
  next();
}
Show answer

The bug is on line 2.

Why:

Line 2 sets Access-Control-Allow-Origin to the wildcard *. When a request is sent with credentials: 'include', the browser rejects any response whose Access-Control-Allow-Origin is *, regardless of Access-Control-Allow-Credentials. The server must echo the specific, validated request origin (and add Vary: Origin) instead. Line 3 is correct on its own, since Access-Control-Allow-Credentials: true is required for credentialed requests, and the preflight handling on lines 4 to 6 is not what breaks the request.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See http-apis salaries and hiring demand from live job postings.

The other 20 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 20 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.