-
Notifications
You must be signed in to change notification settings - Fork 276
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
Implemented possible solution for path traversal #28
base: dev-0.3
Are you sure you want to change the base?
Changes from 2 commits
c26e5e2
4b16c9b
e55c8b8
f09f1d0
dedde58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,12 @@ def post_config(name: str): | |
content = flask.request.get_json() | ||
nginx_path = flask.current_app.config['NGINX_PATH'] | ||
|
||
with io.open(os.path.join(nginx_path, name), 'w') as f: | ||
config_file = os.path.join(nginx_path, name) | ||
|
||
if not os.path.commonprefix(os.path.realpath(config_file), nginx_path): | ||
return flask.make_response({'success': False}), 200 | ||
|
||
with io.open(config_file, 'w') as f: | ||
f.write(content['file']) | ||
|
||
return flask.make_response({'success': True}), 200 | ||
|
@@ -57,6 +62,9 @@ def get_domains(): | |
sites_available = [] | ||
sites_enabled = [] | ||
|
||
if not os.path.exists(config_path): | ||
errorMessage = 'The config folder "{}" does not exists.'.format(config_path) | ||
return flask.render_template('domains.html', errorMessage=errorMessage, sites_available=(), sites_enabled=()), 200 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Classic case of Java developer. Lower CamelCase is uncommon in Python. error_message would be nice! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also like to have the string formatting with f-string syntax. Then it will be consistent in the code. error_message = f'The config folder "{config_path}" doesn't exists.' |
||
for _ in os.listdir(config_path): | ||
|
||
if os.path.isfile(os.path.join(config_path, _)): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
<div class="column"> | ||
|
||
<div class="ui cards" id="domain_cards"> | ||
{% if errorMessage %} | ||
<div> | ||
{{errorMessage}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is functional, but you could enhance it with a message from the semantic framework. Here is a link to the component: Error Messages |
||
</div> | ||
{% endif %} | ||
{% if sites_available %} | ||
{% for domain in sites_available %} | ||
<div class="card"> | ||
|
@@ -30,4 +35,4 @@ | |
<!-- file content --> | ||
</div> | ||
|
||
</div> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would choose a different status code. For example a 400 (Bad Request) or 403 (Forbidden).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that
os.path.commonprefix(("/a/b", "/c/d"))
returns"/"
which is truthy, so the condition is not met. Andcommonprefix
takes an iterable and not variadic arguments so I think this errors out. Maybe use something likeos.path.realpath(config_file).startswith(os.path.realpath(nginx_path) + os.sep)
(though not as this ugly oneliner maybe).