feat(security): Implement transport-level rate limiting and spam protection - #79
Open
Samuel1505 wants to merge 2 commits into
Open
feat(security): Implement transport-level rate limiting and spam protection#79Samuel1505 wants to merge 2 commits into
Samuel1505 wants to merge 2 commits into
Conversation
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.
Summary
Implements a token-bucket rate limiter to prevent malicious nodes from flooding neighbors with excessive messages, protecting against Resource Exhaustion / DOS attacks in the permissionless mesh network.
Problem
In a permissionless mesh network, anyone can join and start broadcasting. A malicious actor could spoof a node and constantly push thousands of 500-byte envelopes per second over WiFi-Direct, which would:
We need strict ingress rate limits per connected peer to mitigate these attacks.
Solution
Implemented a token-bucket rate limiter using the
governorcrate that:PeerViolation) for external monitoring and ban handlingRate Limits
Changes
New Files
src/security/mod.rs- Security module declarationsrc/security/events.rs- Security event definitions (PeerViolation,ViolationReason)src/security/rate_limit.rs- Token bucket rate limiter implementationtests/integration/rate_limit_test.rs- Integration tests for rate limitingModified Files
src/lib.rs- Addedsecuritymodulesrc/transport/unified.rs- Integrated rate limiter intoTransportManager::recv_any()Cargo.toml- Addedgovernorandnonzero_extdependenciesImplementation Details
RateLimiter: Per-peer token bucket rate limiter with separate limiters for BLE and WiFi-Direct
governorcrate'sRateLimiterwithQuota::per_second()TransportManager Integration:
recv_any()before processing messagesPeerViolationevent is emitted (if event sender is configured)Event System:
SecurityEvent::PeerViolationevent for external handlingbroadcast::Sender<SecurityEvent>for event emissionTesting
Unit Tests (7 tests)
Integration Tests (8 tests)
All tests pass: 119 unit tests + 8 integration tests
Dependencies Added
governor = "0.6"- Token bucket rate limiting implementationnonzero_ext = "0.3"- NonZeroU32 constant helpersCI Status
✅
cargo fmt --all- Code formatted✅
cargo clippy --all-targets --all-features -- -D warnings- No warnings✅
cargo test --workspace- All tests passAcceptance Criteria Met
Usage Example
Breaking Changes
None - This is a purely additive feature. Existing code continues to work without changes.
Future Improvements
closes #64