Skip to content

Comments

🛡️ Sentinel: [HIGH] Fix Missing rate limiting on sensitive endpoints#96

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

🛡️ Sentinel: [HIGH] Fix Missing rate limiting on sensitive endpoints#96
Dexploarer wants to merge 1 commit intodevelopfrom
sentinel-rate-limit-16945940585250314293

Conversation

@Dexploarer
Copy link
Owner

  • 🚨 Severity: HIGH
  • 💡 Vulnerability: Sensitive endpoints (/api/wallet/export, /api/agent/reset, /api/cloud/login) lacked rate limiting, exposing them to brute force or abuse.
  • 🎯 Impact: Potential private key exfiltration (via brute force of authenticated sessions), data loss (reset abuse), or cloud account compromise.
  • 🔧 Fix: Implemented a generic checkRateLimit function with fixed-window counters and applied it to these endpoints. Also refactored existing pairing rate limit to use this unified system.
  • ✅ Verification: Added src/api/server.rate-limit.test.ts covering 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

- 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
@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.

@github-actions github-actions bot added the tests label Feb 19, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 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-16945940585250314293

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.

@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 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

  • Security Vulnerability Addressed: A high-severity security vulnerability was addressed by implementing rate limiting on sensitive API endpoints that were previously exposed to brute-force attacks or abuse.
  • Generic Rate Limiting Function: A new generic checkRateLimit function was introduced, utilizing a fixed-window counter to manage request rates effectively.
  • Endpoint Protection: Rate limiting was applied to critical endpoints including /api/wallet/export, /api/agent/reset, and /api/cloud/login to prevent potential private key exfiltration, data loss, or account compromise.
  • Refactored Existing Logic: The existing rate limiting logic for the /api/pairing endpoint was refactored to leverage the new, unified checkRateLimit function.
  • Comprehensive Testing: New unit tests were added for the checkRateLimit function, covering various scenarios to ensure its correctness and robustness.

🧠 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 a new test file for the checkRateLimit function.
    • Included tests for allowing requests within limits, blocking exceeding requests, resetting after a window, and handling different keys/IPs separately.
  • src/api/server.ts
    • Defined rateLimitMap in ServerState and introduced RateLimitEntry interface.
    • Implemented the checkRateLimit function for fixed-window rate limiting.
    • Removed the pairingAttempts map and rateLimitPairing function, consolidating rate limiting logic.
    • Integrated checkRateLimit for the /api/pairing endpoint.
    • Integrated checkRateLimit for the /api/agent/reset endpoint with a limit of 3 attempts per minute.
    • Integrated checkRateLimit for the /api/wallet/export endpoint with a limit of 3 attempts per minute.
    • Integrated checkRateLimit for the /api/cloud/login endpoint with a limit of 5 attempts per minute.
    • Initialized rateLimitMap when the API server starts.
    • Added a scheduled cleanup for expired rate limit entries every 5 minutes.
    • Ensured the rate limit cleanup interval is cleared when the server closes.
Activity
  • PR was automatically created by Jules for task 16945940585250314293, initiated by @Dexploarer.
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.

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

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.

Comment on lines +910 to +913
if (!entry || now > entry.resetAt) {
state.rateLimitMap.set(fullKey, { count: 1, resetAt: now + windowMs });
return true;
}

Choose a reason for hiding this comment

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

security-high high

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",

Choose a reason for hiding this comment

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

medium

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",

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