Commit b2d71bfd authored by Steven's avatar Steven

Add `frame-src` CSP header to image optimziation api

parent 8a5e1ceb
......@@ -608,7 +608,10 @@ export function setResponseHeaders(
)
}
res.setHeader('Content-Security-Policy', `script-src 'none'; sandbox;`)
res.setHeader(
'Content-Security-Policy',
`script-src 'none'; frame-src 'none'; sandbox;`
)
res.setHeader('X-Nextjs-Cache', xCache)
return { finished: false }
......
<svg width="960" height="850">
<g transform="translate(300, 0) rotate(20)">
<foreignObject x="10" y="10" width="800" height="800">
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe id="iframe" style="opacity:0;visibilty:hidden;" width="1px" height="1px;" src="http://127.0.0.1:5243/embed"></iframe>
</body>
</foreignObject>
</g>
</svg>
\ No newline at end of file
......@@ -47,6 +47,7 @@ describe('Production Usage', () => {
NODE_OPTIONS: '--no-addons',
}
}
await fs.remove(join(appDir, '.next', 'cache', 'images'))
const result = await nextBuild(appDir, undefined, opts)
appPort = await findPort()
......
......@@ -337,6 +337,37 @@ module.exports = (context) => {
if (browser) await browser.close()
}
})
it('should not execute iframe embedded inside svg image', async () => {
let wasInvoked = false
const server = http
.createServer((req, res) => {
const { method, pathname } = req
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Headers', '*')
if (method === 'OPTIONS') {
res.end(200)
return
}
wasInvoked = true
console.log(JSON.stringify({ method, pathname }))
res.end(JSON.stringify({ method, pathname }))
})
.listen(5243)
try {
const browser = await webdriver(
context.appPort,
'/_next/image?url=%2Fiframe.svg&w=256&q=75'
)
expect(await browser.elementById('iframe').getAttribute('src')).toBe(
'http://127.0.0.1:5243/embed'
)
expect(wasInvoked).toBe(false)
} finally {
server.close()
}
})
}
})
}
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