Skip to content
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

[security] Path traversal due to incorrect input sanitization. #3

Merged
merged 1 commit into from
Nov 30, 2021
Merged

[security] Path traversal due to incorrect input sanitization. #3

merged 1 commit into from
Nov 30, 2021

Conversation

porcupineyhairs
Copy link
Contributor

@porcupineyhairs porcupineyhairs commented Nov 21, 2021

Vulnerability Report

Summary

There exists a path traversal vulnerability in the /<path:url>/<path:filename> route. This occurs as attacker controlled values are used directly in the send_from_directory call.

The vulnerability can be attributed to the following block of code.

@app.route("/<path:url>/<path:filename>")
def downloader(url,filename):
dirpath = os.path.join(app.root_path, url) # 下载文件目录路径
return send_from_directory(dirpath, filename, as_attachment=True) # as_attachment=True 一定要写,不然会变成打开,而不是下载

os.path.join call is not safe when used with untrusted input. It does not behave well when linux and windows file schemes are mixed and can lead to path traversal vulnerabilities.

Remediation

The code in this PR should fix the underlying issue.

GitHub Security Advisories

If possible, please could you create a GitHub Security Advisory for these findings?
When you use a GitHub Security Advisory, you can request a CVE identification number from GitHub. GitHub usually reviews the request within 72 hours, and the CVE details will be published after you make your security advisory public. Publishing a GitHub Security Advisory and a CVE will help notify the downstream consumers of your project, so they can update to the fixed version.

`os.path.join` call is unsafe to use with untrusted input and can lead to path traversal vulnerabilities. Instead, use of `flask.safe_join` prevents patth traversal attacks.
@porcupineyhairs
Copy link
Contributor Author

@ChangeWeDer ping

@ChangeWeDer ChangeWeDer merged commit fe9a39e into ChangeWeDer:master Nov 30, 2021
@porcupineyhairs
Copy link
Contributor Author

@ChangeWeDer Can you please request an advisory for these findings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants