Skip to content

Comments

🛡️ Sentinel: [HIGH] Add rate limiting to sensitive endpoints#101

Draft
Dexploarer wants to merge 1 commit intodevelopfrom
sentinel-rate-limit-fix-7239182323050929434
Draft

🛡️ Sentinel: [HIGH] Add rate limiting to sensitive endpoints#101
Dexploarer wants to merge 1 commit intodevelopfrom
sentinel-rate-limit-fix-7239182323050929434

Conversation

@Dexploarer
Copy link
Owner

🛡️ Sentinel: [HIGH] Add rate limiting to sensitive endpoints

Vulnerability: Missing rate limiting on sensitive endpoints (e.g., wallet export, agent reset, cloud login) allowed for potential brute-force attacks or Denial of Service (DoS).

Fix:

  • Implemented a generic in-memory rate limiter (checkRateLimit).
  • Added rateLimitMap to the server state with automatic cleanup every 5 seconds.
  • Applied rate limits to:
    • /api/cloud/login: 5 requests per minute.
    • /api/wallet/export: 5 requests per minute.
    • /api/agent/reset: 1 request per minute.
    • /api/agent/export: 5 requests per minute.
    • /api/agent/import: 5 requests per minute.

Verification:

  • Added src/api/server.rate-limit.test.ts to verify the rate limiting logic (allow, block, reset).
  • Verified no regressions with existing src/api/server.test.ts.

Impact: significantly reduces the risk of abuse on critical administrative endpoints.


PR created automatically by Jules for task 7239182323050929434 started by @Dexploarer

- Add `rateLimitMap` to `ServerState` in `src/api/server.ts`.
- Implement `checkRateLimit` helper function.
- Initialize rate limit map and cleanup interval in `startApiServer`.
- Apply rate limiting to `/api/cloud/login`, `/api/wallet/export`, `/api/agent/reset`, `/api/agent/export`, and `/api/agent/import`.
- Add unit tests in `src/api/server.rate-limit.test.ts`.

This mitigates DoS and brute-force risks on sensitive operations.
@google-labs-jules
Copy link

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sentinel-rate-limit-fix-7239182323050929434

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the tests label Feb 20, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 of the application by introducing robust rate limiting to several sensitive API endpoints. By implementing a generic, in-memory rate limiter and applying it to critical operations like agent management, wallet export, and cloud login, the changes effectively mitigate the risk of brute-force attacks and Denial of Service (DoS). This proactive measure strengthens the system's resilience against malicious or excessive requests.

Highlights

  • Rate Limiting Implementation: A generic in-memory rate limiting function (checkRateLimit) was implemented to control request frequency on sensitive endpoints.
  • Server State Integration: A rateLimitMap was added to the server state to track request counts and reset times, with an automatic cleanup mechanism every 5 seconds for expired entries.
  • Endpoint Protection: Rate limits were applied to critical API endpoints including /api/cloud/login, /api/wallet/export, /api/agent/reset, /api/agent/export, and /api/agent/import to prevent abuse.
  • Testing: A new dedicated test file (src/api/server.rate-limit.test.ts) was introduced to thoroughly verify the functionality and correctness of the rate limiting logic.

🧠 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
  • src/api/server.rate-limit.test.ts
    • Added unit tests for the new rate limiting logic, covering allowance, blocking, and reset scenarios.
  • src/api/server.ts
    • Updated the ServerState interface to include a rateLimitMap for tracking request counts.
    • Introduced the checkRateLimit function to enforce request limits based on key, limit, and window.
    • Applied rate limiting to /api/agent/reset (1 request/minute).
    • Applied rate limiting to /api/agent/export (5 requests/minute).
    • Applied rate limiting to /api/agent/import (5 requests/minute).
    • Applied rate limiting to /api/wallet/export (5 requests/minute).
    • Applied rate limiting to /api/cloud/login (5 requests/minute).
    • Initialized the rateLimitMap when the API server starts.
    • Implemented a cleanup mechanism for expired rate limit entries within the 5-second status broadcast interval.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment on lines +111 to +115
it("handles missing rateLimitMap gracefully", () => {
const state: any = {}; // No map
// Should return true (fail open) if map is missing
expect(checkRateLimit(state, "key", 1, 1000)).toBe(true);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail-open behavior for missing rateLimitMap may mask initialization errors

The test on lines 111-115 checks that checkRateLimit returns true if rateLimitMap is missing from the state. While this ensures the function does not throw, it may mask underlying issues in production if the state is not properly initialized. Consider updating the implementation to throw an error or ensure the map is always present, rather than silently allowing requests:

if (!state.rateLimitMap) throw new Error('rateLimitMap missing');

This would make failures explicit and easier to debug.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a generic in-memory rate limiter to protect sensitive administrative and security-related endpoints from brute-force attacks and potential Denial of Service (DoS). The implementation includes a tracking map in the server state, a periodic cleanup mechanism to manage memory, and targeted application of limits to critical routes such as agent reset, export/import, wallet export, and cloud login. Overall, the logic is sound and follows a standard fixed-window approach, which is appropriate for this use case. My feedback focuses on improving the robustness of client identification and enhancing code maintainability through constants.

limit: number,
windowMs: number,
): boolean {
if (!state.rateLimitMap) return true; // Safety check

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While req.socket.remoteAddress is a standard way to identify clients, it will return the IP of the proxy if the server is deployed behind a reverse proxy (like Nginx or a load balancer). This can lead to all users behind that proxy sharing the same rate limit bucket. Consider checking for x-forwarded-for headers if the server is configured to trust proxies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant