Skip to content

Commit

Permalink
max depth limit
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Feb 5, 2024
1 parent 4c91e02 commit 5c75071
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/next/src/server/web/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ export const run = withTaggedErrors(async function runWithTaggedErrors(params) {
const runtime = await getRuntimeContext(params)
const subreq = params.request.headers[`x-middleware-subrequest`]
const subrequests = typeof subreq === 'string' ? subreq.split(':') : []
const allowSubrequests = params.request.headers[`x-middleware-allow-subrequests`] === "true"
if (subrequests.includes(params.name) && !allowSubrequests) {

const MAX_RECURSION_DEPTH = 5
const depth = subrequests.reduce(
(acc, curr) => (curr === params.name ? acc + 1 : acc),
0
)

if (depth > MAX_RECURSION_DEPTH) {
return {
waitUntil: Promise.resolve(),
response: new runtime.context.Response(null, {
Expand Down

0 comments on commit 5c75071

Please sign in to comment.