mirror of
https://github.com/actions/checkout.git
synced 2026-12-03 22:40:06 +00: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:
co-authored by
Copilot App
parent
8b33a4c30e
commit
152ac2d544
Vendored
+15
-5
@@ -42024,8 +42024,8 @@ async function assertSafePrCheckout(input, authToken) {
|
||||
const { owner, repo } = github_context.repo;
|
||||
if (input.qualifiedRepository.toLowerCase() ===
|
||||
`${owner}/${repo}`.toLowerCase() &&
|
||||
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin &&
|
||||
!(await commitIsInWorkflowHistory(authToken, owner, repo, commit, input.githubServerUrl))) {
|
||||
fetchesFromWorkflowServer(input) &&
|
||||
!(await commitIsInWorkflowHistory(authToken, owner, repo, commit))) {
|
||||
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.');
|
||||
}
|
||||
@@ -42039,7 +42039,16 @@ 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, githubServerUrl) {
|
||||
// SSH fetch URLs keep only the hostname, so the scheme and port cannot
|
||||
// distinguish the checkout server from the workflow server.
|
||||
function fetchesFromWorkflowServer(input) {
|
||||
const checkoutServer = getServerUrl(input.githubServerUrl);
|
||||
const workflowServer = getServerUrl();
|
||||
return input.usesSsh
|
||||
? checkoutServer.hostname === workflowServer.hostname
|
||||
: checkoutServer.origin === workflowServer.origin;
|
||||
}
|
||||
async function commitIsInWorkflowHistory(authToken, owner, repo, commit) {
|
||||
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.');
|
||||
@@ -42049,7 +42058,7 @@ async function commitIsInWorkflowHistory(authToken, owner, repo, commit, githubS
|
||||
}
|
||||
try {
|
||||
// Compare immutable commits so the result does not depend on current PR metadata.
|
||||
const { data } = await getOctokit(authToken, { baseUrl: getServerApiUrl(githubServerUrl) })
|
||||
const { data } = await getOctokit(authToken, { baseUrl: getServerApiUrl() })
|
||||
.rest.repos.compareCommitsWithBasehead({
|
||||
owner,
|
||||
repo,
|
||||
@@ -42255,7 +42264,8 @@ async function getInputs() {
|
||||
ref: result.ref,
|
||||
commit: result.commit,
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
|
||||
githubServerUrl: result.githubServerUrl
|
||||
githubServerUrl: result.githubServerUrl,
|
||||
usesSsh: !!result.sshKey
|
||||
}, result.authToken);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user