fix(next/image): handle invalid url (#67465)

This commit is contained in:
Steven 2024-07-04 15:55:32 -04:00 committed by GitHub
parent 38b3423160
commit 28fc89448f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View file

@ -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('/')) {

View file

@ -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 }