Middleware that resolves trusted client IPs and enforces rate limits using a KV store, with a QA kill switch.
// Source: https://github.com/doable-me/Doable | License: MIT | Copyright 2026 Doable Works LLC
// Provided via justclaw.it.com; keep this notice with the code.
import { createMiddleware } from "hono/factory";
import { recordSpan } from "../integrations/xray.js";
import { getKVStore } from "@doable/shared/kv-store.js";
interface RateLimitOptions {
/** Time window in milliseconds */
windowMs: number;
/** Max requests per window */
max: number;
/** Custom key extractor (defaults to trusted-source IP) */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
keyGenerator?: (c: any) => string;
/** Namespace prefix for KV keys (avoids collisions) */
prefix?: string;
}
/**
* Resolve the client IP from a trusted source.
*
* BUG-CORPUS-SEC-001 (rate-limit bypass): we
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key