Fix: In-memory route cache grows unbounded#133
Open
Xenon010101 wants to merge 4 commits into
Open
Conversation
Closes madanrajsagar#129 Added verifyToken middleware to /send-email endpoint so that emergency SOS emails can only be sent by authenticated users. Previously anyone could POST to /send-email and trigger emergency alerts to contacts, enabling spam and alert fatigue attacks. Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
…nting Closes madanrajsagar#70, Closes madanrajsagar#126 - Reduced express.json body limit from 8mb to 1mb (8mb was excessive for most endpoints and increased abuse potential) - Removed duplicate app.use(userVideoRoutes) which caused redundant middleware execution and potential double-prefixing issues Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
Closes madanrajsagar#62 Added isValidIncidentId check (non-empty string, max 64 chars) with Express router.param middleware so all /:incidentId routes reject malformed IDs with a clean 400 response instead of processing them. Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
Closes madanrajsagar#59 Added MAX_CACHE_SIZE (500 entries) limit to both recentRouteCache and recentGeocodeCache with LRU eviction (deletes oldest entry when full) to prevent unbounded memory growth under heavy load. Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
Author
|
👋 Hi maintainer! Quick follow-up on this PR. It's been about a week — would appreciate a review when you get a chance. Happy to make any adjustments! |
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.
Closes #59
Root cause:
recentRouteCacheandrecentGeocodeCacheinbackend/routes/journey.js:23-24were plain Maps with TTL expiration but no maximum size limit. Under heavy load they could grow unbounded, causing memory exhaustion.Fix: Added
MAX_CACHE_SIZE = 500limit with LRU eviction — when a cache exceeds 500 entries, the oldest entry (first key in insertion order) is deleted before inserting the new one.