rate-limiting
БесплатноБез исполняемых скриптовНе проверенImplement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks…
Об этом скилле
Rate Limiting - Preventing Brute Force & Resource Abuse
Why Rate Limiting Matters
The Brute Force Problem
Without rate limiting, attackers can try thousands of passwords per second. A 6-character password has 308 million possible combinations.
Without rate limiting:
- At 1,000 attempts/second → Cracked in 5 minutes
With our rate limiting (5 requests/minute):
- At 5 attempts/minute → Would take 117 years
Real-World Brute Force Attacks
Zoom Credential Stuffing (2020): Attackers made over 500,000 login attempts using stolen credentials. Proper rate limiting would have detected and blocked this within the first few hundred attempts.
WordPress Distributed Attacks (2021): Multiple WordPress sites were targeted by distributed brute force attacks attempting millions of login combinations. Sites without rate limiting saw server costs spike as attackers consumed resources.
The Cost of Resource Abuse
Beyond security, rate limiting protects your infrastructure costs. Without it:
- Bots can spam your contact form thousands of times
- Attackers can abuse expensive operations (AI API calls, database queries)
- Your server bill skyrockets before you notice
Real Story: One startup built a "summarize any article" AI feature without rate limiting. A malicious user scripted 10,000 requests in minutes. At AI API costs, this generated $9,600 in charges in 10 minutes. The attack ran 4 hours unnoticed—total cost over $200,000.
Our Rate Limiting Architecture
Implementation Features
- 5 requests per minute per IP address - Balances usability and security
- In-memory tracking - Fast, no database overhead
- IP-based identification - Works behind proxies via x-forwarded-for
- HTTP 429 status - Standard "Too Many Requests" response
- Shared budget - All routes using withRateLimit() share same 5/min limit per IP
Why 5 Requests Per Minute?
Research on usability vs security shows that legitimate users rarely make more than 5 requests per minute to the same endpoint. This limit:
- ✅ Stops automated attacks
- ✅ Doesn't impact real users
- ✅ Allows reasonable form resubmissions
- ✅ Permits error recovery attempts
Why Per-IP Tracking?
- Individual users get individual limits
- An attack on one IP doesn't block others
- During distributed attack, each bot IP limited separately
- Makes attacks ineffective at scale
Implementation Files
lib/withRateLimit.ts- Rate limiting middlewareapp/api/test-rate-limit/route.ts- Test endpointscripts/test-rate-limit.js- Verification script
How to Use Rate Limiting
Basic Usage
For any endpoint that could be abused:
import { NextRequest, NextResponse } from 'next/server';
import { withRateLimit } from '@/lib/withRateLimit';
async function handler(request: NextRequest) {
// Your business logic
return NextResponse.json({ success: true });
}
// Apply rate limiting
export const POST = withRateLimit(handler);
export const config = {
runtime: 'nodejs',
};
Combined with CSRF Protection
For maximum security on state-changing operations:
import { NextRequest, NextResponse } from 'next/server';
import { withRateLimit } from '@/lib/withRateLimit';
import { withCsrf } from '@/lib/withCsrf';
async function handler(request: NextRequest) {
// Business logic
return NextResponse.json({ success: true });
}
// Layer both protections (rate limit first, then CSRF)
export const POST = withRateLimit(withCsrf(handler));
export const config = {
runtime: 'nodejs',
};
When to Apply Rate Limiting
✅ Always Apply To:
- Contact/support forms
- Newsletter signup
- Account creation
- Password reset requests
- File upload endpoints
- Search endpoints
- Data export endpoints
- Any expensive AI/API operations
- Webhook endpoints
- Comment/review submission
- Report generation
- Bulk operations
❌ Usually Not Needed For:
- Static asset requests (handled by CDN)
- Simple GET endpoints that only read public data
- Health check endpoints
- Endpoints already protected by authentication rate limits
Complete Examples
Example 1: Contact Form with Full Protection
// app/api/contact/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { withRateLimit } from '@/lib/withRateLimit';
import { withCsrf } from '@/lib/withCsrf';
import { validateRequest } from '@/lib/validateRequest';
import { contactFormSchema } from '@/lib/validation';
import { handleApiError } from '@/lib/errorHandler';
async function contactHandler(request: NextRequest) {
try {
const body = await request.json();
const validation = validateRequest(contactFormSchema, body);
if (!validation.success) {
return validation.response;
}
const { name, email, subject, message } = validation.data;
await sendEmail({
to: '[email protected]',
from: email,
subject,
message
});
return NextRespon
Установить rate-limiting в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл rate-limiting?
Implement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks, prevent API abuse, limit request frequency, or control infrastructure costs. Triggers include "rate limiting", "rate limit", "brute force", "prevent spam", "API abuse", "resource exhaustion", "DoS", "withRateLimit", "too many requests", "429 error".
Как установить скилл rate-limiting?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл rate-limiting запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic