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:28:21 +01:00
parent 8b33a4c30e
commit 152ac2d544
4 changed files with 60 additions and 18 deletions

View File

@@ -273,12 +273,14 @@ describe('input-helper tests', () => {
describe('explicit checkout pins on a fork PR workflow_run', () => {
const originalServerUrl = process.env['GITHUB_SERVER_URL']
const originalApiUrl = process.env['GITHUB_API_URL']
const workflowSha = '1234567890123456789012345678901234567890'
const ancestorSha = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
const mergeSha = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
beforeEach(() => {
process.env['GITHUB_SERVER_URL'] = 'https://github.com'
process.env['GITHUB_API_URL'] = 'https://api.github.com'
inputs.token = 'checkout-token'
mockGithubContext.eventName = 'workflow_run'
mockGithubContext.payload = {
@@ -301,6 +303,11 @@ describe('input-helper tests', () => {
} else {
process.env['GITHUB_SERVER_URL'] = originalServerUrl
}
if (originalApiUrl === undefined) {
delete process.env['GITHUB_API_URL']
} else {
process.env['GITHUB_API_URL'] = originalApiUrl
}
})
it.each([
@@ -329,9 +336,10 @@ describe('input-helper tests', () => {
],
['https://org.ghe.com', 'https://org.ghe.com/', 'https://api.org.ghe.com']
])(
'uses the checkout API URL for workflow history on %s',
'uses the workflow API URL for workflow history on %s',
async (workflowServer, checkoutServer, apiUrl) => {
process.env['GITHUB_SERVER_URL'] = workflowServer
process.env['GITHUB_API_URL'] = apiUrl
inputs['github-server-url'] = checkoutServer
inputs.ref = ancestorSha
mockCompareCommits.mockResolvedValue({
@@ -351,6 +359,25 @@ describe('input-helper tests', () => {
}
)
it('verifies an SSH pin whose host matches the workflow server', async () => {
inputs['ssh-key'] = 'some ssh private key'
inputs['github-server-url'] = 'https://github.com:8443'
inputs.ref = mergeSha
mockCompareCommits.mockResolvedValue({
data: {
base_commit: {sha: workflowSha},
merge_base_commit: {sha: ancestorSha}
}
})
await expect(inputHelper.getInputs()).rejects.toThrow(
/Refusing to check out the requested commit/
)
expect(github.getOctokit).toHaveBeenCalledWith('checkout-token', {
baseUrl: 'https://api.github.com'
})
})
it.each([
['a PR merge commit outside workflow history', workflowSha, ancestorSha],
['a comparison against an unexpected base', ancestorSha, mergeSha]