Validate log_file paths to prevent arbitrary file writes#3656
Closed
eddieran wants to merge 1 commit intopre-commit:mainfrom
Closed
Validate log_file paths to prevent arbitrary file writes#3656eddieran wants to merge 1 commit intopre-commit:mainfrom
eddieran wants to merge 1 commit intopre-commit:mainfrom
Conversation
A hook manifest can specify a `log_file` with an absolute path or path traversal sequences (e.g. `../../../etc/cron.d/malicious`), causing pre-commit to write hook output to arbitrary locations on the host filesystem via `output.write_line_b`. Reject absolute paths and paths that traverse above the working directory during manifest validation. Fixes #3655
Member
|
there's no such thing as a "malicious remote hook" every part of pre-commit is opt in please don't send ai slop prs |
Member
|
also lol if they're truly evil they ALREADY HAVE ARBITRARY CODE EXECUTION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
log_filein hook manifests (.pre-commit-hooks.yaml) accepts arbitrary strings and is passed directly toopen(logfile_name, 'ab')inoutput.write_line_b. A malicious remote hook manifest can setlog_fileto an absolute path (e.g./etc/cron.d/malicious) or use path traversal (../../../etc/passwd) to write hook output to arbitrary locations on the host filesystem.Fix
Add path validation for
log_fileinclientlib.pyduring manifest schema validation:../foo)The validation is applied via
check_log_fileon theMANIFEST_HOOK_DICTschema, which also propagates toCONFIG_HOOK_DICTandLOCAL_HOOK_DICT.Test plan
test_check_log_file_valid— verifies relative paths likeoutput.log,logs/hook.log, and empty string pass validationtest_check_log_file_invalid— verifies absolute paths and..traversal paths are rejected withcfgv.ValidationErrorFixes #3655