Conversation
- Implemented ECDSA signature validation and anti-replay attack logic - Added global X-API-Key validation for IoT devices - Built Redis-backed rate limiter (50 req/sec) to prevent DoS - Replaced REST polling with WebSockets and Redis Pub/Sub for alerts - Updated stress and broadcast tests to support new security/limits
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.
🌋 Overview
This PR resolves Issue #19 (Security & Rate Limiting) and Issue #27 (Real-Time Notifications). It introduces critical security and scalability improvements to the FastAPI backend, preparing the API gateway to safely handle production IoT traffic and broadcast instant alerts.
🛠️ Key Changes
X-API-Keyvalidation for all IoT endpoints. Implemented strict ECDSA cryptographic signature validation and timestamp checking to block spoofed payloads and Replay attacks./ws/alerts). Hooked WebSockets into Redis Pub/Sub to instantly broadcast life-saving alerts to hundreds of clients across multiple containers.tests/stress_test.pyto include proper API headers, simulate malicious Replay/Bad Signature attacks, and pace requests to respect the new rate limiter.tests/test_websocket_broadcast.pyto verify Pub/Sub broadcasting to concurrent mobile clients.🧪 Testing Performed
stress_test.pywith 200 concurrent virtual sensors. Rate limiter successfully handled traffic bursts.401 Unauthorizedand403 Forbidden.test_websocket_broadcast.pysimulating 100 concurrent mobile clients receiving instant Redis alerts.docker compose up --buildworks cleanly with new dependencies (redis,websockets)./statistics) is temporarily skipped as the endpoint has not been implemented yet.worker.pyto asynchronously persist the valid payloads to PostGIS.