Skip to content

harden output file handling against race conditions and symlink attacks#4640

Open
metsw24-max wants to merge 1 commit intofacebook:devfrom
metsw24-max:cli-output-file-hardening
Open

harden output file handling against race conditions and symlink attacks#4640
metsw24-max wants to merge 1 commit intofacebook:devfrom
metsw24-max:cli-output-file-hardening

Conversation

@metsw24-max
Copy link
Copy Markdown

This change hardens the CLI output file creation path by eliminating race-prone patterns and preventing symlink-based overwrite attacks.

The update replaces the existing unlink-and-recreate workflow with atomic file creation semantics and introduces additional safety checks for output file handling

Replace non-atomic unlink() + open() pattern with atomic open using O_EXCL for non-overwrite mode

Prevent symlink traversal during output file creation using O_NOFOLLOW

Add O_CLOEXEC to reduce file descriptor leakage across exec boundaries

Introduce explicit handling of EEXIST and ELOOP for clearer and safer error reporting

@meta-cla meta-cla bot added the CLA Signed label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant