Skip to content

Commit dfdd52e

Browse files
committed
version 0.10.1 Fixed directory traversal vulnerability
1 parent 91da429 commit dfdd52e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/router.js

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"async",
2222
"promises"
2323
],
24-
"version": "0.10.0",
24+
"version": "0.10.1",
2525
"homepage": "http://node-simple-router.herokuapp.com",
2626
"author": "Ernesto Savoretti <[email protected]>",
2727
"repository": {

src/router.coffee

+10
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ Router = (options = {}) ->
613613

614614
dispatch.static = (pathname, req, res) ->
615615
full_path = "#{dispatch.static_route}#{unescape(pathname)}"
616+
if full_path.indexOf('..') isnt -1
617+
return dispatch._403(null, res, pathname, "Trying to get private things through directory traversal is a nasty thing to do.")
616618
fs.exists full_path, (exists) ->
617619
if exists
618620
if ((pathname.indexOf("#{dispatch.cgi_dir}/") isnt - 1) or (pathname.match /\.php$/)) and (pathname.substr(-1) isnt "/") and (dispatch.serve_cgi is true)
@@ -1002,6 +1004,14 @@ Router = (options = {}) ->
10021004
else
10031005
res.end data
10041006

1007+
dispatch._403 = (req, res, path, message) ->
1008+
res.writeHead(500, {'Content-Type': 'text/html'})
1009+
res.end("""
1010+
<h2>403 - Forbidden: #{message}</h2>
1011+
<hr/><h3>Served by #{dispatch.served_by} v#{dispatch.version}</h3>
1012+
<p style="text-align: center;"><button onclick='history.back();'>Back</button></p>
1013+
""")
1014+
10051015
dispatch._405 = (req, res, path, message) ->
10061016
res.writeHead(405, {'Content-Type': 'text/html'})
10071017
res.end("""

0 commit comments

Comments
 (0)