Skip to content

Add WAF rule engine prototype using wirefilter#968

Draft
hansott wants to merge 1 commit intomainfrom
waf-wirefilter-prototype
Draft

Add WAF rule engine prototype using wirefilter#968
hansott wants to merge 1 commit intomainfrom
waf-wirefilter-prototype

Conversation

@hansott
Copy link
Member

@hansott hansott commented Mar 24, 2026

Use Cloudflare's wirefilter engine (via zen-internals WASM) to evaluate WAF rules against HTTP requests. Rules come from the config API and get checked in the middleware per request.

Summary by Aikido

Security Issues: 0 🔍 Quality Issues: 1 Resolved Issues: 0

🚀 New Features

  • Added WAF engine prototype using wirefilter WASM integration.
  • Introduced WafRule types and evaluation/setters for rule management.

⚡ Enhancements

  • Evaluated WAF rules during request processing and returned block result.
  • Updated Hono and Express middleware to handle WAF blocking responses.
  • Extended agent Config to include wafRules and imported setWafRules.

More info

Use Cloudflare's wirefilter engine (via zen-internals WASM) to
evaluate WAF rules against HTTP requests. Rules come from the
config API and get checked in the middleware per request.

Field names follow Cloudflare's conventions (http.request.method,
http.request.uri.path, ip.src, etc.) with operators like contains,
matches (regex), eq, and in {CIDR}.
query: query,
uri: url,
full_uri: `${host}${url}`,
user_agent:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header extraction for user-agent, cookie, referer and x-forwarded-for repeats the same ternary logic; extract a small helper (e.g., getHeaderString(headers, key)) to avoid duplication.

Details

✨ AI Reasoning
​Multiple header fields are extracted using the same ternary pattern and repeated inline: this repeats identical logic (check typeof header key is string ? use it : undefined) for user-agent, cookie, referer, and x-forwarded-for. Consolidating into a small helper would reduce repetitive code and the chance of inconsistent changes when adding more headers.

🔧 How do I fix it?
Delete extra code. Extract repeated code sequences into reusable functions or methods. Use loops or data structures to eliminate repetitive patterns.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

@hansott hansott marked this pull request as draft March 24, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant