Skip to content

approve: fix silent approval bypass when PR exceeds GitHub file list API limit#707

Open
jmguzik wants to merge 1 commit intokubernetes-sigs:mainfrom
jmguzik:global-trusted-apps
Open

approve: fix silent approval bypass when PR exceeds GitHub file list API limit#707
jmguzik wants to merge 1 commit intokubernetes-sigs:mainfrom
jmguzik:global-trusted-apps

Conversation

@jmguzik
Copy link
Copy Markdown
Contributor

@jmguzik jmguzik commented May 5, 2026

GitHub's "List pull request files" REST API endpoint returns at most 3000 files across all pages. When a pull request exceeds this limit, GitHub silently stops returning further pages. Prow's GetPullRequestChanges follows pagination via Link headers, so it terminates normally without any indication that the result is incomplete.

This creates a security vulnerability: a contributor who has OWNERS approval rights over an alphabetically-early directory can craft a PR with more than 3000 file changes in directories they own, then append additional changes in directories they do not own. Because the approve plugin only evaluates the files returned by the API, the hidden files are never checked against OWNERS, and the PR can receive the approved label without proper review coverage. This was observed in practice against openshift/hypershift#8355.

Fix:

  1. Add ChangedFiles to the PullRequest struct so that the value GitHub returns on the PR object itself (which is always accurate, unlike the paginated file list) can be compared against the number of files the API actually returned.

  2. Introduce a getFilenames helper that implements a layered strategy:

    • Fast path: use GetPullRequestChanges (works for <=3000 files).
    • Fallback: if the file list is shorter than PR.ChangedFiles, call ListPullRequestCommits and GetSingleCommit for each commit (up to maxCommitsForFallback=10) and union the filenames. This handles the common case of large auto-generated PRs that touch many files across a small number of commits.
    • Give up: if the PR has more than 10 commits, or if the per-commit file lists are also truncated, declare truncation.
  3. When truncation cannot be resolved:

    • Post an [ApprovalNotifier] comment explaining why automated approval is blocked, with the specific reason (too many commits, or individual commits also truncated). The comment is deduplicated against the latest existing notifier comment to avoid spam.
    • Remove the approved label if present and it was not added manually by a human (preserving manual administrator overrides). If the WasLabelAddedByHuman API call fails, label state is preserved rather than risking removal of a legitimate manual override.
    • Return nil so the hook handler does not log a spurious error.

For PRs within the limit the behaviour is unchanged: the fast path returns immediately after the first API call.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2026

Deploy Preview for k8s-prow ready!

Name Link
🔨 Latest commit decefa0
🔍 Latest deploy log https://app.netlify.com/projects/k8s-prow/deploys/69f9c5309d05c3000892e5cc
😎 Deploy Preview https://deploy-preview-707--k8s-prow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 5, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jmguzik / name: Jakub Guzik (decefa0)

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jmguzik
Once this PR has been reviewed and has the lgtm label, please assign stevekuznetsov for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the area/plugins Issues or PRs related to prow's plugins for the hook component label May 5, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 5, 2026
…API limit

GitHub's "List pull request files" REST API endpoint returns at most 3000
files across all pages. When a pull request exceeds this limit, GitHub
silently stops returning further pages. Prow's GetPullRequestChanges
follows pagination via Link headers, so it terminates normally without
any indication that the result is incomplete.

This creates a security vulnerability: a contributor who has OWNERS
approval rights over an alphabetically-early directory can craft a PR
with more than 3000 file changes in directories they own, then append
additional changes in directories they do not own. Because the approve
plugin only evaluates the files returned by the API, the hidden files
are never checked against OWNERS, and the PR can receive the approved
label without proper review coverage. This was observed in practice
against openshift/hypershift#8355.

Fix:

1. Add ChangedFiles to the PullRequest struct so that the value
   GitHub returns on the PR object itself (which is always accurate,
   unlike the paginated file list) can be compared against the number
   of files the API actually returned.

2. Introduce a getFilenames helper that implements a layered strategy:
   - Fast path: use GetPullRequestChanges (works for <=3000 files).
   - Fallback: if the file list is shorter than PR.ChangedFiles,
     call ListPullRequestCommits and GetSingleCommit for each commit
     (up to maxCommitsForFallback=10) and union the filenames. This
     handles the common case of large auto-generated PRs that touch
     many files across a small number of commits.
   - Give up: if the PR has more than 10 commits, or if the per-commit
     file lists are also truncated, declare truncation.

3. When truncation cannot be resolved:
   - Post an [ApprovalNotifier] comment explaining why automated
     approval is blocked, with the specific reason (too many commits,
     or individual commits also truncated). The comment is deduplicated
     against the latest existing notifier comment to avoid spam.
   - Remove the approved label if present and it was not added manually
     by a human (preserving manual administrator overrides). If the
     WasLabelAddedByHuman API call fails, label state is preserved
     rather than risking removal of a legitimate manual override.
   - Return nil so the hook handler does not log a spurious error.

For PRs within the limit the behaviour is unchanged: the fast path
returns immediately after the first API call.

Co-authored with Cursor.

Signed-off-by: Jakub Guzik <jguzik@redhat.com>
@jmguzik jmguzik force-pushed the global-trusted-apps branch from c3553c3 to decefa0 Compare May 5, 2026 10:23
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 5, 2026
seen[f] = struct{}{}
}
for _, c := range commits {
commit, err := ghc.GetSingleCommit(org, repo, c.SHA)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this API call have the same limitation?

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

Labels

area/plugins Issues or PRs related to prow's plugins for the hook component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants