fix(proxy): reject malformed server-action requests to reduce CPU spikes
CI / check (push) Successful in 29s
CI / tests-unit (push) Successful in 1m55s
CI / tests-integration (push) Successful in 1m59s
CI / tests-quality (push) Successful in 50s
CI / tests-imaging-browsers (push) Successful in 3m42s
CI / tests-ui (push) Successful in 4m49s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 4m12s
CI / check (push) Successful in 29s
CI / tests-unit (push) Successful in 1m55s
CI / tests-integration (push) Successful in 1m59s
CI / tests-quality (push) Successful in 50s
CI / tests-imaging-browsers (push) Successful in 3m42s
CI / tests-ui (push) Successful in 4m49s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 4m12s
This commit is contained in:
1 parent
1ad4f9ea28
commit
a878d831aa
1 file changed
+8
@@ -19,6 +19,14 @@ const SECURITY_HEADERS: Record<string, string> = {
|
||||
};
|
||||
|
||||
export const proxy = async (req: import("next/server").NextRequest) => {
|
||||
// Server actions carry an opaque action id in this header. A malformed or
|
||||
// trivially short id (e.g. "x" sent by bots) can never resolve to a real
|
||||
// action; rejecting it here avoids the expensive lookup/render path.
|
||||
const nextAction = req.headers.get("next-action");
|
||||
if (nextAction && !/^[A-Za-z0-9_-]{8,}$/.test(nextAction)) {
|
||||
return new NextResponse(null, { status: 400 });
|
||||
}
|
||||
|
||||
const decision = await enforceDdosRateLimit(req);
|
||||
if (decision.outcome === "suspect") {
|
||||
return ddosReject(403);
|
||||
|
||||
Reference in new issue
Block a user