Scope workflow history verification to the checkout server

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Francesco Renzi
2026-12-03 18:14:19 +01:00
parent 3c9b07f567
commit bea5d06012
4 changed files with 112 additions and 10 deletions

13
dist/index.js vendored
View File

@@ -1806,7 +1806,8 @@ function getInputs() {
qualifiedRepository,
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
githubServerUrl: result.githubServerUrl
}, result.authToken);
}
return result;
@@ -2403,6 +2404,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.assertSafePrCheckout = void 0;
const github = __importStar(__nccwpck_require__(5438));
const ref_helper_1 = __nccwpck_require__(8601);
const url_helper_1 = __nccwpck_require__(9437);
const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/;
function assertSafePrCheckout(input, authToken) {
if (input.allowUnsafePrCheckout) {
@@ -2457,8 +2459,9 @@ function assertSafePrCheckout(input, authToken) {
!input.ref &&
commit &&
input.qualifiedRepository.toLowerCase() ===
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase()) {
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
`${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 => {
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.');
@@ -2475,7 +2478,7 @@ function assertSafePrCheckout(input, authToken) {
`on the actions/checkout step.`);
}
exports.assertSafePrCheckout = assertSafePrCheckout;
function commitIsInWorkflowHistory(authToken, commit) {
function commitIsInWorkflowHistory(authToken, commit, githubServerUrl) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const workflowSha = github.context.sha.toLowerCase();
@@ -2488,7 +2491,7 @@ function commitIsInWorkflowHistory(authToken, commit) {
const { owner, repo } = github.context.repo;
try {
const { data } = yield github
.getOctokit(authToken)
.getOctokit(authToken, { baseUrl: (0, url_helper_1.getServerApiUrl)(githubServerUrl) })
.rest.repos.compareCommitsWithBasehead({
owner,
repo,