Skip to content

Commit

Permalink
Fix: prevent to traverse up the root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Aug 31, 2024
1 parent 5fcca27 commit 0aca9f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 3 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Now
- command line argument to set any option
- all todos
- all fixmes
- readme
- header is too large, decrease the header size

## later
- readme
# cache assets
10 changes: 10 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ def test_server_notfound(ymdapp, ymdserver, mockupfs):

when(url='/bar.md')
assert status == 404


def test_server_unauthorized(ymdapp, ymdserver, mockupfs):
root = mockupfs(**{
'index.md': '# index',
})
ymdapp.settings.root = root
ymdapp.ready()
with ymdserver('/../foo'):
assert status == 403
5 changes: 3 additions & 2 deletions yhttp/markdown/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def info(req):
)


# TODO: cache
@app.route('/index.css')
@sass
def get(req, path=None):
Expand Down Expand Up @@ -102,7 +101,9 @@ def notfound(req, path, **kw):

@y.html
def get(req, path=None):
# FIXME: (security) prevent to get parent directories
if '..' in path:
raise y.statuses.forbidden()

targetpath = os.path.join(cfg.root, path or '')
targetfile = None

Expand Down
1 change: 0 additions & 1 deletion yhttp/markdown/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def extractdir(root, directory, depth=6):
subdirs = []
root = os.path.abspath(root)

# FIXME: prevent to traverse up
dirpath = os.path.join(root, directory)
for item in sorted(os.listdir(dirpath)):
if SYSFILES.match(item):
Expand Down

0 comments on commit 0aca9f3

Please sign in to comment.