mirror of
https://github.com/actions/checkout.git
synced 2026-12-03 18:00:06 +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
57c9bdfe25
commit
b1df8e93a6
Vendored
+8
-5
@@ -2013,7 +2013,8 @@ function getInputs() {
|
||||
qualifiedRepository,
|
||||
ref: result.ref,
|
||||
commit: result.commit,
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
|
||||
githubServerUrl: result.githubServerUrl
|
||||
}, result.authToken);
|
||||
}
|
||||
return result;
|
||||
@@ -2632,6 +2633,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.assertSafePrCheckout = assertSafePrCheckout;
|
||||
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) {
|
||||
@@ -2686,8 +2688,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.');
|
||||
@@ -2703,7 +2706,7 @@ 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) {
|
||||
function commitIsInWorkflowHistory(authToken, commit, githubServerUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
const workflowSha = github.context.sha.toLowerCase();
|
||||
@@ -2716,7 +2719,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,
|
||||
|
||||
Reference in New Issue
Block a user