Skip to content

Commit

Permalink
fix(next/image): set max url length to 3072 (#65457)
Browse files Browse the repository at this point in the history
This PR sets the maximum `url` parameter length to 3072 for image
optimization.

Closes NEXT-3348
  • Loading branch information
styfle committed May 7, 2024
1 parent 5a76ac9 commit 1f598bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/next/src/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export class ImageOptimizerCache {
return { errorMessage: '"url" parameter cannot be an array' }
}

if (url.length > 3072) {
return { errorMessage: '"url" parameter is too long' }
}

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 @@ -982,6 +982,13 @@ export function runTests(ctx: RunTestsCtx) {
expect(await res.text()).toBe(`"url" parameter is invalid`)
})

it('should fail when url is too long', async () => {
const query = { url: `/${'a'.repeat(4000)}`, 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 is too long`)
})

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

0 comments on commit 1f598bc

Please sign in to comment.