Skip to main content
skill CX Codex

rate-limiting-abuse-protection — Claude Code skill: API abuse

A skill that adds request throttling to your API: per-route policies, IP and user limits, sliding windows, and clean error responses.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill rate-limiting-abuse-protection -a claude-code
Open on GitHub

What rate-limiting-abuse-protection does

This skill walks the agent through locking an API against brute force and flooding. It covers four strategies: fixed window, sliding window, token bucket, and leaky bucket. The TypeScript examples use express-rate-limit for a global limiter plus a stricter one on login endpoints.

For distributed setups there is a Redis version built on ioredis: old entries are trimmed by score, the request is added, the counter is read, and the key gets a TTL. Separate blocks handle limits keyed on req.user.id and IP reputation checks with a blocklist and a threat intelligence lookup. Responses carry X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, and Retry-After; over the limit you return 429 with a retry delay.

One catch: the Redis path needs a running Redis and the ioredis package, and the IP reputation check leans on an external service that the example does not include — you write checkThreatIntel yourself. The skill advises different limits per endpoint, tighter ones for expensive operations, and a bypass for internal services.

What it helps with

  • throttle API requests per route
  • stop password brute force on a login form
  • track limits separately for each user
  • send clients the remaining quota and reset time in headers
  • log violations and spot traffic spikes

Example prompts for the agent

  • add rate limiting to /api/ with 100 requests per 15 minutes
  • put a strict limit on /api/auth/login — 5 attempts, skip successful logins
  • rewrite the limiter on Redis with a sliding window and per-user limits

How to install rate-limiting-abuse-protection

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill rate-limiting-abuse-protection -a claude-code

2Manually: put the files in place

~/.claude/skills/rate-limiting-abuse-protection/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/rate-limiting-abuse-protection/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about rate-limiting-abuse-protection

How do I install rate-limiting-abuse-protection in Claude?

Run npx skills add patricio0312rev/skills --skill rate-limiting-abuse-protection -a claude-code. The skill lands in ~/.claude/skills/rate-limiting-abuse-protection/SKILL.md.

What does rate-limiting-abuse-protection do?

It gives the agent ready patterns for request throttling: per-route policies, IP and user limits, sliding windows, rate limit headers, and safe 429 responses.

What does the Redis version require?

A running Redis instance and the ioredis package. The IP reputation check also needs an external threat intelligence API — the example calls checkThreatIntel, which you implement yourself.

Source text

SKILL.md · MIT
---
name: rate-limiting-abuse-protection
description: Implements rate limiting and abuse prevention with per-route policies, IP/user-based limits, sliding windows, safe error responses, and observability. Use when adding "rate limiting", "API protection", "abuse prevention", or "DDoS protection".
---

# Rate Limiting & Abuse Protection

Protect APIs from abuse with intelligent rate limiting.

## Rate Limit Strategies

**Fixed Window**: 100 requests per hour
**Sliding Window**: More accurate, prevents bursts
**Token Bucket**: Allow bursts up to limit
**Leaky Bucket**: Smooth request rate

## Implementation (Express)

```typescript
import rateLimit from "express-rate-limit";

// Global rate limit
const globalLimiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100, // 100 requests per window
  message: "Too many requests, please try again later",
  standardHeaders: true, // Return rate limit info in headers
  legacyHeaders: false,
});

// Stricter limit for auth endpoints
const authLimiter = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 5, // Only 5 attempts
  skipSuccessfulRequests: true, // Don't count successful logins
});

app.use("/api/", globalLimiter);
app.use("/api/auth/login", authLimiter);
```

## Redis-based Rate Limiting

```typescript
import Redis from "ioredis";

const redis = new Redis();

export const checkRateLimit = async (
  key: string,
  max: number,
  window: number
): Promise<{ allowed: boolean; remaining: number }> => {
  const now = Date.now();
  const windowStart = now - window;

  await redis
    .multi()
    .zremrangebyscore(key, 0, windowStart)
    .zadd(key, now, `${now}`)
    .zcard(key)
    .expire(key, Math.ceil(window / 1000))
    .exec();

  const count = await redis.zcard(key);

  return {
    allowed: count <= max,
    remaining: Math.max(0, max - count),
  };
};
```

## Per-User Rate Limiting

```typescript
export const userRateLimit = (max: number, window: number) => {
  return async (req, res, next) => {
    if (!req.user) return next();

    const key = `rate_limit:user:${req.user.id}`;
    const result = await checkRateLimit(key, max, window);

    res.setHeader("X-RateLimit-Limit", max);
    res.setHeader("X-RateLimit-Remaining", result.remaining);

    if (!result.allowed) {
      return res.status(429).json({
        error: "Rate limit exceeded",
        retryAfter: window / 1000,
      });
    }

    next();
  };
};
```

## IP-based Protection

```typescript
// Block suspicious IPs
const ipBlocklist = new Set<string>();

export const checkIPReputation = async (ip: string): Promise<boolean> => {
  if (ipBlocklist.has(ip)) return false;

  // Check against threat intelligence API
  const reputation = await checkThreatIntel(ip);
  if (reputation.isMalicious) {
    ipBlocklist.add(ip);
    return false;
  }

  return true;
};
```

## Response Headers

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640000000
Retry-After: 3600
```

## Best Practices

- Different limits for different endpoints
- Lower limits for expensive operations
- Skip rate limit for internal services
- Return helpful error messages
- Log rate limit violations
- Monitor for abuse patterns
- Allowlist trusted IPs

## Output Checklist

- [ ] Rate limiter middleware
- [ ] Per-route policies
- [ ] User-based limiting
- [ ] IP-based limiting
- [ ] Rate limit headers
- [ ] Safe error responses
- [ ] Observability/logging
- [ ] Bypass for internal services

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

Everything for Security →

From the same set26

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor