Verify SSH pins against the workflow server

SSH fetch URLs keep only the hostname of github-server-url, so a port or
scheme change no longer skips workflow history verification. Verification
always uses the workflow's API endpoint.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Francesco Renzi
2026-12-03 18:30:20 +01:00
parent f38dcf9239
commit 15c98b676d
4 changed files with 59 additions and 16 deletions

View File

@@ -197,7 +197,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
githubServerUrl: result.githubServerUrl
githubServerUrl: result.githubServerUrl,
usesSsh: !!result.sshKey
},
result.authToken
)

View File

@@ -10,6 +10,7 @@ export interface IUnsafePrCheckoutInput {
commit: string | undefined
allowUnsafePrCheckout: boolean
githubServerUrl?: string
usesSsh?: boolean
}
export function assertSafePrCheckout(
@@ -79,13 +80,9 @@ export function assertSafePrCheckout(
commit &&
input.qualifiedRepository.toLowerCase() ===
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase() &&
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin
fetchesFromWorkflowServer(input)
) {
return commitIsInWorkflowHistory(
authToken,
commit,
input.githubServerUrl
).then(isInHistory => {
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
if (!isInHistory) {
throw new Error(
'Refusing to check out the requested commit for this fork pull request. ' +
@@ -107,10 +104,19 @@ export function assertSafePrCheckout(
)
}
// SSH fetch URLs keep only the hostname, so the scheme and port cannot
// distinguish the checkout server from the workflow server.
function fetchesFromWorkflowServer(input: IUnsafePrCheckoutInput): boolean {
const checkoutServer = getServerUrl(input.githubServerUrl)
const workflowServer = getServerUrl()
return input.usesSsh
? checkoutServer.hostname === workflowServer.hostname
: checkoutServer.origin === workflowServer.origin
}
async function commitIsInWorkflowHistory(
authToken: string,
commit: string,
githubServerUrl?: string
commit: string
): Promise<boolean> {
const workflowSha = github.context.sha.toLowerCase()
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(workflowSha)) {
@@ -125,7 +131,7 @@ async function commitIsInWorkflowHistory(
const {owner, repo} = github.context.repo
try {
const {data} = await github
.getOctokit(authToken, {baseUrl: getServerApiUrl(githubServerUrl)})
.getOctokit(authToken, {baseUrl: getServerApiUrl()})
.rest.repos.compareCommitsWithBasehead({
owner,
repo,