Skip to content

fix(codeql): resolve live base identity from authenticated branch refs - #2657

Open
seonghobae wants to merge 1 commit into
mainfrom
fix/codeql-live-base-ref-20261015
Open

seonghobae wants to merge 1 commit into
mainfrom
fix/codeql-live-base-ref-20261015

Conversation

@seonghobae

@seonghobae seonghobae commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Observed failure

CodeQL dispatch run 38724148386 for #2642 head 8864077 rejects the producer merge because the PR object's base.sha is af81ef4, while the actual main ref and producer merge's first parent are 6a03ae9. A fresh substantive head reproduced the mismatch. The named branch ref, not an old PR base snapshot, must supply current base identity.

Repair

Read the authenticated exact branch ref in all five affected boundaries: receipt reader, coordinator, dispatch admission, pre-scan revalidation and required-run settlement. Encode branch names in the API path and require the exact returned ref, commit object type and canonical 40-hex SHA.

The existing exact merge-parent/head/source checks, actor/repository admission, required-run/language-job receipt identity, permissions, scanner gates and stale-run refusal remain. Missing, malformed, wrong or unavailable refs fail closed; there is no fallback to historical PR base.sha. No branch protection, token, ACL or runner registration is changed.

Verified scope

  • 6 regression RED cases before repair.
  • 123 focused actual-shell/contract tests pass, independently rerun and source-reviewed.
  • Final complete local functional suite: 6541 passed, 10 skipped, 92 subtests passed, exit 0. Python 3.12, GITHUB_ACTIONS=true, full Git history and writable temporary HOME.
  • Controls cover missing/wrong ref/type/hash, transport failure, moved base, pre-scan/settlement rejection, stale PR snapshots, receipt reading and slash branch path encoding.
  • Actual public GitHub GET with a percent-encoded slash branch returned the expected exact ref and commit.
  • actionlint workflow/expression checks and diff-check pass. ShellCheck is unavailable; complete shell-scanner acceptance is not claimed.
  • Four published Git blob SHAs match the locally tested files exactly.

Integration boundary

Ready for normal independent review after source repair and local verification, not operational acceptance. Protected repository_dispatch executes the handler from main: an unmerged PR client cannot prove the new protected handler. Keep exact-head remote security/CodeQL/review checks and normal protected integration requirements; do not bypass them or treat predecessor or skipped checks as acceptance. After protected handler integration, affected consumers need fresh source/run-bound evidence.

Existing broad owners #2040 and #2051 remain untouched; this is a narrow live-reference correction on current main.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c5a74938-25d5-43fa-8613-99d0389237e3
📥 Commits

Reviewing files that changed from the base of the PR and between 6a03ae9 and e04587a.

📒 Files selected for processing: 4
  • .github/workflows/codeql-pr.yml
  • .github/workflows/codeql-scan-dispatch.yml
  • tests/test_codeql_pr_workflow_contract.py
  • tests/test_codeql_scan_dispatch_workflow_contract.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae marked this pull request as ready for review October 15, 2026 11:10

@cwl-noema-review cwl-noema-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noema LLM review

Approve. The change consistently replaces stale pull-request base snapshots with authenticated current branch tips, fails closed on lookup or identity mismatches, and preserves settlement safety when the base branch moves.

Reviewed changed lines

  • .github/workflows/codeql-pr.yml:356 (RIGHT): The coordinator resolves the named base branch through the Git refs API and requires an exact refs/heads identity and commit-shaped SHA before constructing dispatch evidence.
  • .github/workflows/codeql-pr.yml:730 (RIGHT): The receipt reader uses the same authenticated branch-tip resolution before deriving the expected status context, preventing stale PR metadata from accepting an obsolete receipt.
  • .github/workflows/codeql-scan-dispatch.yml:381 (RIGHT): Dispatch admission is bound to the live authenticated base branch and fails if the supplied base identity does not match it.
  • .github/workflows/codeql-scan-dispatch.yml:547 (RIGHT): The privileged pre-scan revalidation repeats the authenticated branch lookup, preserving the live-base check at the security boundary.
  • .github/workflows/codeql-scan-dispatch.yml:1047 (RIGHT): Settlement rejects wake-up when the current authenticated branch tip differs from the base identity bound to the scan.

Adversarial validation

  • .github/workflows/codeql-scan-dispatch.yml:381 (RIGHT) falsified: A stale pull-request base.sha could either reject a valid dispatch or admit a dispatch against the wrong base. — The new validation derives live_base_sha from the exact branch ref and compares the supplied identity against that value; the added stale-snapshot contract test exercises this case.
  • .github/workflows/codeql-pr.yml:356 (RIGHT) falsified: A slash-containing or otherwise encoded base branch could resolve the wrong ref or permit endpoint ambiguity. — The branch name is URI-encoded before the Git refs request and the response is required to match the exact refs/heads value; the coordinator contract test asserts the encoded path and resulting payload identity.
  • .github/workflows/codeql-scan-dispatch.yml:1047 (RIGHT) falsified: A base branch moved after scanning could still wake the required run because settlement only trusted the historical PR snapshot. — Settlement now fetches the current branch ref and exits before posting the wake-up when its SHA differs; the added changed-branch settlement test asserts that no post occurs.
  • .github/workflows/codeql-scan-dispatch.yml:381 (RIGHT) falsified: A ref transport failure could trigger fallback to the historical PR base and admit an unverified dispatch. — The new lookup is executed under fail-fast shell handling with no fallback assignment; the added transport-failure test requires a nonzero result and no dispatch.
  • Residual risk: No confirmed regression found. A narrow unavoidable TOCTOU window remains between ref lookup and later GitHub operations, but the dispatch handler and settlement boundary revalidate the live branch identity and fail closed.

Findings

  • No blocking findings.
  • Result: APPROVE
  • Head SHA: e04587abd3cdd228651bf8b64d71a5efd6f29efc
  • Reviewer credential: noema-review-github-app-refresh
  • Actor: cwl-noema-review[bot]

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

OpenCode reviewed the current-head product diff. Coverage is a separate gate.

Changed files

  • .github/workflows/codeql-pr.yml — GitHub Actions review job
  • .github/workflows/codeql-scan-dispatch.yml — GitHub Actions review job
  • tests/test_codeql_pr_workflow_contract.py — regression suite
  • tests/test_codeql_scan_dispatch_workflow_contract.py — regression suite

Changed behavior

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Workflow: codeql-pr.yml"]
  S1 --> I1["GitHub Actions review job"]
  I1 --> R1["Review risk: Workflow: codeql-pr.yml"]
  R1 --> V1["actionlint plus required checks"]
  Evidence --> S2["Workflow: codeql-scan-dispatch.yml"]
  S2 --> I2["GitHub Actions review job"]
  I2 --> R2["Review risk: Workflow: codeql-scan-dispatch.yml"]
  R2 --> V2["actionlint plus required checks"]
  Evidence --> S3["Test: test_codeql_pr_workflow_contract.py (2 files)"]
  S3 --> I3["regression suite"]
  I3 --> R3["Review risk: Test: test_codeql_pr_workflow_contract.py (2 files)"]
  R3 --> V3["targeted test run"]
Loading

Findings

No source-backed product finding is synthesized from the coverage gate. A coverage miss belongs in the status comment.

  • Head SHA: e04587abd3cdd228651bf8b64d71a5efd6f29efc
  • Workflow run: 38725543518
  • Workflow attempt: 1
  • Coverage gate: failure

Review outcome

Coverage is a gate, not the review. This body reviews the changed product files.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Workflow: codeql-pr.yml"]
  S1 --> I1["GitHub Actions review job"]
  I1 --> R1["Review risk: Workflow: codeql-pr.yml"]
  R1 --> V1["actionlint plus required checks"]
  Evidence --> S2["Workflow: codeql-scan-dispatch.yml"]
  S2 --> I2["GitHub Actions review job"]
  I2 --> R2["Review risk: Workflow: codeql-scan-dispatch.yml"]
  R2 --> V2["actionlint plus required checks"]
  Evidence --> S3["Test: test_codeql_pr_workflow_contract.py (2 files)"]
  S3 --> I3["regression suite"]
  I3 --> R3["Review risk: Test: test_codeql_pr_workflow_contract.py (2 files)"]
  R3 --> V3["targeted test run"]
Loading

@opencode-agent

opencode-agent Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

Coverage evidence did not pass, so approval is blocked. The formal pull-request review is the source-backed diff review, not this status comment.

This branch has not been deployed

No deployments
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.

1 participant