Security: Metadata restoration applies arbitrary mode bits including setuid/setgid #157
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
file_restore_metadata()insrc/shared/metadata.c:96-107writes the receivedmodefield directly to disk usingchmod(path, metadata->mode & 07777). Becausemetadata->modecomes from the peer, a malicious client can set setuid, setgid, or sticky bits on files created at the destination.For example, a client could transfer a file with mode
04755to a path such as../../../tmp/setuid-sh, giving any user a root shell if the server runs as root. Thechown()call at line 100 also usesuid/gidvalues from the network and is silently ignored on failure.Location
src/shared/metadata.c:99—chmod(path, metadata->mode & 07777);src/shared/metadata.c:100—chown(path, metadata->uid, metadata->gid);return value discarded.Suggested fix
chmod(path, (metadata->mode & 0777)), or at least strip setuid/setgid unless explicitly allowed by policy.chown()failures; consider refusing to apply metadata that cannot be verified.Severity
High
Category
security
This issue was automatically generated by the issue-creator agent.