Course contentsShow
← Cloud and Infrastructure
Lesson 2375 of 2,98951. Network SecurityFree lesson

Custom Rules and Request Inspection

Writing custom rules based on request headers, body content, URI patterns, and query strings.

Custom Rules and Request Inspection

What you'll learn: How to create fine-grained WAF rules that inspect specific parts of HTTP requests to detect and block malicious traffic based on your application's unique security needs.

Beyond Pre-Built Rules

While managed rule groups (like OWASP Top 10 protections) cover common threats, your application has unique vulnerabilities and traffic patterns. Custom rules let you inspect specific request components—headers, body content, URI patterns, and query strings—to catch attacks that generic rules miss.

Inspecting Request Components

Think of each HTTP request as a multi-compartment suitcase going through security. You can open and inspect each compartment:

Headers: Check for suspicious User-Agent strings, missing required headers, or SQL injection attempts in Referer values.

URI Path: Block requests to /admin from unauthorized IPs, or patterns like /../etc/passwd indicating path traversal attacks.

Query Strings: Detect SQL keywords (SELECT, UNION) in parameters like ?id=1' OR '1'='1.

Request Body: Inspect POST data for malicious payloads, especially in JSON or form submissions.

Writing Custom Rules

Custom rules typically follow this structure:

  1. Condition: What to inspect (URI, header X-Custom-Token, body field email)
  2. Match criteria: Regex pattern, exact match, size constraint, or contains operation
  3. Action: Block, allow, count (dry-run), or CAPTCHA challenge

For example, blocking requests where the URI contains <script> tags or where the body exceeds 1MB protects against XSS and oversized payload attacks.

Combining Conditions

Advanced rules use AND/OR logic: "Block if User-Agent contains 'bot' AND URI starts with '/api/' AND rate exceeds 100 req/min."

Key Takeaway: Custom rules transform your WAF from a generic shield into a precision security tool by inspecting request headers, URIs, query strings, and body content with conditions tailored to your application's specific threat landscape.