Commit cd7f5c26 authored by Leo Iannacone's avatar Leo Iannacone

better code to forbid accesses to chroots

parent c931a2a0
...@@ -45,25 +45,18 @@ if config.routes.commands ...@@ -45,25 +45,18 @@ if config.routes.commands
# debomatic static page # debomatic static page
if config.routes.debomatic if config.routes.debomatic
app.all config.routes.debomatic + "*", (req, res, next) -> chroot_forbidden = (res) ->
# send 403 status when users want to browse the chroots:
# - unstable/unstable
# - unstable/build/*
# this prevents system crashes
base = config.routes.debomatic
base += "/" if base[base.length - 1] isnt "/" # append /
match = req.url.replace(base, "").split("/")
match.pop() if match[match.length - 1] is ""
if match.length >= 2 and
((match[0] is match[1]) or # case unstable/unstable
(match[1] is "build" and match.length > 2)) # case unstable/build/*
res.status(403).send """<h1>403 Forbidden</h1> res.status(403).send """<h1>403 Forbidden</h1>
<h2>You cannot see the chroot internals</h2> <h2>You cannot see the chroot internals</h2>"""
"""
else # call next() here to move on to next middleware/router app.get config.routes.debomatic + '/:distribution/:subdir', (req, res, next) ->
if req.params.distribution == req.params.subdir
chroot_forbidden(res)
else
next() next()
return
app.get config.routes.debomatic + '/:distribution/build/:subdir', (req, res) ->
chroot_forbidden(res)
app.get config.routes.debomatic + '/:distribution/logs/:file', (req, res) -> app.get config.routes.debomatic + '/:distribution/logs/:file', (req, res) ->
distribution = req.params.distribution distribution = req.params.distribution
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment