Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder. By manipulating variables that reference files with “dot-dot-slash (../)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files. This attack is also known as “dot-dot-slash”, “directory traversal”, “directory climbing” and “backtracking”.
Root Cause Analysis
Passing untrusted input to
flask.send_file
can lead to path traversal attacks.In this case, the problems occurs due to the following code :
https://github.com/piaoyunsoft/bt_lnmp/blob/fa49519b04586a00e76c105e7ce1da36eadf6922/www/server/panel/BTPanel/__init__.py#L858
Here, the
filename
parameter is attacker controlled and is used as the filename passed to thesend_file
call. This leads to a path traversal attack.Remediation
This can be fixed by preventing flow of untrusted data to the vulnerable
send_file
function. In case the application logic necessiates this behaviour, one can either use theflask.safe_join
to join untrusted paths or replaceflask.send_file
calls withflask.send_from_directory
calls.References
This bug was found using (CodeQL by Github)[https://codeql.github.com/]