🛡️ Sentinel: [HIGH] Fix Missing rate limiting on sensitive endpoints#96
🛡️ Sentinel: [HIGH] Fix Missing rate limiting on sensitive endpoints#96Dexploarer wants to merge 1 commit intodevelopfrom
Conversation
- Implemented generic `checkRateLimit` helper in `src/api/server.ts` - Applied rate limiting to `/api/wallet/export`, `/api/agent/reset`, and `/api/cloud/login` - Refactored `/api/auth/pair` to use the new rate limiter - Added `rateLimitMap` to `ServerState` with automatic cleanup interval - Added `src/api/server.rate-limit.test.ts` for verification
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @Dexploarer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security posture of the application by introducing robust rate limiting mechanisms. It targets critical endpoints previously vulnerable to brute-force attacks or abuse, thereby mitigating risks such as private key exfiltration, data loss, and account compromise. The changes centralize rate limiting logic and ensure consistent protection across sensitive operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements rate limiting for sensitive API endpoints, which is a significant security improvement against brute-force and abuse. The implementation uses a generic checkRateLimit function with a fixed-window counter and an in-memory map. While the logic is sound, the current implementation has a high-severity vulnerability where the rate-limit map is unbounded, potentially leading to memory exhaustion (DoS). Additionally, the use of remoteAddress without checking for proxy headers may cause issues in environments where the server is behind a reverse proxy.
| if (!entry || now > entry.resetAt) { | ||
| state.rateLimitMap.set(fullKey, { count: 1, resetAt: now + windowMs }); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
The rateLimitMap is currently unbounded, which introduces a potential Denial of Service (DoS) vector via memory exhaustion. Since endpoints like /api/auth/pair are unauthenticated and trigger a new map entry for every unique IP, an attacker could flood the server with requests from many different IPs (or spoofed IPs), causing the map to grow until the process runs out of memory. A hard limit on the map size should be enforced.
if (!entry || now > entry.resetAt) {
if (!entry && state.rateLimitMap.size >= 10000) {
return false;
}
state.rateLimitMap.set(fullKey, { count: 1, resetAt: now + windowMs });
return true;
}| if ( | ||
| !checkRateLimit( | ||
| state, | ||
| req.socket.remoteAddress ?? "unknown", |
There was a problem hiding this comment.
Using req.socket.remoteAddress directly does not account for reverse proxies. If the application is deployed behind a proxy (e.g., Nginx, Cloudflare, or the Vite dev server), remoteAddress will return the proxy's IP rather than the actual client's IP. This would cause all users to share the same rate limit bucket, potentially blocking legitimate users when one triggers the limit. This applies to all call sites of checkRateLimit in this file.
(req.headers["x-forwarded-for"] as string)?.split(",")[0].trim() ?? req.socket.remoteAddress ?? "unknown",
/api/wallet/export,/api/agent/reset,/api/cloud/login) lacked rate limiting, exposing them to brute force or abuse.checkRateLimitfunction with fixed-window counters and applied it to these endpoints. Also refactored existing pairing rate limit to use this unified system.src/api/server.rate-limit.test.tscovering various scenarios. Verified logic via ad-hoc script due to environment limitations preventing full test suite execution.PR created automatically by Jules for task 16945940585250314293 started by @Dexploarer