Skip to content

Commit

Permalink
fix(next/image): handle invalid url
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jul 4, 2024
1 parent 38b3423 commit 81324b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/next/src/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ export class ImageOptimizerCache {
}
}

if (url.startsWith('/_next/image')) {
return {
errorMessage: '"url" parameter cannot be recursive',
}
}

let isAbsolute: boolean

if (url.startsWith('/')) {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/image-optimizer/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,13 @@ export function runTests(ctx: RunTestsCtx) {
)
})

it('should fail when url is recursive', async () => {
const query = { url: `/_next/image?url=test.pngw=1&q=1`, w: ctx.w, q: 1 }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
expect(res.status).toBe(400)
expect(await res.text()).toBe(`"url" parameter cannot be recursive`)
})

it('should fail when internal url is not an image', async () => {
const url = `/api/no-header`
const query = { url, w: ctx.w, q: 39 }
Expand Down

0 comments on commit 81324b5

Please sign in to comment.