mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This PR modifies Image behavior to require `images.localPatterns.search`
value when used with search queries in the `src` property:
```jsx
// Error
<Image src="/api/user?id=1" width="50" height="50" />
```
```ts
// next.config.ts
export default {
images: {
localPatterns: [
{
pathname: '/api/user',
// Either set explicit query string or leave undefined to match all
search: '?v=2',
},
],
},
}
```
It is to prevent malicious actors like Denial of Wallet (DoW) attacks
and strictly match the search queries for image optimization.
The deprecation warning was added at
https://github.com/vercel/next.js/pull/82627
---------
Co-authored-by: Steven <[email protected]>
29 lines
1003 B
TypeScript
29 lines
1003 B
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('next-image-src-with-query-without-local-patterns', () => {
|
|
const { next, isNextDev, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
it('should throw error for relative image with query without localPatterns', async () => {
|
|
if (isNextDev) {
|
|
await next.start()
|
|
await next.browser('/')
|
|
expect(next.cliOutput).toContain(
|
|
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
|
|
)
|
|
} else {
|
|
const { cliOutput } = await next.build()
|
|
expect(cliOutput).toContain(
|
|
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
|
|
)
|
|
}
|
|
})
|
|
})
|