fix: prevent cache poisoning by force-resetting worktree on failed PR remediation#6368
Open
AftAb-25 wants to merge 1 commit intomindersec:mainfrom
Open
fix: prevent cache poisoning by force-resetting worktree on failed PR remediation#6368AftAb-25 wants to merge 1 commit intomindersec:mainfrom
AftAb-25 wants to merge 1 commit intomindersec:mainfrom
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6367
Description
This fixes a cache poisoning bug in the PR remediator where failed remediations would leak uncommitted changes into the shared ingest cache, causing silent evaluation failures for subsequent rules.
When pull_request.go aborts a remediation and runs checkoutToOriginallyFetchedBranch, it previously used the default
go-gitcheckout which preserves modifications to the worktree/index. Because the executor uses a single sharedingestCache.Fsper run, those left-behind dirty files would then be incorrectly evaluated by subsequent rules.This PR aggressively resets the worktree during the checkout cleanup phase:
Force: trueto the checkout options to discard modified tracked files.wt.Clean(&git.CleanOptions{Dir: true})to remove any untracked leftover files.I've also added a unit test (checkout_cleanup_test.go) that simulates a dirty worktree and ensures both tracked modifications and untracked files are correctly wiped out.
Checklist