rate-limiting-abuse-protection
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".
Works with
---
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".
license: MIT
---
# 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 servicesMore API Design skills
lark-event
larksuite/cli
Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume <EventKey>` (covers IM messages/reactions/chat changes, Approval status changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.
lark-contact
larksuite/cli
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。
lark-openapi-explorer
larksuite/cli
飞书/Lark 原生 OpenAPI 探索:从官方文档库中挖掘未经 CLI 封装的原生 OpenAPI 接口。当用户的需求无法被现有 lark-* skill 或 lark-cli 已注册命令满足,需要查找并调用原生飞书 OpenAPI 时使用。

