Skip to content

Commit 1f598bc

Browse files
authored
fix(next/image): set max url length to 3072 (#65457)
This PR sets the maximum `url` parameter length to 3072 for image optimization. Closes NEXT-3348
1 parent 5a76ac9 commit 1f598bc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/next/src/server/image-optimizer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ export class ImageOptimizerCache {
188188
return { errorMessage: '"url" parameter cannot be an array' }
189189
}
190190

191+
if (url.length > 3072) {
192+
return { errorMessage: '"url" parameter is too long' }
193+
}
194+
191195
let isAbsolute: boolean
192196

193197
if (url.startsWith('/')) {

test/integration/image-optimizer/test/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,13 @@ export function runTests(ctx: RunTestsCtx) {
982982
expect(await res.text()).toBe(`"url" parameter is invalid`)
983983
})
984984

985+
it('should fail when url is too long', async () => {
986+
const query = { url: `/${'a'.repeat(4000)}`, w: ctx.w, q: 1 }
987+
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
988+
expect(res.status).toBe(400)
989+
expect(await res.text()).toBe(`"url" parameter is too long`)
990+
})
991+
985992
it('should fail when internal url is not an image', async () => {
986993
const url = `//<h1>not-an-image</h1>`
987994
const query = { url, w: ctx.w, q: 39 }

0 commit comments

Comments
 (0)