Skip to content

Commit 8818510

Browse files
committed
fix: throw request limit early
1 parent ac4c43c commit 8818510

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

packages/auth-server-api/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ app.get("/api/health", (_req: Request, res: Response) => {
3535
res.json({ status: "ok", timestamp: new Date().toISOString() });
3636
});
3737

38-
// Deploy account endpoint (with Prividium auth middleware when enabled, plus rate limiting)
39-
app.post("/api/deploy-account", prividiumAuthMiddleware(prividiumConfig), deployLimiter, deployAccountHandler);
38+
// Deploy account endpoint (rate limiting first, then auth, then handler)
39+
app.post("/api/deploy-account", deployLimiter, prividiumAuthMiddleware(prividiumConfig), deployAccountHandler);
4040

4141
// Global error handler
4242
// eslint-disable-next-line @typescript-eslint/no-unused-vars

packages/auth-server-api/src/middleware/rate-limit.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { rateLimitConfig } from "../config.js";
55

66
/**
77
* Rate limiter for the deploy-account endpoint.
8-
* Uses Prividium userId when available, falls back to IP address.
8+
* Runs before authentication to avoid expensive operations when rate limited.
9+
* Uses IP-based limiting.
910
*/
1011
export const deployLimiter = rateLimit({
1112
windowMs: rateLimitConfig.deployWindowMs,
@@ -14,11 +15,6 @@ export const deployLimiter = rateLimit({
1415
legacyHeaders: false,
1516
message: { error: "Deployment rate limit exceeded, please try again later" },
1617
keyGenerator: (req: Request) => {
17-
// Use Prividium userId if available for per-user limiting
18-
if (req.prividiumUser?.userId) {
19-
return `user:${req.prividiumUser.userId}`;
20-
}
21-
// Fall back to IP address when Prividium is disabled
2218
return req.ip || req.socket.remoteAddress || "unknown";
2319
},
2420
});

0 commit comments

Comments
 (0)