From 0b1f1c2ab0712fe5563533240aef1de8948220e1 Mon Sep 17 00:00:00 2001 From: Porcupiney Hairs Date: Fri, 29 Apr 2022 00:55:50 +0530 Subject: [PATCH] # Absolute Path Traversal due to incorrect use of `send_file` call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 the `send_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 the `flask.safe_join` to join untrusted paths or replace `flask.send_file` calls with `flask.send_from_directory` calls. ## References * [OWASP Path Traversal](https://owasp.org/www-community/attacks/Path_Traversal) * github/securitylab#669 ### This bug was found using *[CodeQL by Github](codeql.github.com/)* --- src/fallenthrone/views/flaskdocs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fallenthrone/views/flaskdocs.py b/src/fallenthrone/views/flaskdocs.py index fd70f74..7c21f22 100644 --- a/src/fallenthrone/views/flaskdocs.py +++ b/src/fallenthrone/views/flaskdocs.py @@ -4,7 +4,7 @@ Gives flask's documentation on tips at http://localhost/docs """ -from flask import Blueprint +from flask import Blueprint,safe_join from fallenthrone import app from flask import make_response, send_file import os @@ -14,7 +14,7 @@ @docs_pages.route ('/', defaults={'filename': 'index.html'}) @docs_pages.route ('/') def docserver (filename): - ifile = os.path.join ("docs", "flask", filename) + ifile = safe_join ("docs", "flask", filename) return send_file (ifile) app.register_blueprint (docs_pages, url_prefix='/docs')