New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static file register arbitrary file read #633

Closed
yeahx opened this Issue Apr 13, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@yeahx
Contributor

yeahx commented Apr 13, 2017

File sanic/sanic/static.py line 46
we can see here is security check

43    async def _handler(request, file_uri=None):
44        # Using this to determine if the URL is trying to break out of the path
45        # served.  os.path.realpath seems to be very slow
46        if file_uri and '../' in file_uri:
47            raise InvalidUsage("Invalid URL")

but at the line 56 in this file,the unquote function decoded file_path
file_path = unquote(file_path)
we only need to "/" url coding can bypass the previous security check
like this:
image

example of vulnerabilities:

#!/usr/bin/env python
#-*- coding:utf-8 -*-
#author: lazyago@gmail.com
from sanic import Sanic
from sanic.response import text


app = Sanic()

app.static('/static', '/var/tmp')

@app.route("/")
async def test(request):
    return text('Hello!')

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8787, debug=True)
@go2sh

This comment has been minimized.

Show comment
Hide comment
@go2sh

go2sh commented Apr 14, 2017

Autsch.

@seemethere

This comment has been minimized.

Show comment
Hide comment
@seemethere

seemethere Apr 14, 2017

Member

Closed with #635

Member

seemethere commented Apr 14, 2017

Closed with #635

@seemethere seemethere closed this Apr 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment