On this page

Summary

I love finding web application firewall (WAF) misconfigurations. Some are simple to exploit and can lead to serious bugs. For me, they offer the best return for the time spent.

A big part of hunting these is thinking like the developer. Say you found a really simple issue in an application and it gets patched. Developers sometimes make the mistake of putting a WAF in front of it as a band-aid, failing to fix the root cause. That makes it worth checking whether the fix covers other ways to reach the same bug.

These are 3 of my favourite techniques because they're so simple.

  1. Adding a ton of spaces
  2. Path normalisation
  3. Visiting the IP directly

WAFs and Limitations

Before getting into the bypasses, it helps to understand where a WAF sits between you and the application.

When your browser asks for a page, the first server it talks to might be a reverse proxy. This proxy is responsible for receiving your request on behalf of the site and forwarding it to the app. A WAF can run on that same proxy, or it could be another hop. It looks at parts of the request, such as the host, path and headers, and checks them against its rules.

Reverse proxy / WAF in action

Rules can be configured in various ways, such as to block certain paths or only allow certain HTTP headers when accessing a site. It also can be configured to check the body of the request, blocking payloads like the <script> tag. I've sadly lost to WAFs multiple times, having to downgrade a potential XSS to a Low impact HTML Injection.

When a WAF blocks a request, it never reaches the application. On a retest, a blocked payload alone cannot tell you whether the underlying bug was fixed.

WAFs are a form of defence-in-depth. If a WAF rule is the only fix, the underlying bug is still there!

Adding Tons of Spaces

Some WAFs inspect only the beginning of a request body. If oversized requests are allowed through, a payload beyond the inspection limit may reach the application unchecked. AWS WAF documents how its inspection limits and oversize policies work for cases like these.

To better explain my point, I'll use an example of an application endpoint that receives and processes XML. This application accepts a message variable:

<document>
  <message>Hello</message>
</document>

Seeing XML being dynamically processed makes XML external entity (XXE) the obvious vector to test. Triggering an out-of-band interaction is one way to test if XXE works:

<!DOCTYPE document [
  <!ENTITY demo SYSTEM
    "https://example.test/demo.txt">
]>
<document>
  <message>&demo;</message>
</document>

Suppose the WAF blocks this payload and returns 403 Forbidden. Further testing shows that certain combinations of characters like <, ! and SYSTEM trigger the WAF rule.

To bypass the WAF, one could add around 200,000 bytes of whitespace to the XML body before the entity declaration like so:

<!DOCTYPE document [
    <!-- Insert 200,000 bytes of whitespace here -->
  <!ENTITY demo SYSTEM
    "https://example.test/demo.txt">
]>
<document>
  <message>&demo;</message>
</document>

Padding only helps if the part the WAF inspects still passes its rules. If the WAF allows the oversized body through, the entity declaration can sit beyond its inspection limit. The XML parser still receives the full body. A request to a URL you control would confirm that the parser resolved the external entity.

Path Normalisation

Another simple bypass comes from the WAF and application reading the same URL differently. The WAF might check the path exactly as it arrived, while the application cleans it up before deciding which page to serve.

An Extra Slash

Suppose /content/internal exposes internal content without checking who's requesting it, and this was previously reported by a bug bounty hunter. The developers added a WAF rule to block that exact path, making the original PoC fail, then closing the issue as "Resolved". However, this fix is not robust enough.

Blocking /content/internal exactly is flawed, because an attacker can just add a / and request /content//internal. The extra slash means the path no longer matches the rule. If the backend merges repeated slashes, it turns the request back into /content/internal and serves the same page.

Adding an extra slash gets through

This works when slash merging happens after the WAF's check. For example, nginx's merge_slashes setting is enabled by default when matching requests to locations. A WAF earlier in the request flow could see two slashes, while nginx routes the request using one.

Apart from using an extra slash, the attacker can also use path traversal sequences to achieve the same result. On some applications I've tested, one or two ../ segments got past the WAF, while adding more returned 403 Forbidden.

An attacker could send requests to /test/../content/internal and get past the exact match rule too. The client needs to send the path unchanged. Curl normally removes the ../ segments, so use --path-as-is when testing this with curl.

The path parameter

A semicolon can cause a similar disagreement. Some frameworks use it to attach parameters to a path segment, as described in RFC 3986 section 3.3. An attacker can try /content/internal;c=1 against the same rule.

The WAF may treat the whole thing as the path, so it misses the rule for /content/internal. The application can read /content/internal as the route and handle c=1 separately as a path parameter.

In the diagram below, suppose the application also converts the path parameter into a query parameter, rewriting the request to /content/internal?c=1. That conversion depends on the app.

An extra path parameter gets through the WAF's rule

Either way, if the request reaches /content/internal and returns the protected content, the original issue is still there. The extra characters only changed which request the WAF recognised.

Visiting the IP directly

The next trick is to change how the request reaches the app. Suppose a request to /content/internal on app.example.test gets blocked by the WAF, and none of the path changes work. Requesting the same path through the site's IP address might still return the content.

An IP request can reach the application server itself

If the IP request reaches the same proxy, its Host header contains the IP instead of the usual hostname. When that value doesn't match a configured site, nginx can route the request to its default server. If that server forwards requests to the same application without the hostname's WAF rules, the blocked page becomes accessible again.

Alternatively, the IP may belong to the application server itself. If it accepts connections from the internet, the request reaches the application without passing through the proxy or its WAF.

Fixes

Enforce authorisation in the application on every request, and disable external entity resolution in the XML parser.

The WAF and application must agree on how paths are resolved and normalised, as attackers can exploit these desyncs to access internal content. Reject requests whose bodies exceed the WAF's inspection limit. Lastly, if the application is meant to sit behind a proxy, restricting access to the origin server is important too.

A WAF rule can buy time. The underlying bug still needs a proper fix.

References