Skip to main content

Timing Attacks & Denial of Service

Fundamentals ยท Web Application Security ยท Reading time: ~8 min

This section's recurring theme โ€” differences in server behavior reveal information an attacker shouldn't have โ€” gets its purest expression here. No payload "does" anything visible; the vulnerability is entirely in how long or how expensive an operation turns out to be.


Timing Attacksโ€‹

If a comparison function returns as soon as it finds the first mismatched character, checking a secret against a guess takes microscopically longer the more leading characters the guess gets right.

Compare "secretABC" vs guess "a........." --> fails at character 1 (fast)
Compare "secretABC" vs guess "s........." --> fails at character 2 (slightly slower)
Compare "secretABC" vs guess "se........" --> fails at character 3 (slightly slower still)

By measuring response times across thousands of requests and statistically isolating the signal from network noise, an attacker can recover a secret one character at a time, without ever seeing the secret directly โ€” a technique that has been used in practice against API key comparisons, password checks, and HMAC signature validation that used a naive, non-constant-time == comparison.

Freshers' takeaway

This is the same "differential thinking" from the methodology page, taken to its logical extreme: instead of comparing response content, the attacker compares response time across thousands of samples. It requires statistics and patience rather than a clever payload โ€” which is exactly why it's easy to overlook during a quick manual test.


Regular Expression Denial of Service (ReDoS)โ€‹

Some regular expression patterns have catastrophic backtracking behavior โ€” for certain crafted inputs, the regex engine's runtime grows exponentially with input length instead of linearly.

Pattern: (a+)+$
Input: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!"

A pattern like this, applied to a long string that almost matches but ultimately fails, can force the regex engine to try an enormous number of ways to group the repeated characters before giving up โ€” turning a tiny, cheap-to-send input into a request that pegs a CPU core for seconds, minutes, or longer. If that regex runs on a request-handling thread, a handful of such requests can exhaust an entire server's capacity.

Attacker sends one small string (a few dozen bytes)
|
v
Vulnerable regex takes exponentially longer to evaluate as length grows
|
v
A single request consumes disproportionate CPU time
|
v
Enough concurrent requests exhaust server capacity for everyone

Application-Layer Denial of Serviceโ€‹

More broadly, any endpoint where a small, cheap-to-send request triggers a disproportionately expensive server-side operation is a potential DoS vector โ€” not just regex. Examples include:

  • An endpoint that generates a large PDF/report from a user-controlled parameter with no size limit.
  • A search feature that performs an expensive, unindexed database query directly from user input.
  • A "zip bomb" style upload โ€” a tiny compressed file that expands to gigabytes once decompressed, if the server processes it without a decompression size limit.
  • Recursive or deeply nested JSON/XML input that costs far more to parse than its byte size suggests (related to the "billion laughs" entity expansion mentioned on the XML page).

The underlying pattern is always an asymmetry: the attacker's cost to send the request is tiny compared to the defender's cost to process it.


How These All Get Fixedโ€‹

VulnerabilityPrimary Fix
Timing attacksUse constant-time comparison functions for secrets (most languages provide one specifically for this, e.g. crypto.timingSafeEqual or equivalent) instead of a standard ==/.equals().
ReDoSAvoid regex patterns with nested, ambiguous repetition; use regex engines or libraries with built-in backtracking limits; set execution timeouts on any regex evaluating untrusted input.
Application-layer DoSEnforce size/complexity limits on anything derived from user input โ€” request bodies, decompressed archive size, query complexity, recursion depth โ€” before expensive processing begins.
General resilienceRate limiting, request timeouts, and resource quotas per request limit how much damage any single asymmetric request can do, even if a specific bug slips through.

Key Takeawaysโ€‹

  • Timing attacks extract secrets through statistical analysis of response latency, not response content โ€” constant-time comparisons are the fix.
  • ReDoS exploits catastrophic backtracking in poorly written regex patterns, turning a tiny input into a CPU-exhausting one.
  • Application-layer DoS generalizes the same idea: look for any place a cheap request triggers an expensive operation.
  • Resource limits (size, recursion depth, timeouts) are the universal defense across this entire category.

Nextโ€‹

The final page in this section rounds up the remaining, smaller-but-still-common bug classes that don't neatly fit the categories above: Misc & Emerging Web Attacks.