Security: Path traversal allows writes/deletes outside destination root #154
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Received file paths are concatenated directly with the destination root directory without validation. A malicious client can send paths containing
..components (e.g.../../../etc/cron.d/exploit) and the server will write, read, or delete files outsidereceive_root_directory.Affected call sites:
src/shared/file.c:130—file_save_to_disk()usespath_cat(root_directory, file->path).src/shared/file.c:328—receive_incremental_check()usespath_cat(config->receive_root_directory, check_path).src/shared/file.c:521-539—receive_manifest()passes manifest paths todelete_extras(), which also concatenates them with the root.path_cat()insrc/shared/utils.c:127-149simply joins two strings and normalizes slashes; it does not reject..components or canonicalize the result. A previous issue (#112) noted a weakstrstr(..)check, but the currentmainbranch contains no such check at all.Reproduction scenario
./build/server --dest-dir /tmp/recv --save-to-diskSTATUS_NEXT+send_str("../../../tmp/owned")+ file data./tmp/recv/../../../tmp/owned=/tmp/owned.With
--delete, an attacker can also delete arbitrary files by listing them in the manifest.Suggested fix
path_cat()or a new helper, reject any path component that is exactly...realpath()and verify the canonical path is still underreceive_root_directory.openat()/mkdirat()relative to a dirfd opened for the root directory to avoid TOCTOU.Severity
Critical
Category
security
This issue was automatically generated by the issue-creator agent.