Security: Path traversal in received file paths #188
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?
Severity: high
Category: security
Location:
src/shared/file.c:129-138,src/shared/file.c:328,src/server/server.c:41-55Description:
Received file paths are used directly to construct destination paths via
path_cat(config->receive_root_directory, file->path)without validation. A malicious client can send paths containing..components, absolute paths (/etc/passwd), or embedded null bytes, causing the server to write outside the intended destination directory.For example, a client sending
path = "../../../etc/cron.d/fastsync"could overwrite system files when the server runs with sufficient privileges.Suggested fix:
file_save_to_disk()andreceive_incremental_check(), canonicalize and validate the received relative path:...openat(dest_fd, rel_path, O_NOFOLLOW)or equivalent to prevent symlink traversal.O_NOFOLLOWflags for destination directories.Labels: security, path-traversal