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

Handle `Origin: null` headers (#85402)

parent b55e52f1
...@@ -551,9 +551,10 @@ export async function handleAction({ ...@@ -551,9 +551,10 @@ export async function handleAction({
// When running actions the default is no-store, you can still `cache: 'force-cache'` // When running actions the default is no-store, you can still `cache: 'force-cache'`
workStore.fetchCache = 'default-no-store' workStore.fetchCache = 'default-no-store'
const originHeader = req.headers['origin']
const originDomain = const originDomain =
typeof req.headers['origin'] === 'string' typeof originHeader === 'string' && originHeader !== 'null'
? new URL(req.headers['origin']).host ? new URL(originHeader).host
: undefined : undefined
const host = parseHostHeader(req.headers) const host = parseHostHeader(req.headers)
......
...@@ -85,7 +85,7 @@ export const blockCrossSite = ( ...@@ -85,7 +85,7 @@ export const blockCrossSite = (
// ensure websocket requests from allowed origin // ensure websocket requests from allowed origin
const rawOrigin = req.headers['origin'] const rawOrigin = req.headers['origin']
if (rawOrigin) { if (rawOrigin && rawOrigin !== 'null') {
const parsedOrigin = parseUrl(rawOrigin) const parsedOrigin = parseUrl(rawOrigin)
if (parsedOrigin) { if (parsedOrigin) {
......
...@@ -26,4 +26,17 @@ describe('app-dir action allowed origins', () => { ...@@ -26,4 +26,17 @@ describe('app-dir action allowed origins', () => {
return await browser.elementByCss('#res').text() return await browser.elementByCss('#res').text()
}, 'hi') }, 'hi')
}) })
it('should not crash for requests from privacy sensitive contexts', async function () {
const res = await next.fetch('/', {
method: 'POST',
headers: {
Origin: 'null',
'Content-type': 'application/x-www-form-urlencoded',
'Sec-Fetch-Site': 'same-origin',
},
})
expect({ status: res.status }).toEqual({ status: 200 })
})
}) })
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