Rate limiting security
Rate limiting controls how often an actor can use an endpoint or a costly dependent service. It reduces brute force attempts, denial-of-service pressure, spam, and unexpected provider spend when limits are enforced by trusted server-side systems.
Protection scope
Rate limiting belongs at every boundary where a request can consume security-sensitive, costly, or scarce capacity. The limit must protect both the public endpoint and the service that the endpoint calls.
Protected endpoint classes
The highest-risk endpoints accept repeated attempts or trigger work outside the application. Review them as abuse paths rather than as isolated routes.
- Authentication flows, including login, registration, password reset, one-time password checks, and magic links.
- AI requests that create provider charges or consume shared model capacity.
- Email and SMS actions that can turn the application into a spam relay.
- File upload and processing actions that consume CPU, memory, or storage.
- Webhook-like endpoints that accept external input at high volume.
References: vibe-security/…/rate-limiting.md• L3-11
Dependent service capacity
An endpoint can be available while its dependent service is exhausted. Set limits and hard caps for external providers, then watch for unusual usage so an attack cannot become a cloud bill, provider outage, or queue backlog.
- Set billing alerts for each cloud provider.
- Set hard spending caps for AI providers.
- Give each user a hard usage quota instead of only a warning.
- Review sudden spikes and activity at unusual times.
References: vibe-security/…/rate-limiting.md• L28-33
Limiting model
An effective limit combines a clear resource budget with an identity key that an attacker cannot change. The limit decision must happen on the server because client state and request fields are controlled by the caller.
Trusted counters
Counters must live in a private or trusted rate-limit system. A public data table is not a safe counter when the caller can reset or edit it through a data API.
Acceptable control points include:
- A managed key-value store with rate-limit support.
- A private database area that is not exposed through the public data API.
- An edge, middleware, or API gateway layer.
- In-memory state for a single-server deployment.
- A shared store such as Redis when several servers must enforce one limit.
The store choice must match the deployment shape. A local counter does not provide one shared limit across multiple servers.
References: vibe-security/SKILL.md• L15-17 vibe-security/…/rate-limiting.md• L13-20
Combined identity keys
Use more than one identity dimension because each single key has a simple bypass. An IP-only limit can be avoided with rotating addresses. A user-only limit can be avoided with new accounts. Together, IP and user limits provide stronger coverage.
The system should identify unauthenticated traffic by network source and authenticated traffic by account, while keeping the counter logic outside client control. Review proxy and edge settings so the network identity used for a limit is trustworthy.
References: vibe-security/…/rate-limiting.md• L22-26 vibe-security/SKILL.md• L15-17
Request control flow
The request path should make the limit decision before it starts the expensive or sensitive work. This diagram shows the intended relationship between the request, the trusted counter, and the dependent service.
flowchart TD
A[Request] --> B[Derive trusted IP and account keys]
B --> C[Check server-side limit]
C -->|Limit available| D[Run protected operation]
D --> E[Call dependent service if needed]
C -->|Limit exceeded| F[Return 429 response]
Rejection boundary
Reject a request before password checks, provider calls, message sends, or heavy file work when the relevant limit is exceeded. A clear 429 response marks the request as throttled and prevents the protected operation from consuming more capacity.
References: vibe-security/…/rate-limiting.md• L35-55
Review relationships
Rate limiting is one part of application resilience. It works with authentication, input checks, deployment controls, and service budgets rather than replacing them. Use the Application resilience page for the wider reliability view and Deployment security for production boundary controls.
Bypass review
Review each limit against the ways an attacker can create a new key or reach a different path. The review should confirm that:
- The counter cannot be edited or reset by the client.
- An attacker cannot avoid the limit by changing only the IP address.
- An attacker cannot avoid the limit by creating accounts.
- Equivalent routes and alternate request methods use the same protection.
- A multi-server deployment shares the state needed for one limit.
- A rejected request does not call a costly dependent service.
References: vibe-security/SKILL.md• L15-17 vibe-security/SKILL.md• L28-30 vibe-security/…/rate-limiting.md• L13-26
Change checklist
When these files or sections are changed, remember to consider these:
- When an endpoint starts an AI, email, SMS, file, or webhook operation, add it to the same abuse review as authentication endpoints.
- When deployment changes from one server to several, move counter state to a shared enforcement point.
- When proxy or edge routing changes, verify that the IP identity used by limits still represents the intended client.
- When a provider or billing plan changes, recheck hard caps and per-user quotas against the new cost and capacity.
- When an endpoint gains an alternate route or request method, preserve the same limit across all entry paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A public table stores the counter | A caller resets or edits the counter and bypasses the limit | Use a private store, middleware, gateway, or trusted managed limiter |
| Only the IP address is limited | Rotating addresses defeats the control | Combine IP and account limits |
| Only the account is limited | New accounts defeat the control | Combine account and network limits |
| A limit runs after the provider call | Abuse still drains provider capacity or budget | Make the limit decision before the costly operation |
| Local counters run on several servers | Each server grants its own allowance | Use shared state or a shared edge enforcement point |
| A soft warning replaces a hard quota | One user can continue to consume shared capacity | Enforce hard user quotas and provider spending caps |
Key files
| File | Why to read it |
|---|---|
| vibe-security/…/rate-limiting.md | Defines the protected endpoint classes, trusted counter locations, combined identity model, cost controls, and rejection pattern. |
| vibe-security/SKILL.md | Places rate limiting in the security review and states the server-side trust rule. |
| docs/application-resilience.md | Parent page for the broader reliability and misuse-resistance guidance. |
| docs/deployment-security.md | Related page for production boundary and deployment controls. |