Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/middleware/rateLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ setInterval(() => {

/**
* Get rate limit key from request
* Note: This runs BEFORE requireAuth, so we must read directly from headers
*/
function getKey(req, limitType) {
const identifier = req.token || req.ip || 'anonymous';
// Extract token directly from header since req.token isn't set yet
const auth = req.headers.authorization;
const token = auth && auth.startsWith('Bearer ') ? auth.slice(7) : null;
const identifier = token || req.ip || 'anonymous';
return `rl:${limitType}:${identifier}`;
}

Expand Down