Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implemented possible solution for path traversal #28

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

Open
chris18191 wants to merge 5 commits into schenkd:dev-0.3
base: dev-0.3
Choose a base branch
Loading
from chris18191:master

Conversation

@chris18191
Copy link

@chris18191 chris18191 commented Jul 1, 2020

No description provided.

@schenkd schenkd self-requested a review July 1, 2020 17:13
@schenkd schenkd self-assigned this Jul 1, 2020
Copy link
Owner

@schenkd schenkd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Chris, thanks for your PR. It looks good and you're solving a problem for the v0.3 release, thanks for that!

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
Copy link
Owner

@schenkd schenkd Jul 1, 2020

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).

Copy link

@erikgeiser erikgeiser Jul 1, 2020
edited
Loading

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. And commonprefix takes an iterable and not variadic arguments so I think this errors out. Maybe use something like os.path.realpath(config_file).startswith(os.path.realpath(nginx_path) + os.sep) (though not as this ugly oneliner maybe).

schenkd and LucaNerlich reacted with thumbs up emoji

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
Copy link
Owner

@schenkd schenkd Jul 1, 2020
edited
Loading

Choose a reason for hiding this comment

The 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! :)

Copy link
Owner

@schenkd schenkd Jul 1, 2020
edited
Loading

Choose a reason for hiding this comment

The 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.'

<div class="ui cards" id="domain_cards">
{% if errorMessage %}
<div>
{{errorMessage}}
Copy link
Owner

@schenkd schenkd Jul 1, 2020
edited
Loading

Choose a reason for hiding this comment

The 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

@schenkd schenkd changed the base branch from master to dev-0.3 July 1, 2020 17:26
@schenkd schenkd assigned chris18191 and unassigned schenkd Jul 1, 2020
Copy link

It seems like you addressed the path traversal issue only in a single endpoint. Looking through endpoints.py, it seems that most API endpoints work rather similar an possibly share the same issue.

Copy link
Author

I added a new function to generate valid paths or return None if the path is not valid, e.g. it is no subdirectory of the given folder.
Errors can now also easily be visualized by calling rendeError, which makes use Semantics error message.

Copy link
Owner

schenkd commented Jul 2, 2020

I added a new function to generate valid paths or return None if the path is not valid, e.g. it is no subdirectory of the given folder.
Errors can now also easily be visualized by calling rendeError, which makes use Semantics error message.

@chris18191 First of all, thank you very much for your efforts. I see you're using lower camel-case everywhere. I did not want to mention every method in the review. Could you adapt it to the Python convention? Unfortunately, I will not be able to do an extensive review before the weekend.

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

Reviewers

@schenkd schenkd schenkd requested changes

+1 more reviewer

@erikgeiser erikgeiser erikgeiser left review comments

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Possible arbitrary file access though Path Traversal vulnerability in some situations

AltStyle によって変換されたページ (->オリジナル) /