File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed
test/integration/image-component/default Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -525,6 +525,8 @@ function setResponseHeaders(
525
525
res . setHeader ( 'Content-Disposition' , `inline; filename="${ fileName } "` )
526
526
}
527
527
528
+ res . setHeader ( 'Content-Security-Policy' , `script-src 'none'; sandbox;` )
529
+
528
530
return { finished : false }
529
531
}
530
532
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Image from 'next/image'
3
+
4
+ const Page = ( ) => {
5
+ return (
6
+ < div >
7
+ < h1 > SVG with a script tag attempting XSS</ h1 >
8
+ < Image id = "img" src = "/xss.svg" width = "100" height = "100" />
9
+ < p id = "msg" > safe</ p >
10
+ </ div >
11
+ )
12
+ }
13
+
14
+ export default Page
Original file line number Diff line number Diff line change @@ -229,6 +229,28 @@ function runTests(mode) {
229
229
}
230
230
} )
231
231
232
+ it ( 'should not execute scripts inside svg image' , async ( ) => {
233
+ let browser
234
+ try {
235
+ browser = await webdriver ( appPort , '/xss-svg' )
236
+ await browser . eval ( `document.getElementById("img").scrollIntoView()` )
237
+ expect ( await browser . elementById ( 'img' ) . getAttribute ( 'src' ) ) . toContain (
238
+ 'xss.svg'
239
+ )
240
+ expect ( await browser . elementById ( 'msg' ) . text ( ) ) . toBe ( 'safe' )
241
+
242
+ browser = await webdriver (
243
+ appPort ,
244
+ '/_next/image?url=%2Fxss.svg&w=256&q=75'
245
+ )
246
+ expect ( await browser . elementById ( 'msg' ) . text ( ) ) . toBe ( 'safe' )
247
+ } finally {
248
+ if ( browser ) {
249
+ await browser . close ( )
250
+ }
251
+ }
252
+ } )
253
+
232
254
it ( 'should work when using flexbox' , async ( ) => {
233
255
let browser
234
256
try {
You can’t perform that action at this time.
0 commit comments