Scope workflow history verification to the checkout server

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Francesco Renzi
2026-12-03 18:11:46 +01:00
co-authored by Copilot App
parent 6e5cb61ce4
commit f38dcf9239
4 changed files with 107 additions and 10 deletions
+2 -1
View File
@@ -196,7 +196,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
qualifiedRepository,
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
githubServerUrl: result.githubServerUrl
},
result.authToken
)
+12 -4
View File
@@ -1,5 +1,6 @@
import * as github from '@actions/github'
import {fromPayload} from './ref-helper'
import {getServerApiUrl, getServerUrl} from './url-helper'
const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/
@@ -8,6 +9,7 @@ export interface IUnsafePrCheckoutInput {
ref: string
commit: string | undefined
allowUnsafePrCheckout: boolean
githubServerUrl?: string
}
export function assertSafePrCheckout(
@@ -76,9 +78,14 @@ export function assertSafePrCheckout(
!input.ref &&
commit &&
input.qualifiedRepository.toLowerCase() ===
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase()
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase() &&
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin
) {
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
return commitIsInWorkflowHistory(
authToken,
commit,
input.githubServerUrl
).then(isInHistory => {
if (!isInHistory) {
throw new Error(
'Refusing to check out the requested commit for this fork pull request. ' +
@@ -102,7 +109,8 @@ export function assertSafePrCheckout(
async function commitIsInWorkflowHistory(
authToken: string,
commit: string
commit: string,
githubServerUrl?: string
): Promise<boolean> {
const workflowSha = github.context.sha.toLowerCase()
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(workflowSha)) {
@@ -117,7 +125,7 @@ async function commitIsInWorkflowHistory(
const {owner, repo} = github.context.repo
try {
const {data} = await github
.getOctokit(authToken)
.getOctokit(authToken, {baseUrl: getServerApiUrl(githubServerUrl)})
.rest.repos.compareCommitsWithBasehead({
owner,
repo,