Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7afc97c5
Unverified
Commit
7afc97c5
authored
Aug 30, 2021
by
Steven
Committed by
GitHub
Aug 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CSP to Image Optimization API (#28620)
Add CSP header to Image Optimization API
parent
8711c5ca
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
1 deletion
+45
-1
image-optimizer.ts
packages/next/server/image-optimizer.ts
+2
-0
svg-image.js
test/integration/production/pages/svg-image.js
+14
-0
xss.svg
test/integration/production/public/xss.svg
+9
-0
index.test.js
test/integration/production/test/index.test.js
+1
-1
security.js
test/integration/production/test/security.js
+19
-0
No files found.
packages/next/server/image-optimizer.ts
View file @
7afc97c5
...
@@ -525,6 +525,8 @@ function setResponseHeaders(
...
@@ -525,6 +525,8 @@ function setResponseHeaders(
res
.
setHeader
(
'Content-Disposition'
,
`inline; filename="
${
fileName
}
"`
)
res
.
setHeader
(
'Content-Disposition'
,
`inline; filename="
${
fileName
}
"`
)
}
}
res
.
setHeader
(
'Content-Security-Policy'
,
`script-src 'none'; sandbox;`
)
return
{
finished
:
false
}
return
{
finished
:
false
}
}
}
...
...
test/integration/production/pages/svg-image.js
0 → 100644
View file @
7afc97c5
import
React
from
'react'
import
Image
from
'next/image'
const
Page
=
()
=>
{
return
(
<
div
>
<
h1
>
SVG
with
a
script
tag
attempting
XSS
<
/h1
>
<
Image
id
=
"img"
src
=
"/xss.svg"
width
=
"100"
height
=
"100"
/>
<
p
id
=
"msg"
>
safe
<
/p
>
<
/div
>
)
}
export
default
Page
test/integration/production/public/xss.svg
0 → 100644
View file @
7afc97c5
<html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<title>
XSS
</title>
</head>
<body>
<p
id=
"msg"
>
safe
</p>
<script>
document.getElementById('msg').textContent='hacked'
</script>
</body>
</html>
test/integration/production/test/index.test.js
View file @
7afc97c5
...
@@ -78,7 +78,7 @@ describe('Production Usage', () => {
...
@@ -78,7 +78,7 @@ describe('Production Usage', () => {
})
})
it
(
'should contain generated page count in output'
,
async
()
=>
{
it
(
'should contain generated page count in output'
,
async
()
=>
{
const
pageCount
=
process
.
env
.
NEXT_PRIVATE_TEST_WEBPACK4_MODE
?
3
7
:
38
const
pageCount
=
process
.
env
.
NEXT_PRIVATE_TEST_WEBPACK4_MODE
?
3
8
:
39
expect
(
output
).
toContain
(
`Generating static pages (0/
${
pageCount
}
)`
)
expect
(
output
).
toContain
(
`Generating static pages (0/
${
pageCount
}
)`
)
expect
(
output
).
toContain
(
expect
(
output
).
toContain
(
`Generating static pages (
${
pageCount
}
/
${
pageCount
}
)`
`Generating static pages (
${
pageCount
}
/
${
pageCount
}
)`
...
...
test/integration/production/test/security.js
View file @
7afc97c5
...
@@ -342,5 +342,24 @@ module.exports = (context) => {
...
@@ -342,5 +342,24 @@ module.exports = (context) => {
expect
(
pathname
).
toBe
(
'/%2fexample.com'
)
expect
(
pathname
).
toBe
(
'/%2fexample.com'
)
expect
(
hostname
).
not
.
toBe
(
'example.com'
)
expect
(
hostname
).
not
.
toBe
(
'example.com'
)
})
})
it
(
'should not execute script embedded inside svg image'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/svg-image'
)
await
browser
.
eval
(
`document.getElementById("img").scrollIntoView()`
)
expect
(
await
browser
.
elementById
(
'img'
).
getAttribute
(
'src'
)).
toContain
(
'xss.svg'
)
expect
(
await
browser
.
elementById
(
'msg'
).
text
()).
toBe
(
'safe'
)
browser
=
await
webdriver
(
context
.
appPort
,
'/_next/image?url=%2Fxss.svg&w=256&q=75'
)
expect
(
await
browser
.
elementById
(
'msg'
).
text
()).
toBe
(
'safe'
)
}
finally
{
if
(
browser
)
await
browser
.
close
()
}
})
})
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment