Skip to content

Commit

Permalink
version 0.10.1 Fixed directory traversal vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy98 committed Apr 27, 2017
1 parent 91da429 commit dfdd52e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/router.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -21,7 +21,7 @@
"async",
"promises"
],
"version": "0.10.0",
"version": "0.10.1",
"homepage": "http://node-simple-router.herokuapp.com",
"author": "Ernesto Savoretti <esavoretti@gmail.com>",
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions src/router.coffee
Expand Up @@ -613,6 +613,8 @@ Router = (options = {}) ->

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

dispatch._403 = (req, res, path, message) ->
res.writeHead(500, {'Content-Type': 'text/html'})
res.end("""
<h2>403 - Forbidden: #{message}</h2>
<hr/><h3>Served by #{dispatch.served_by} v#{dispatch.version}</h3>
<p style="text-align: center;"><button onclick='history.back();'>Back</button></p>
""")

dispatch._405 = (req, res, path, message) ->
res.writeHead(405, {'Content-Type': 'text/html'})
res.end("""
Expand Down

0 comments on commit dfdd52e

Please sign in to comment.