Web Application Firewall Explained: Stopping SQLi, XSS, and Bots

An engineering breakdown of the Web Application Firewall: how it inspects HTTP traffic to stop SQL injection, XSS, and bots before they reach your app, and how it differs from a network firewall.
What Is a Web Application Firewall (WAF)?
A Web Application Firewall (WAF) is a security layer that sits between the user and your application, inspecting every HTTP and HTTPS request before it reaches the server and blocking malicious traffic that tries to exploit flaws in your code. Unlike a network firewall that only examines IP addresses and ports, a WAF understands the content of the request itself: the path, the HTTP headers, the cookies, the form fields, and the request body. That application-level understanding is exactly what lets it tell the difference between a normal login request and one carrying a SQL injection payload.
This is not a luxury. According to OWASP, injection flaws have stayed among the top ten web vulnerabilities for more than twenty years running, and industry reports attribute roughly 43% of data breaches to attacks aimed directly at web applications. A malicious request does not need an unusual open port, it enters through the very same port 443 that serves your site, wrapped as a legitimate HTTPS request. A network firewall waves it through because it never reads what is inside, while a WAF opens it up and analyzes its intent.
At Cloud, this layer sits in front of managed hosting and virtual servers inside our Riyadh data centers, so a request is inspected and either passed or blocked in under a millisecond of added latency, on top of a baseline round trip of around 8ms from inside the Kingdom versus 100 to 120ms for foreign servers. Security inspection does not mean noticeable slowness, because it happens locally and close to the Saudi user.
How a WAF Works Under the Hood
A WAF runs as a reverse proxy or as a module inside the web server, such as ModSecurity on Apache or Nginx. It receives the request, unwraps it, applies a rule set, and then decides: pass, block, log, or challenge. That decision is built on two core models that usually work together.
The Negative Model (Blocklist)
This relies on known attack signatures and patterns. The OWASP Core Rule Set ships with more than 200 rules covering SQL injection, XSS, command injection, and path traversal. Any request that matches a malicious pattern gets blocked. Its strength is speed and clarity, its weakness is that it only chases attacks it already knows.
The Positive Model (Allowlist)
This defines the allowed shape of a request: which fields each path accepts, their lengths, and their data types. Anything outside that shape is rejected even if it matches no known attack signature. This model defends against zero-day attacks because it permits the known-safe instead of chasing the unknown-malicious, but it demands careful tuning per application.
Modern systems add a cumulative risk-scoring layer: each rule a request violates adds points, and once the total crosses a threshold the request is blocked. This reduces false positives, since one minor violation may not be enough to block while a buildup of several suspicious signals is. Studies point to false positives as the number one reason security teams disabled their own firewalls, which is why threshold tuning became essential.
How a WAF Stops SQL Injection
SQL injection (SQLi) happens when an attacker inserts code into an input field so it becomes part of a database query. A classic example targets a username field to bypass authentication. The impact is devastating: a full database leak, deletion, or privilege escalation. Despite its age, SQLi remains among the three most frequent vulnerability classes in OWASP data, and it has been on the list since 2003.
A WAF detects it through several signals combined:
- Query keywords such as UNION, SELECT, and DROP appearing where free text input is not expected.
- Suspicious characters and sequences such as stray single quotes, comment markers, and semicolons inside form values.
- Evasion attempts through encoding, such as double URL encoding or converting characters to their hexadecimal form to slip past filters.
Crucially, a WAF decodes and normalizes the request before inspection, so it sees the payload in its true form rather than its disguised one. Still, a WAF is a second line of defense, not a replacement for parameterized queries in the code itself. Combining both is the correct practice.
How a WAF Stops XSS Attacks
Cross-site scripting (XSS) injects JavaScript code into a page that other users view, stealing their sessions, redirecting them, or planting malicious content. XSS remains one of the most widespread vulnerabilities and shows up in a large share of applications tested each year, since a single unsanitized input point is enough to exploit it.
A WAF catches XSS patterns by looking for suspicious script tags, event handlers injected into attributes, and attempts to call sensitive functions inside values that should be plain text. When it normalizes the request, it exposes variants disguised by encoding or by changing letter case. Like SQLi, full protection requires output encoding in the application, while the WAF provides a safety net that repels automated waves and known attempts before they reach the code.
How a WAF Handles Bots
Not all automated traffic is malicious, but industry reports estimate that nearly half of all global internet traffic is automated, and that roughly a third of it is bad bots scanning for vulnerabilities, testing passwords, and scraping content. A WAF distinguishes bad bots through several methods:
- Rate limiting: blocking or slowing a source sending requests at a rate far beyond human speed, such as hundreds of attempts per second against a login page.
- Fingerprint analysis: examining the order of HTTP headers, the User-Agent value, and session behavior to catch automated tools impersonating a browser.
- Challenges: presenting a lightweight challenge such as a JavaScript check or CAPTCHA when a source is suspect, which humans pass and simple automation fails.
- Reputation lists: blocking IP addresses known as attack sources or botnets.
This mitigates credential-stuffing attacks that rely on trying millions of leaked username and password pairs, and it reduces the scraping load that drains server resources for no return.
WAF Versus Network Firewall
Confusing the two is common, but they operate at different layers of the OSI model. A network firewall works at layers three and four (IP and ports), while a WAF works at layer seven (the application).
The Network Firewall
It decides based on source and destination address, port, and protocol. It asks: is this connection allowed at all? It blocks a closed port or a banned IP range, but it has no idea what is inside a legitimate HTTPS packet arriving on port 443. To it, a normal login request and one carrying SQL injection are completely identical.
The Web Application Firewall
It reads request content at the HTTP level. It asks: what is this allowed request actually doing? It distinguishes a malicious payload inside a legitimate field on a legitimate port. That is why neither replaces the other, they complement each other within a defense-in-depth model. The network controls who enters, and the application controls what is done after entry.
A simplified comparison:
- Layer: network at 3 and 4, application at 7.
- Unit inspected: the network examines packets and ports, the application examines full HTTP requests.
- Stops: the network stops unauthorized access and scanning, the application stops SQLi, XSS, and bots.
- Blind to: the network is blind to request content, the application is blind to connections outside the web scope.
WAF on Saudi Infrastructure
Where the inspection happens matters a great deal. When a WAF sits inside a Saudi data center, the inspected request data stays within the Kingdom, which is what the National Cybersecurity Authority (NCA) controls and National Access policies for government entities require. Inspection outside the Kingdom means routing every request through foreign infrastructure, which pushes latency above 100ms and raises data sovereignty questions.
At Cloud, the WAF layer runs in front of hosting and virtual servers inside Riyadh, with automatic provisioning within seconds of payment, so you get both protection and geographic proximity together. The numbers are clear: an 8ms baseline round trip, blocking at layer seven, and data that never leaves the Kingdom. Real security is not a single product but an architecture: a network firewall controlling entry, a WAF controlling content, and clean code treating inputs with care, all together making the difference.


