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
02fe7cf6
Commit
02fe7cf6
authored
Jun 01, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-dir-traversal-error'
parents
442c611d
43c447ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
index.js
server/index.js
+18
-1
No files found.
server/index.js
View file @
02fe7cf6
import
{
resolve
,
join
}
from
'path'
import
{
resolve
,
join
,
sep
}
from
'path'
import
{
parse
as
parseUrl
}
from
'url'
import
{
parse
as
parseUrl
}
from
'url'
import
{
parse
as
parseQs
}
from
'querystring'
import
{
parse
as
parseQs
}
from
'querystring'
import
fs
from
'fs'
import
fs
from
'fs'
...
@@ -295,6 +295,10 @@ export default class Server {
...
@@ -295,6 +295,10 @@ export default class Server {
}
}
async
serveStatic
(
req
,
res
,
path
)
{
async
serveStatic
(
req
,
res
,
path
)
{
if
(
!
this
.
isServeableUrl
(
path
))
{
return
this
.
render404
(
req
,
res
)
}
try
{
try
{
return
await
serveStatic
(
req
,
res
,
path
)
return
await
serveStatic
(
req
,
res
,
path
)
}
catch
(
err
)
{
}
catch
(
err
)
{
...
@@ -306,6 +310,19 @@ export default class Server {
...
@@ -306,6 +310,19 @@ export default class Server {
}
}
}
}
isServeableUrl
(
path
)
{
const
resolved
=
resolve
(
path
)
if
(
resolved
.
indexOf
(
join
(
this
.
dir
,
this
.
dist
)
+
sep
)
!==
0
&&
resolved
.
indexOf
(
join
(
this
.
dir
,
'static'
)
+
sep
)
!==
0
)
{
// Seems like the user is trying to traverse the filesystem.
return
false
}
return
true
}
isInternalUrl
(
req
)
{
isInternalUrl
(
req
)
{
for
(
const
prefix
of
internalPrefixes
)
{
for
(
const
prefix
of
internalPrefixes
)
{
if
(
prefix
.
test
(
req
.
url
))
{
if
(
prefix
.
test
(
req
.
url
))
{
...
...
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