mirror of
https://github.com/actions/checkout.git
synced 2026-12-03 19:10:01 +00:00
Scope workflow history verification to the checkout server
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot App
parent
a4ddf0647e
commit
8b33a4c30e
Vendored
+7
-4
@@ -41969,6 +41969,7 @@ async function getGitCommandManager(settings) {
|
||||
;// CONCATENATED MODULE: ./src/unsafe-pr-checkout-helper.ts
|
||||
|
||||
|
||||
|
||||
const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/;
|
||||
async function assertSafePrCheckout(input, authToken) {
|
||||
if (input.allowUnsafePrCheckout) {
|
||||
@@ -42023,7 +42024,8 @@ async function assertSafePrCheckout(input, authToken) {
|
||||
const { owner, repo } = github_context.repo;
|
||||
if (input.qualifiedRepository.toLowerCase() ===
|
||||
`${owner}/${repo}`.toLowerCase() &&
|
||||
!(await commitIsInWorkflowHistory(authToken, owner, repo, commit))) {
|
||||
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin &&
|
||||
!(await commitIsInWorkflowHistory(authToken, owner, repo, commit, input.githubServerUrl))) {
|
||||
throw new Error('Refusing to check out the requested commit for this fork pull request. ' +
|
||||
'The commit is not verified to be in the workflow commit history. Use a trusted branch ref.');
|
||||
}
|
||||
@@ -42037,7 +42039,7 @@ async function assertSafePrCheckout(input, authToken) {
|
||||
`at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' ` +
|
||||
`on the actions/checkout step.`);
|
||||
}
|
||||
async function commitIsInWorkflowHistory(authToken, owner, repo, commit) {
|
||||
async function commitIsInWorkflowHistory(authToken, owner, repo, commit, githubServerUrl) {
|
||||
const workflowSha = github_context.sha?.toLowerCase() || '';
|
||||
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(workflowSha)) {
|
||||
throw new Error('Unable to verify the requested commit: the workflow commit SHA is missing or invalid.');
|
||||
@@ -42047,7 +42049,7 @@ async function commitIsInWorkflowHistory(authToken, owner, repo, commit) {
|
||||
}
|
||||
try {
|
||||
// Compare immutable commits so the result does not depend on current PR metadata.
|
||||
const { data } = await getOctokit(authToken)
|
||||
const { data } = await getOctokit(authToken, { baseUrl: getServerApiUrl(githubServerUrl) })
|
||||
.rest.repos.compareCommitsWithBasehead({
|
||||
owner,
|
||||
repo,
|
||||
@@ -42252,7 +42254,8 @@ async function getInputs() {
|
||||
qualifiedRepository,
|
||||
ref: result.ref,
|
||||
commit: result.commit,
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
|
||||
githubServerUrl: result.githubServerUrl
|
||||
}, result.authToken);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user