CORAZA v3 WAF & OWASP CRS v4 TUNING

Hackergate embeds the Coraza v3 Web Application Firewall engine in 100% native Go. It executes the industry-standard OWASP Core Rule Set (CRS) v4 directly inside the reverse proxy process without CGO bindings, context switches, or external daemon hops.

Inspection Pipeline & Processing Phases

Coraza models HTTP inspection in 5 sequential phases matching the ModSecurity / SecLang execution lifecycle. Requests that exceed anomaly scoring thresholds in Phase 1 or 2 are aborted immediately before backend invocation, saving upstream compute capacity.

CORAZA INSPECTION LIFECYCLE
Client Request ────────► [Phase 1: Request Headers] ───► Anomaly Score Check │ (URL, Method, Headers, Cookies) ▼ [Phase 2: Request Body] ──────► Anomaly Score Check ──► REJECT (HTTP 403) │ (JSON, Multipart, URLEncoded) (if score >= threshold) ▼ [Backend Proxy Dispatch] ─────► Upstream Origin Server │ ▼ Backend Response ◄────── [Phase 3: Response Headers] ──► Status Code / Header Filter │ ▼ [Phase 4: Response Body] ─────► DLP Shield / Masking ─► OVERRIDE (HTTP 500) │ (Regex Credit Cards, API Keys) ▼ [Phase 5: Audit Logging] ─────► JSON Structured Log / OTel Span

OWASP CRS v4 Paranoia Levels (PL 1 – PL 4)

Paranoia levels balance detection sensitivity against operational overhead. As paranoia level increases, additional rule families are evaluated, requiring targeted exclusions for legitimate application patterns.

PL 1: Baseline Production

Designed for zero false positives. Catches obvious SQL injection, Cross-Site Scripting (XSS), Local File Inclusion (LFI), Remote Code Execution (RCE), PHP code evaluation, and HTTP protocol anomalies.

Inbound Score: 5 • Outbound: 4
Tuning needed: None to minimal.

PL 2: Hardened Services

Adds rigorous protocol checks: validates UTF-8 byte sequences, disallows null bytes and carriage returns in headers, verifies Content-Type match against body, and enforces parameter length caps.

Inbound Score: 4 • Outbound: 4
Tuning needed: Common webhooks require exclusions.

PL 3: Banking & High Risk

Detects advanced evasion techniques: character hex encoding expansions, repetition of SQL statement keywords (UNION, SELECT), multiple URL encodings, and strict parameter format matching.

Inbound Score: 3 • Outbound: 3
Tuning needed: Substantial per-endpoint rule exclusions.

PL 4: Forensic Lockdown

Extreme defensive containment. Drops requests containing Unix/Windows shell metacharacters (| & ; $ ` > <) or non-alphanumeric parameter structures.

Inbound Score: 2 • Outbound: 2
Tuning needed: Heavy allow-listing required.

Anomaly Scoring Mechanics

Unlike traditional WAFs that block on the first matched pattern (traditional regex mode), Hackergate uses OWASP CRS collaborative anomaly scoring. Each rule match contributes an anomaly weight based on severity. The request is only blocked when the cumulative score reaches the inbound threshold.

Severity LevelScore AddedExample TriggersTypical Action
CRITICAL+5SQLi UNION SELECT, Command Injection, Directory TraversalImmediate block on PL 1 (threshold 5 reached)
ERROR+4XSS event handler in URL, Missing Host headerWarns on PL 1, blocks if combined with notice
WARNING+3Unknown Content-Type, Obsolete HTTP/1.0 without Keep-AliveContributes to total anomaly score
NOTICE+2Missing Accept header, Generic crawler User-AgentInformational telemetry indicator

Configuring WAF in Virtual Host YAML

WAF settings are configured declaratively per virtual host in /etc/hackergate/vhosts.d/. Different domains on the same server can run different paranoia levels and custom rule files.

/etc/hackergate/vhosts.d/api.example.com.yaml
name: api.example.com domains: - api.example.com waf: enabled: true paranoia_level: 2 inbound_anomaly_threshold: 5 outbound_anomaly_threshold: 4 rules_file: /etc/hackergate/rules.d/custom-api.conf backend: driver: proxy target: http://10.0.0.15:8080

Custom SecLang Directives & Rule Exclusions

When legitimate application behavior triggers CRS rules, write target-scoped exclusions rather than disabling the entire WAF or entire rule families. Hackergate supports standard SecLang directives.

/etc/hackergate/rules.d/custom-api.conf
# /etc/hackergate/rules.d/custom-api.conf # ------------------------------------------------------------- # 1. SCOPED EXCLUSION: Disable SQLi rule 942100 on auth passwords # ------------------------------------------------------------- SecRule REQUEST_URI "@streq /api/v1/auth/login" \ "id:10001,phase:1,pass,nolog,ctl:ruleRemoveTargetById=942100;ARGS:password" # ------------------------------------------------------------- # 2. INCREASE BODY LIMIT: Allow 50MB uploads on ingestion routes # ------------------------------------------------------------- SecRule REQUEST_URI "@beginsWith /api/v1/documents/upload" \ "id:10002,phase:1,pass,nolog,ctl:requestBodyLimit=52428800" # ------------------------------------------------------------- # 3. GRAPHQL QUERY EXCLUSION: Allow curly braces in query parameter # ------------------------------------------------------------- SecRule REQUEST_URI "@streq /graphql" \ "id:10003,phase:1,pass,nolog,ctl:ruleRemoveById=941100" # ------------------------------------------------------------- # 4. DATA LEAKAGE SHIELD: Drop outbound responses exposing AWS keys # ------------------------------------------------------------- SecRule RESPONSE_BODY "@rx (?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}" \ "id:10004,phase:4,deny,status:500,log,auditlog,msg:'CRITICAL: Outbound AWS Access Key leak blocked by Hackergate'"

Response Body Shielding (Data Leakage Prevention)

Hackergate inspects outbound backend HTTP response bodies in Phase 4. If an upstream service accidentally reflects database credentials, private cryptographic keys, or unmasked credit card numbers, Hackergate intercepts the response, substitutes a safe HTTP 500 error, and fires a high-priority threat alert to the mesh.

Credential & Key Leaks

Pre-compiled regex patterns identify AWS Access Keys, Google Cloud service account JSON blocks, RSA / EC private key headers (-----BEGIN PRIVATE KEY-----), and GitHub / GitLab personal access tokens.

PII & PCI-DSS Card Validation

Outbound credit card number patterns are verified with real-time Luhn checksum calculation. False matches (such as numeric product barcodes) pass through unaffected.

Stack Trace & Debug Suppression

Suppresses unhandled backend exceptions exposing database connection strings, SQL dialect query dumps, or internal microservice IP addresses to public clients.

← PREV: KUBERNETES INGRESSNEXT: DECENTRALIZED THREAT GOSSIP →