Unverified Commit 0be95ebf authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

fix(fetch-cache): key fetch(Request, init) by the effective request (#96009)

https://github.com/vercel/next.js/security/advisories/GHSA-68g3-v927-f742Co-authored-by: 's avatarKarim Rahal <karim@karimrahal.com>
parent 025bf4a5
...@@ -374,6 +374,18 @@ export function createPatchedFetcher( ...@@ -374,6 +374,18 @@ export function createPatchedFetcher(
typeof input === 'object' && typeof input === 'object' &&
typeof (input as Request).method === 'string' typeof (input as Request).method === 'string'
// With `fetch(new Request(url), init)`, native fetch lets `init`
// override the base Request. Merge them into a single effective Request
// so cacheability, the cache key, and the upstream request all describe
// the same thing.
if (isRequestInput && init) {
// `next` (revalidate/tags) is Next-specific and dropped by
// `new Request`, so keep it on `init` and move the rest onto input.
const { next, ...overrides } = init
input = new Request(input as Request, overrides)
init = next ? { next } : undefined
}
const getRequestMeta = (field: string) => { const getRequestMeta = (field: string) => {
// If request input is present but init is not, retrieve from input first. // If request input is present but init is not, retrieve from input first.
const value = (init as any)?.[field] const value = (init as any)?.[field]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment