mirror of
https://github.com/actions/checkout.git
synced 2026-12-04 03:22:56 +08:00
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:
@@ -177,6 +177,7 @@ describe('input-helper tests', () => {
|
||||
|
||||
describe('workflow checkout server', () => {
|
||||
const originalServerUrl = process.env['GITHUB_SERVER_URL']
|
||||
const originalApiUrl = process.env['GITHUB_API_URL']
|
||||
const originalEventName = github.context.eventName
|
||||
const originalPayload = github.context.payload
|
||||
const workflowSha = '1234567890123456789012345678901234567890'
|
||||
@@ -185,6 +186,7 @@ describe('input-helper tests', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com'
|
||||
process.env['GITHUB_API_URL'] = 'https://api.github.com'
|
||||
github.context.eventName = 'workflow_run'
|
||||
github.context.payload = {
|
||||
repository: {id: 100, name: 'some-repo', owner: {login: 'some-owner'}},
|
||||
@@ -217,6 +219,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([
|
||||
@@ -244,9 +251,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
|
||||
|
||||
await expect(inputHelper.getInputs()).resolves.toMatchObject({
|
||||
@@ -258,6 +266,24 @@ describe('input-helper tests', () => {
|
||||
expect(mockCompareCommits).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
)
|
||||
|
||||
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'
|
||||
mockCompareCommits.mockResolvedValue({
|
||||
data: {
|
||||
base_commit: {sha: workflowSha},
|
||||
merge_base_commit: {sha: workflowSha}
|
||||
}
|
||||
})
|
||||
|
||||
await expect(inputHelper.getInputs()).rejects.toThrow(
|
||||
/Refusing to check out the requested commit/
|
||||
)
|
||||
expect(github.getOctokit).toHaveBeenCalledWith('checkout-token', {
|
||||
baseUrl: 'https://api.github.com'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('unsafe PR checkout guard', () => {
|
||||
|
||||
Reference in New Issue
Block a user