Repository navigation
security: independently validate GitHub reviewer approval before STEP_UP permit #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
blocksifrdev
merged 6 commits into
main
from
security/independent-github-approval-20261102
Nov 2, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d11210
security: independently verify GitHub environment approval, reviewer …
blocksifrdev 14e3016
security: deny self-asserted GitHub approvals and require independent…
blocksifrdev 503d16e
test: reject unverified HTTP step-up approvals and exercise independe…
blocksifrdev 095ef99
docs: require server-side GitHub approval verifier credential and dis…
blocksifrdev d967023
security: validate approval claim field types before invoking GitHub …
blocksifrdev 3b8a435
test: malformed reviewer claim denied with HTTP 400, not authority crash
blocksifrdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Independent GitHub-side approval proof. Caller assertions never count as | ||
| // reviewer evidence. Network lookups always use the fixed api.github.com host. | ||
| export type ApprovalEntry = { | ||
| state?: string | ||
| environments?: Array<{ name?: string }> | ||
| user?: { login?: string } | ||
| } | ||
| export interface ReviewClaim { | ||
| repo: string | ||
| workflowRunId: string | ||
| commitSha: string | ||
| branch: string | ||
| resource: string | ||
| invokingActor: string | ||
| reviewer: string | ||
| } | ||
| export interface ReviewProof { | ||
| verified: boolean | ||
| reason: string | ||
| reviewer?: string | ||
| } | ||
| export function assessApprovalHistory( | ||
| entries: unknown, claim: ReviewClaim, author: string, sha: string, branch: string | ||
| ): ReviewProof { | ||
| if (!Array.isArray(entries)) return { verified: false, reason: "INVALID_GITHUB_APPROVAL_HISTORY" } | ||
| if (sha !== claim.commitSha || branch !== claim.branch) { | ||
| return { verified: false, reason: "GITHUB_PR_HEAD_CHANGED" } | ||
| } | ||
| const expected = claim.reviewer.toLowerCase() | ||
| const blocked = [author, claim.invokingActor].map(s => s.toLowerCase()) | ||
| if (!expected || blocked.includes(expected)) return { verified: false, reason: "SELF_APPROVAL" } | ||
| const matches = (entries as ApprovalEntry[]).filter(entry => | ||
| entry && typeof entry === "object" && | ||
| entry.state?.toLowerCase() === "approved" && | ||
| entry.user?.login?.toLowerCase() === expected && | ||
| Array.isArray(entry.environments) && | ||
| entry.environments.some(e => e?.name === "protected-execution") | ||
| ) | ||
| return matches.length === 1 | ||
| ? { verified: true, reason: "GITHUB_APPROVAL_VERIFIED", reviewer: claim.reviewer } | ||
| : { verified: false, reason: "INDEPENDENT_APPROVAL_NOT_VERIFIED" } | ||
| } | ||
| export async function verifyIndependentGithubApproval(claim: ReviewClaim): Promise<ReviewProof> { | ||
| const token = process.env.GITHUB_APPROVAL_VERIFY_TOKEN | ||
| if (!token || token.length < 20) return { verified: false, reason: "GITHUB_APPROVAL_VERIFIER_UNCONFIGURED" } | ||
| if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(claim.repo) || | ||
| !/^[0-9]+$/.test(claim.workflowRunId) || | ||
| !/^[0-9a-fA-F]{40}$/.test(claim.commitSha) || | ||
| !claim.reviewer || !claim.invokingActor) { | ||
| return { verified: false, reason: "INVALID_GITHUB_APPROVAL_CLAIM" } | ||
| } | ||
| const match = /^repo:([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+):pr\/([0-9]+)$/.exec(claim.resource) | ||
| if (!match || match[1].toLowerCase() !== claim.repo.toLowerCase()) { | ||
| return { verified: false, reason: "INVALID_PR_RESOURCE" } | ||
| } | ||
| const headers = { | ||
| Accept: "application/vnd.github+json", | ||
| Authorization: "Bearer " + token, | ||
| "X-GitHub-Api-Version": "2022-11-28" | ||
| } | ||
| async function readJson(endpoint: string): Promise<unknown> { | ||
| const response = await fetch("https://api.github.com" + endpoint, { | ||
| headers, signal: AbortSignal.timeout(8000), redirect: "error" | ||
| }) | ||
| if (!response.ok) throw new Error("GitHub API error") | ||
| return response.json() | ||
| } | ||
| try { | ||
| const base = "/repos/" + claim.repo | ||
| const [history, pr] = await Promise.all([ | ||
| readJson(base + "/actions/runs/" + claim.workflowRunId + "/approvals"), | ||
| readJson(base + "/pulls/" + match[2]) | ||
| ]) | ||
| if (!pr || typeof pr !== "object") return { verified:false, reason:"PR_NOT_VERIFIED" } | ||
| const snapshot = pr as { | ||
| state?: string | ||
| user?: { login?: string } | ||
| head?: { sha?: string, ref?: string } | ||
| base?: { repo?: { full_name?: string } } | ||
| } | ||
| if (snapshot.state !== "open" || !snapshot.user?.login || | ||
| snapshot.base?.repo?.full_name?.toLowerCase() !== claim.repo.toLowerCase()) { | ||
| return { verified: false, reason: "GITHUB_PR_IDENTITY_MISMATCH" } | ||
| } | ||
| return assessApprovalHistory(history, claim, snapshot.user.login, | ||
| snapshot.head?.sha ?? "", snapshot.head?.ref ?? "") | ||
| } catch { | ||
| return { verified: false, reason: "GITHUB_APPROVAL_LOOKUP_UNAVAILABLE" } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the verifier token is configured, an authenticated caller can supply an already-approved run ID from another PR or an older revision, obtain a fresh STEP_UP receipt using that ID, and reauthorize the current PR without a new human approval. These lookups independently verify that the run has an approval and that the PR matches the claimed head, but never establish that the approved run belongs to that PR revision. The prior-receipt checks only preserve the caller-supplied association. Fetch and validate authoritative run/event metadata linking the approval to the requested PR revision before returning a verified proof; include a negative fixture with an approved run unrelated to the otherwise matching PR.
Useful? React with 👍 / 👎.