[BUG] LFI Vulnerability via Unsanitized File Path in Upload and Download Handlers #1462
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.
Version: 0.0.14
Description
A critical Local File Inclusion (LFI) vulnerability exists in SuperAGI’s file handling mechanism. The application does not properly sanitize file paths during both upload and download operations, allowing attackers to read arbitrary files from the server.
The issue stems from two endpoints: the upload endpoint (
/add/<agent_id>
) and the download endpoint (/get/<resource_id>
), both located insuperagi/controllers/resources.py
.During upload, user-supplied filenames are accepted via
multipart/form-data
and directly joined with a base directory usingos.path.join()
without validating the full path. The resulting path is stored in the database.Later, the download endpoint retrieves this path from the database and uses it to read the file. Although it calls
Path().resolve()
during the read operation, the path has already been constructed and trusted. This enables attackers to:../../../../etc/passwd.txt
.Source - Sink Analysis
Source:
upload()
insuperagi/controllers/resources.py
Intermediate:
os.path.join()
inresources.py
Sink (Write):
open()
inresources.py
Sink (Read):
Path.resolve()
inresources.py
Proof of Concept
1. Upload a file with a malicious name:
2. Retrieve the file via the download endpoint:
This confirms that arbitrary files can be read through crafted upload paths, allowing an attacker to access sensitive system files or previously overwritten files via AFO.
Impact
This vulnerability allows attackers to: