Prompt
SQL injection XSS WAF rules
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
I can help with defensive WAF rule design for SQL injection and XSS. If your goal is to protect an app, here are practical rules and patterns you can use.
1) SQL injection: WAF rule ideas
Common indicators to inspect
- SQL keywords:
select,union,insert,update,delete,drop,create,alter,exec,execute - Boolean logic abuse:
or 1=1,and 1=1 - Comment markers:
--,#,/* ... */ - Tautology / payload patterns
- Suspicious encodings: URL-encoded, double-encoded, mixed case, Unicode homoglyphs
- Delimiter abuse:
',",;
Example ModSecurity-style rule patterns
SecRule ARGS|ARGS_NAMES|REQUEST_HEADERS|REQUEST_COOKIES "@rx (?i)(\bunion\b.*\bselect\b|\bor\b\s+1=1\b|\band\b\s+1=1\b|(--|#|/\*|\*/)|\b(select|insert|update|delete|drop|alter|create|exec|execute)\b)"
"id:100100,phase:2,deny,status:403,msg:'Possible SQL injection attempt'"
Stronger approach
Instead of a single broad regex, use several targeted rules:
- Detect SQL meta characters only when combined with suspicious context
- Normalize input first:
- URL decode
- lowercase
- compress whitespace
- Apply stricter rules on parameters that should be numeric or enum-only
Reduce false positives
- Allowlist known-safe parameters
- Use parameter-specific validation:
user_id→ digits onlysort→ one of predefined valuesemail→ email format
- Log first, then block after tuning
2) XSS: WAF rule ideas
Common indicators
- Script tags:
<script - Event handlers:
onload=,onerror=,onclick= - JavaScript URLs:
javascript: - Dangerous HTML tags:
iframe,svg,img,object,embed - HTML entity encoded payloads
- DOM-based vectors in query strings or form fields
Example rule
SecRule ARGS|ARGS_NAMES|REQUEST_HEADERS|REQUEST_COOKIES "@rx (?i)(<\s*script\b|javascript\s*:|on\w+\s*=|<\s*(iframe|svg|img|object|embed)\b)"
"id:100200,phase:2,deny,status:403,msg:'Possible XSS attempt'"
Better XSS mitigation
- Block only in contexts where HTML is not expected
- Use output encoding in the app:
- HTML encode for HTML context
- JS encode for JavaScript context
- URL encode for URL context
- Add a Content Security Policy (CSP)
- Sanitize rich text inputs with an allowlist sanitizer
3) Recommended WAF tuning approach
Baseline strategy
- Start in detection-only mode
- Review logs for legitimate requests
- Add exclusions for safe parameters
- Tighten to block mode
- Re-test with real traffic
Normalize before matching
Handle:
- URL encoding
- HTML entity decoding
- case folding
- whitespace collapsing
- multi-encoding attempts
Score-based detection
Instead of one rule, assign points:
- SQL keyword: +2
- comment marker: +2
- quote + operator combo: +3
- XSS tag/event handler: +4 Block if score exceeds threshold.
4) Example high-level WAF policy
SQLi
- Block if request contains:
- SQL keyword + operator combo
- comment markers near SQL keywords
- malformed numeric parameter
- Allow if parameter schema matches expected type
XSS
- Block if request contains:
<script- event handler attributes
javascript:- HTML tags in fields expected to be plain text
- Allow sanitized rich text only through a separate field with strict sanitizer
5) Important limitations
- WAF rules are helpful, but not sufficient alone
- The strongest protection is:
- parameterized queries / prepared statements
- server-side validation
- output encoding
- CSP for XSS
- least-privilege DB accounts
If you want, I can provide:
- ModSecurity rules for SQLi/XSS
- AWS WAF regex patterns
- Cloudflare WAF expressions
- A tuned rule set for a specific application/framework