mirror of
https://github.com/actions/checkout.git
synced 2026-12-03 21:30:04 +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
bea5d06012
commit
6aec1b2363
Vendored
+15
-5
@@ -1807,7 +1807,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;
|
||||
@@ -2460,8 +2461,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.');
|
||||
@@ -2478,7 +2479,16 @@ function assertSafePrCheckout(input, authToken) {
|
||||
`on the actions/checkout step.`);
|
||||
}
|
||||
exports.assertSafePrCheckout = assertSafePrCheckout;
|
||||
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) {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const workflowSha = github.context.sha.toLowerCase();
|
||||
@@ -2491,7 +2501,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,
|
||||
|
||||
Reference in New Issue
Block a user