Hey everyone! I've been tinkering with a Python-based filtering layer, a bit like an application-level WAF, but functioning within the app rather than at the infrastructure level. The goal isn't to replace services like Cloudflare or Nginx; rather, I'm exploring the added control we get when the logic is informed by the application context, such as user roles, session states, and specific API behaviors. I'm currently using a scoring system that assesses multiple types of signals: payload inspection (like SQLi and XSS patterns), behavioral signals (e.g., rate patterns and repeated requests), identity signals (IP or user-level risk over time), and contextual anomalies (such as request size and structure). Each of these contributes to a final score determining whether to allow, flag, throttle, or block a request. I'm also considering separating hard deterministic checks from probabilistic scoring because I've noticed that strong signals can become diluted. Does this split between deterministic and scoring-based signals make sense? For anyone experienced with WAFs or similar filtering systems, where do you typically differentiate between infrastructure-level protection and application-level logic? Could something like this serve as a useful additional layer for handling unique app behaviors? I appreciate any insights on how to design this effectively!
4 Answers
Your focus on making the system flexible is key! Traditional WAFs miss the nuances, like recognizing when a user just changed their password and is now behaving oddly. It's smart to allow configurable checks based on endpoints. Some routes might need stricter rules on SQL injection while others may prioritize rate limiting.
I completely agree with the deterministic vs. probabilistic split; it echoes best practices from tools like ModSecurity. A tip would be to define your fail-open vs. fail-closed policies early—this can make a big difference during rule tuning in development environments. In production, ensure that confirmed threats like SQLi are hard blocks, irrespective of the scoring.
Your plan to split deterministic checks and scoring-based signals sounds solid. In most applications, deterministic checks like rate limiting and IP filtering are best left at the WAF level. Once the requests are within your app, your middleware can handle logging and context-specific checks. Think about using an organized logging setup to capture essential details like IP, URI, and payload, which can be invaluable for tuning your rules later.
Absolutely! Having endpoint-specific configurations is a great feature to include. It allows developers to customize according to their app's needs and tackle threats more precisely. Keep iterating on this, and it can turn into a really useful tool for many developers!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically