Waf

AWS WAF with rate limiting, IP reputation, OWASP core rules and SQL injection protection in one line. Starts in count mode so nothing breaks.

Security · anvil:aws:Waf

What it blocks by default

new anvil.aws.Waf('edge') creates these rules, evaluated in order — cheap IP checks first, expensive body inspection last. Requests that match nothing are allowed.

RuleDefaultStops
ipAllowListonly if setAlways allows these IPs, skipping every other rule
ipBlockListonly if setAlways blocks these IPs — in count mode too
blockCountriesonly if setTraffic from the listed countries
Rate limiton — 2,000 requests per client per 5 minFloods and brute force from a single IP
IP reputationonIPs on Amazon's threat-intelligence lists
Known bad inputsonLog4Shell, Spring4Shell, Java deserialisation, React RCE and other known exploits
Core rule setonOWASP Top 10: XSS, path traversal, remote file inclusion, cloud metadata SSRF, scanners
SQL injectiononSQL injection in query strings, bodies, cookies and paths
Anonymous IPsoffVPNs, Tor, hosting providers — suits B2B apps
Admin protectionoffRequests to admin-looking paths

The core rule set's "body over 8 KB" rule (SizeRestrictions_BODY) only counts by default — blocking it would break forms, JSON APIs and uploads. Restore it with ruleOverrides: { SizeRestrictions_BODY: 'block' }.

What it doesn't cover

  • Request bodies beyond the first 16 KB aren't inspected (an AWS WAF limit for CloudFront). An attack placed after 16 KB of padding gets through — keep validating input in your app.
  • Distributed and slow attacks: the rate limit is per IP, so many IPs or a slow rate stay under it. Lower rateLimit to suit your traffic.
  • Bots and application-layer DDoS: AWS's paid Bot Control and Anti-DDoS groups aren't included.
  • Your app's own bugs: broken access control, auth flaws and business logic. A WAF catches known attack patterns, not logic errors.
  • HttpApi: AWS WAF can't attach to API Gateway HTTP APIs. Verify webhook signatures and use authorizers there.

Verified on AWS

Tested against a deployed site in block mode:

TestResult
XSS, SQL injection (query and body), path traversal, Log4Shell, metadata SSRF, scanner and missing user agents, sensitive file extensions9/9 blocked
Evasions: double URL-encoding, mixed case, XSS without <script>, SQL comment obfuscation, attacks in cookies and on static-asset paths, spoofed X-Forwarded-For7/7 blocked
Legitimate traffic: pages, form posts, JSON, 20 KB bodiesAll allowed
Rate limit (lowered to 100 / min for the test)Blocking started after ~28 s; 801 of 972 requests blocked
Calling the site's server directly, around CloudFront and the WAF8/8 refused (403)
SQL injection hidden after 17 KB of body paddingNot blocked — the 16 KB inspection limit above