Skip to content

fix: prevent cache poisoning by force-resetting worktree on failed PR remediation#6368

Open
AftAb-25 wants to merge 1 commit intomindersec:mainfrom
AftAb-25:fix/6367-remediation-cache-poisoning
Open

fix: prevent cache poisoning by force-resetting worktree on failed PR remediation#6368
AftAb-25 wants to merge 1 commit intomindersec:mainfrom
AftAb-25:fix/6367-remediation-cache-poisoning

Conversation

@AftAb-25
Copy link
Copy Markdown
Contributor

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-git checkout which preserves modifications to the worktree/index. Because the executor uses a single shared ingestCache.Fs per 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:

  • Adds Force: true to the checkout options to discard modified tracked files.
  • Calls 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

  • Code compiles correctly
  • Added tests that fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

@AftAb-25 AftAb-25 requested a review from a team as a code owner April 14, 2026 19:14
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 59.534% (-0.005%) from 59.539% — AftAb-25:fix/6367-remediation-cache-poisoning into mindersec:main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cache poisoning vulnerability in PR remediator causes silent evaluation failures

2 participants