How teler-sh/teler-waf works
Main Components
• HTTP Middleware: This is the “Teler” instance that wraps a net/http.Handler. It intercepts requests before they reach your application’s actual handler.
• Request Analyzer / Threat Engine: Components such as analyze.go, rule.go, and files under the “threat” package perform the analysis, inspect the request against pre-defined and custom rules (via DSL conditions), and then decide if the request is malicious.
• Rule & Condition Engine: The project supports both built-in and custom rules (via “Customs” or “CustomsFromFile”). Files like condition.go, rule.go, and DSL-related logic are part of this engine.
• Configuration & Option Handling: The “option” package (loader, loader_test.go, utils) helps load runtime options from JSON or YAML configurations. It controls aspects such as whitelists, threat exclusions, and logging preferences.
• Logging & Response Mechanism: This module logs detected malicious behavior, generates unique request IDs, and returns a custom response to the client (with details like threat category, error message, etc.).
• External Integrations: Examples include integration configurations for Falco Sidekick (sending JSON events to external monitoring tools) and Wazuh (via provided XML configurations and extra rule files).
• Example Applications: The examples directory shows various integration methods (with popular Go HTTP frameworks) and provides runnable demos.
Relationships and Data Flows
• Incoming HTTP requests from clients flow into the teler-waf middleware.
• The middleware first routes the request into the threat analysis engine. It uses configured options (from YAML/JSON or in-code constants) and applies multiple security checks using a combination of default and custom rules (via DSL expressions).
• If a threat is detected, the middleware will generate a JSON log, and – optionally – forward the event to external systems such as Falco Sidekick or be picked up by Wazuh based on specific integrations.
• The configuration component ensures these flows are customizable (e.g., enabling/disabling caching, development mode, and threat dataset updates).
Architectural Patterns and Design Principles
• Modular Design: The project is split into distinct modules (e.g., request, threat, option,dsl, etc.), enabling an extensible and maintainable design.
• Middleware Pattern: By conforming to the net/http.Handler interface, the system can be seamlessly integrated into various Go HTTP frameworks.
• DSL for Rules: The use of a domain-specific language for defining conditions provides flexibility and powerful rule customization.
• External Integrations: Loose coupling with external alerting and monitoring systems like Falco Sidekick and Wazuh.
Relevant Technologies and Frameworks
• Go (standard net/http for middleware)
• Configuration handling (YAML/JSON parsing)
• DSL expressions (leveraging the expr package and custom DSL functions)
• Integration with external systems: Falco Sidekick, Wazuh rule sets.
Instructing the Principal Software Engineer
• Branch off to show the threat analysis engine that includes the rule engine, DSL processor, and dataset management components.
• Nodes for configuration management (option loading) and link these to both the middleware and rule engine components.
• Clearly label every component with its name and main function.