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
8c8c08ac
Commit
8c8c08ac
authored
Jan 24, 2018
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply the fix for the path traversal security issue.
More info:
https://github.com/zeit/next.js/releases/tag/4.2.3
parent
aa096257
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
index.js
server/index.js
+1
-0
render.js
server/render.js
+21
-2
index.test.js
test/integration/production/test/index.test.js
+16
-0
No files found.
server/index.js
View file @
8c8c08ac
...
@@ -55,6 +55,7 @@ export default class Server {
...
@@ -55,6 +55,7 @@ export default class Server {
dev
,
dev
,
staticMarkup
,
staticMarkup
,
dir
:
this
.
dir
,
dir
:
this
.
dir
,
dist
:
this
.
dist
,
hotReloader
:
this
.
hotReloader
,
hotReloader
:
this
.
hotReloader
,
buildStats
:
this
.
buildStats
,
buildStats
:
this
.
buildStats
,
buildId
:
this
.
buildId
,
buildId
:
this
.
buildId
,
...
...
server/render.js
View file @
8c8c08ac
import
{
join
}
from
'path'
import
{
join
,
sep
}
from
'path'
import
{
existsSync
}
from
'fs'
import
{
existsSync
}
from
'fs'
import
{
createElement
}
from
'react'
import
{
createElement
}
from
'react'
import
{
renderToString
,
renderToStaticMarkup
}
from
'react-dom/server'
import
{
renderToString
,
renderToStaticMarkup
}
from
'react-dom/server'
...
@@ -122,18 +122,37 @@ async function doRender (req, res, pathname, query, {
...
@@ -122,18 +122,37 @@ async function doRender (req, res, pathname, query, {
return
'<!DOCTYPE html>'
+
renderToStaticMarkup
(
doc
)
return
'<!DOCTYPE html>'
+
renderToStaticMarkup
(
doc
)
}
}
function
isServeableUrl
(
path
,
opts
)
{
if
(
path
.
indexOf
(
join
(
opts
.
dir
,
opts
.
dist
)
+
sep
)
!==
0
&&
path
.
indexOf
(
join
(
opts
.
dir
,
'static'
)
+
sep
)
!==
0
)
{
// Seems like the user is trying to traverse the filesystem.
return
false
}
return
true
}
export
async
function
renderScript
(
req
,
res
,
page
,
opts
)
{
export
async
function
renderScript
(
req
,
res
,
page
,
opts
)
{
try
{
try
{
const
dist
=
getConfig
(
opts
.
dir
).
distDir
const
dist
=
getConfig
(
opts
.
dir
).
distDir
const
path
=
join
(
opts
.
dir
,
dist
,
'bundles'
,
'pages'
,
page
)
const
path
=
join
(
opts
.
dir
,
dist
,
'bundles'
,
'pages'
,
page
)
const
realPath
=
await
resolvePath
(
path
)
const
realPath
=
await
resolvePath
(
path
)
if
(
!
isServeableUrl
(
realPath
,
opts
))
{
res
.
statusCode
=
404
res
.
end
(
'404'
)
return
}
await
serveStatic
(
req
,
res
,
realPath
)
await
serveStatic
(
req
,
res
,
realPath
)
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
err
.
code
===
'ENOENT'
)
{
if
(
err
.
code
===
'ENOENT'
)
{
renderScriptError
(
req
,
res
,
page
,
err
,
{},
opts
)
renderScriptError
(
req
,
res
,
page
,
err
,
{},
opts
)
return
return
}
}
throw
err
throw
err
}
}
}
}
...
...
test/integration/production/test/index.test.js
View file @
8c8c08ac
...
@@ -13,6 +13,7 @@ import {
...
@@ -13,6 +13,7 @@ import {
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
fetch
from
'node-fetch'
import
fetch
from
'node-fetch'
import
dynamicImportTests
from
'../../basic/test/dynamic'
import
dynamicImportTests
from
'../../basic/test/dynamic'
import
{
readFileSync
}
from
'fs'
const
appDir
=
join
(
__dirname
,
'../'
)
const
appDir
=
join
(
__dirname
,
'../'
)
let
appPort
let
appPort
...
@@ -110,6 +111,21 @@ describe('Production Usage', () => {
...
@@ -110,6 +111,21 @@ describe('Production Usage', () => {
const
data
=
await
renderViaHTTP
(
appPort
,
'/static/data/item.txt'
)
const
data
=
await
renderViaHTTP
(
appPort
,
'/static/data/item.txt'
)
expect
(
data
).
toBe
(
'item'
)
expect
(
data
).
toBe
(
'item'
)
})
})
it
(
'should only access files inside .next directory'
,
async
()
=>
{
const
buildId
=
readFileSync
(
join
(
__dirname
,
'../.next/BUILD_ID'
),
'utf8'
)
const
pathsToCheck
=
[
`/_next/
${
buildId
}
/page/../../../info`
,
`/_next/
${
buildId
}
/page/../../../info.js`
,
`/_next/
${
buildId
}
/page/../../../info.json`
]
for
(
const
path
of
pathsToCheck
)
{
const
data
=
await
renderViaHTTP
(
appPort
,
path
)
expect
(
data
.
includes
(
'cool-version'
)).
toBeFalsy
()
}
})
})
})
describe
(
'X-Powered-By header'
,
()
=>
{
describe
(
'X-Powered-By header'
,
()
=>
{
...
...
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