Add subnet and URI repetition blocking metrics to MetricsHandler#18
Draft
luisgizirian wants to merge 3 commits intomainfrom
Draft
Add subnet and URI repetition blocking metrics to MetricsHandler#18luisgizirian wants to merge 3 commits intomainfrom
luisgizirian wants to merge 3 commits intomainfrom
Conversation
- Added DEFENSE_FEATURES environment variable to configure defense features modularly. - Implemented parsing of defense features in the configuration. - Updated the Defender struct to include a bitfield for enabled defense features. - Enhanced request checking logic to conditionally apply defense features based on configuration. - Added new metrics for repeat blocked requests and updated stats reporting. - Updated documentation to reflect new configuration options and feature descriptions. - Modified storage methods to include request count when blocking IPs.
…mentation and expanded test cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Subnet and URI Repetition Blocking Metrics + Complete Defense Features Migration
Summary
This PR completes the modular defense features system by:
Key Changes
1. Metrics & Monitoring Improvements
Added
repeat_blocked_requestsMetric:/stats,/metrics,/timeseries, and SSE eventsFixed Request Count Display:
BlockedIPInfonow tracks actual request count before blocking/statsendpoint showing "0 requests" for blocked IPs{"ip": "10.4.4.4", "requests": 5, "blocked": true}Updated Metrics:
{ "blocked_requests": 150, // Total blocks (initial + repeats) "repeat_blocked_requests": 45, // Subset: repeat blocks only "top_ips": [ {"ip": "1.2.3.4", "requests": 5, "blocked": true} // Now shows actual count ] }2. Complete Defense Features Migration
Migrated 7 Hardcoded Patterns to Modular Flags:
All attack detection patterns are now individually configurable via
DEFENSE_FEATURES:path-traversal../and..\patternsexcessive-nestingsql-injectionUNION SELECT,DROP TABLEpatternsxss<script>,eval()patternsopen-redirectfile-access.env,.git,config,backupadmin-scanning/wp-admin,/phpmyadmin,.phpsubnet-blockingidentical-uriburst-detectionConfiguration Examples:
3. Implementation Details
Refactored Pattern Storage:
suspiciousPatternsinto feature-specific slicesAdded Feature Flag Checks:
Memory Efficiency:
int32bitfield (4 bytes) vs 10 separate bools (10+ bytes)4. Test Suite Enhancements
Updated
scripts/test-attacks.sh:[sql-injection],[xss], etc.Test Coverage:
Breaking Changes
None - Fully backward compatible:
DEFENSE_FEATURES="all"preserves existing behaviorMigration Guide
Existing Deployments:
No action required - default configuration preserves all functionality.
New Deployments (Opt-In Mode):
Performance Tuning:
Testing
All Tests Pass:
Integration Testing:
Documentation
Updated Files:
README.md- Complete 10-feature table with performance metricsFEATURE-FLAGS-REFACTOR.md- Technical implementation detailsDEFENSE-FEATURES-MIGRATION.md- Migration guide and summaryscripts/test-attacks.sh- Comprehensive test coverageMetrics & Monitoring
New Prometheus Metrics:
Performance Impact
Memory:
CPU:
Files Changed
internal/defender/defender.gointernal/defender/metrics.gointernal/defender/events.gointernal/storage/storage.gointernal/config/config.goscripts/test-attacks.shREADME.mdFEATURE-FLAGS-REFACTOR.mdexamples/live-dashboard.htmlTotal: ~479 lines changed across 9 files
Next Steps
Related Issues: N/A
Related PRs: #10 (Initial feature flags implementation)
Breaking Changes: None
Backward Compatible: ✅ Yes