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:32:07 +01:00
parent b1df8e93a6
commit a12225cd31
4 changed files with 59 additions and 16 deletions

20
dist/index.js vendored
View File

@@ -2014,7 +2014,8 @@ function getInputs() {
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
githubServerUrl: result.githubServerUrl
githubServerUrl: result.githubServerUrl,
usesSsh: !!result.sshKey
}, result.authToken);
}
return result;
@@ -2689,8 +2690,8 @@ function assertSafePrCheckout(input, authToken) {
commit &&
input.qualifiedRepository.toLowerCase() ===
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase() &&
(0, url_helper_1.getServerUrl)(input.githubServerUrl).origin === (0, url_helper_1.getServerUrl)().origin) {
return commitIsInWorkflowHistory(authToken, commit, input.githubServerUrl).then(isInHistory => {
fetchesFromWorkflowServer(input)) {
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
if (!isInHistory) {
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.');
@@ -2706,7 +2707,16 @@ 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.`);
}
function commitIsInWorkflowHistory(authToken, 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 = (0, url_helper_1.getServerUrl)(input.githubServerUrl);
const workflowServer = (0, url_helper_1.getServerUrl)();
return input.usesSsh
? checkoutServer.hostname === workflowServer.hostname
: checkoutServer.origin === workflowServer.origin;
}
function commitIsInWorkflowHistory(authToken, commit) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const workflowSha = github.context.sha.toLowerCase();
@@ -2719,7 +2729,7 @@ function commitIsInWorkflowHistory(authToken, commit, githubServerUrl) {
const { owner, repo } = github.context.repo;
try {
const { data } = yield github
.getOctokit(authToken, { baseUrl: (0, url_helper_1.getServerApiUrl)(githubServerUrl) })
.getOctokit(authToken, { baseUrl: (0, url_helper_1.getServerApiUrl)() })
.rest.repos.compareCommitsWithBasehead({
owner,
repo,