Files
next.js/test/e2e/next-image-src-with-query-without-local-patterns/next-image-src-with-query-without-local-patterns.test.ts
8041a382c9 [Breaking] Require images.localPatterns for query in Image src (#84406)
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]>
2025-10-09 21:01:42 +02:00

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'
)
}
})
})