You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds optional expectedHeadSha pinning to merge_pull_request.
The value is forwarded to github.PullRequestOptions.SHA, which go-github serializes as the GitHub REST merge endpoint's optional sha field.
This closes the TOCTOU gap between reviewing a pull request HEAD and merging
it: if the HEAD changes, GitHub rejects the merge instead of merging the new
commit.
Changes
add optional expectedHeadSha to the merge_pull_request schema;
pass it to `PullRequestOption...
Analysis
Vulnerability Type: Time-of-Check-Time-of-Use (TOCTOU) Race Condition Severity: High
Description
The merge_pull_request function had a TOCTOU vulnerability where the pull request HEAD could be modified between when a user reviewed it and when the merge was executed. An attacker could change the PR's HEAD after approval but before merge, causing unreviewed code to be merged. The patch adds optional expectedHeadSha pinning that validates the HEAD hasn't changed before merging, closing this race condition gap.
Affected Code
options := &github.PullRequestOptions{
CommitTitle: commitTitle,
MergeMethod: mergeMethod,
}
// No SHA validation before merge
Proof of Concept
1. User reviews PR #42 with HEAD SHA abc123...
2. Attacker pushes malicious commit to PR, changing HEAD to def456...
3. User calls merge_pull_request without expectedHeadSha parameter
4. Malicious code at def456... gets merged without review
With patch:
User calls merge_pull_request with expectedHeadSha='abc123...'
If attacker changed HEAD to def456..., GitHub returns 409 Conflict
Merge fails and operator must explicitly re-review before retrying
Activity