mirror of
https://github.com/actions/checkout.git
synced 2026-07-15 19:24:48 +03:00
skip running unsafe pr check if input is default (backport #2518 to releases/v2)
This commit is contained in:
committed by
GitHub
parent
262cdb5f1c
commit
38a064df5a
@@ -140,4 +140,50 @@ describe('input-helper tests', () => {
|
|||||||
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||||
expect(settings.workflowOrganizationId).toBe(123456)
|
expect(settings.workflowOrganizationId).toBe(123456)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('unsafe PR checkout guard', () => {
|
||||||
|
const forkPayload = {
|
||||||
|
repository: {id: 100},
|
||||||
|
pull_request: {
|
||||||
|
head: {
|
||||||
|
sha: '1234567890123456789012345678901234567890',
|
||||||
|
repo: {id: 200, full_name: 'attacker/fork'}
|
||||||
|
},
|
||||||
|
merge_commit_sha: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it('allows the default self-checkout on a fork pull_request_target', async () => {
|
||||||
|
const originalEvent = github.context.eventName
|
||||||
|
const originalPayload = github.context.payload
|
||||||
|
try {
|
||||||
|
github.context.eventName = 'pull_request_target'
|
||||||
|
github.context.payload = forkPayload as any
|
||||||
|
// Simulate a rebase/fast-forward merge where the base tip (event SHA)
|
||||||
|
// equals the PR head SHA. The default self-checkout must still succeed.
|
||||||
|
github.context.sha = '1234567890123456789012345678901234567890'
|
||||||
|
const settings: IGitSourceSettings = await inputHelper.getInputs()
|
||||||
|
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
|
||||||
|
} finally {
|
||||||
|
github.context.eventName = originalEvent
|
||||||
|
github.context.payload = originalPayload
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('refuses an explicit fork repository on pull_request_target', async () => {
|
||||||
|
const originalEvent = github.context.eventName
|
||||||
|
const originalPayload = github.context.payload
|
||||||
|
try {
|
||||||
|
github.context.eventName = 'pull_request_target'
|
||||||
|
github.context.payload = forkPayload as any
|
||||||
|
inputs.repository = 'attacker/fork'
|
||||||
|
await expect(inputHelper.getInputs()).rejects.toThrow(
|
||||||
|
/Refusing to check out fork pull request code/
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
github.context.eventName = originalEvent
|
||||||
|
github.context.payload = originalPayload
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Vendored
+13
-6
@@ -18568,12 +18568,19 @@ function getInputs() {
|
|||||||
(core.getInput('allow-unsafe-pr-checkout') || 'false').toUpperCase() ===
|
(core.getInput('allow-unsafe-pr-checkout') || 'false').toUpperCase() ===
|
||||||
'TRUE';
|
'TRUE';
|
||||||
core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`);
|
core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`);
|
||||||
unsafePrCheckoutHelper.assertSafePrCheckout({
|
// The default self-checkout (this repository with no explicit ref) always
|
||||||
qualifiedRepository,
|
// resolves to the trusted ref/commit GitHub set for the triggering event, so
|
||||||
ref: result.ref,
|
// the fork-checkout guard only needs to run when the caller customized the
|
||||||
commit: result.commit,
|
// repository or ref.
|
||||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
const isDefaultCheckout = isWorkflowRepository && !core.getInput('ref');
|
||||||
});
|
if (!isDefaultCheckout) {
|
||||||
|
unsafePrCheckoutHelper.assertSafePrCheckout({
|
||||||
|
qualifiedRepository,
|
||||||
|
ref: result.ref,
|
||||||
|
commit: result.commit,
|
||||||
|
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
||||||
|
});
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-8
@@ -7,7 +7,7 @@ import * as workflowContextHelper from './workflow-context-helper'
|
|||||||
import {IGitSourceSettings} from './git-source-settings'
|
import {IGitSourceSettings} from './git-source-settings'
|
||||||
|
|
||||||
export async function getInputs(): Promise<IGitSourceSettings> {
|
export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
const result = ({} as unknown) as IGitSourceSettings
|
const result = {} as unknown as IGitSourceSettings
|
||||||
|
|
||||||
// GitHub workspace
|
// GitHub workspace
|
||||||
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
|
||||||
@@ -121,7 +121,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||||||
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'
|
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'
|
||||||
|
|
||||||
// Workflow organization ID
|
// Workflow organization ID
|
||||||
result.workflowOrganizationId = await workflowContextHelper.getOrganizationId()
|
result.workflowOrganizationId =
|
||||||
|
await workflowContextHelper.getOrganizationId()
|
||||||
|
|
||||||
// Set safe.directory in git global config.
|
// Set safe.directory in git global config.
|
||||||
result.setSafeDirectory =
|
result.setSafeDirectory =
|
||||||
@@ -133,12 +134,19 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||||||
'TRUE'
|
'TRUE'
|
||||||
core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`)
|
core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`)
|
||||||
|
|
||||||
unsafePrCheckoutHelper.assertSafePrCheckout({
|
// The default self-checkout (this repository with no explicit ref) always
|
||||||
qualifiedRepository,
|
// resolves to the trusted ref/commit GitHub set for the triggering event, so
|
||||||
ref: result.ref,
|
// the fork-checkout guard only needs to run when the caller customized the
|
||||||
commit: result.commit,
|
// repository or ref.
|
||||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
const isDefaultCheckout = isWorkflowRepository && !core.getInput('ref')
|
||||||
})
|
if (!isDefaultCheckout) {
|
||||||
|
unsafePrCheckoutHelper.assertSafePrCheckout({
|
||||||
|
qualifiedRepository,
|
||||||
|
ref: result.ref,
|
||||||
|
commit: result.commit,
|
||||||
|
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user