- d6e8d2f: Optimize bundle size by excluding test files and source maps from published package
- babdcf3: Security & algorithm improvements:
- Switch to sliding window timestamps (more accurate rate limiting)
- Add IP validation/sanitization to prevent header injection
- Add
failOpenoption (default: true) for cache failures - Add
Retry-AfterandX-RateLimit-Resetheaders - Export
isValidIp,normalizeIp,sanitizeIputilities - Upgrade to Medusa 2.13.0 compatibility
- dfc39e3: Fixed the default ip-rate-limit middleware and do not use the x-forwarded-for header for the direct connection ip address instead
-
5e0ee7a: V3 - Revamped the whole way we rate limit apps. Introducing the
RateLimitclass for more granular control.Breaking Changes:
- The
defaultRateLimitmiddleware has been removed - Global configuration has been removed
New Features:
- Introduction of the
RateLimitclass for programmatic rate limiting - Built-in
ipRateLimitmiddleware for common IP-based rate limiting - Support for custom identifiers beyond IP addresses
- More granular control over rate limiting logic
The core of V3 is the new
RateLimitclass that gives you programmatic control over rate limiting. This class integrates directly with Medusa's cache service and allows you to implement custom rate limiting logic.import { defineMiddlewares } from "@medusajs/medusa"; import { RateLimit } from "@perseidesjs/medusa-plugin-rate-limit"; import { Modules } from "@medusajs/framework/utils"; export default defineMiddlewares({ routes: [ { matcher: "/store/custom*", middlewares: [ async ( req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction, ) => { const cacheService = req.scope.resolve(Modules.CACHE); const rateLimit = new RateLimit({ cacheService, options: { limit: 50, // 50 requests per minute window: 60, }, }); const ip = req.headers["x-forwarded-for"] as string; const { success } = await rateLimit.limit(ip); if (!success) { res .status(429) .send("Too many requests, please try again later."); return; } next(); }, ], }, ], });
- The
- ceb1e9b: Increased defaults values to
limitandwindow
- 0aaa241: Fixed README.md on NPM
- 0f909a4: Upgraded dependencies
- ca6b93a: - Upgraded devDependencies and Medusa peer dependency