diff options
| author | Aiqiao Yan <55104035+aiqiaoy@users.noreply.github.com> | 2026-07-07 16:34:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-07 16:34:16 -0400 |
| commit | ced100813c147e2fc3ca692ddc52876ed2358c51 (patch) | |
| tree | a3e9785ead5e277b5d38735b9436d8a90b9956ab /dist | |
| parent | bc8e7a2fc551aab4af101037f06bd94d72c7df97 (diff) | |
backport `allow-unsafe-pr-checkout` to v2 (#2504)
* block checking out fork pr for pull_request_target and workflow_run (#2454)
* block checking out fork pr for some events
* address copilot and reviewer feedback
* run prettier formatting
* build
* update urls
* update readme
* update description and url again
* edit url one more time
* update error wording (#2467)
* bump upload-artifact
* rebuild
Diffstat (limited to 'dist')
| -rw-r--r-- | dist/index.js | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/dist/index.js b/dist/index.js index cfa7728..dbd2dbb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4740,7 +4740,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0; +exports.fromPayload = exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0; const url_1 = __webpack_require__(835); const core = __importStar(__webpack_require__(470)); const github = __importStar(__webpack_require__(469)); @@ -4958,6 +4958,7 @@ exports.checkCommitInfo = checkCommitInfo; function fromPayload(path) { return select(github.context.payload, path); } +exports.fromPayload = fromPayload; function select(obj, path) { if (!obj) { return undefined; @@ -13324,6 +13325,102 @@ function getNextPage (octokit, link, headers) { /***/ }), +/***/ 554: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.assertSafePrCheckout = void 0; +const github = __importStar(__webpack_require__(469)); +const ref_helper_1 = __webpack_require__(227); +const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/; +function assertSafePrCheckout(input) { + if (input.allowUnsafePrCheckout) { + return; + } + const eventName = github.context.eventName; + if (eventName !== 'pull_request_target' && eventName !== 'workflow_run') { + return; + } + const baseRepoId = (0, ref_helper_1.fromPayload)('repository.id'); + if (typeof baseRepoId !== 'number') { + return; + } + let prHeadRepoId; + let prHeadRepoFullName; + const prShas = []; + if (eventName === 'pull_request_target') { + prHeadRepoId = (0, ref_helper_1.fromPayload)('pull_request.head.repo.id'); + prHeadRepoFullName = (0, ref_helper_1.fromPayload)('pull_request.head.repo.full_name'); + pushIfSha(prShas, (0, ref_helper_1.fromPayload)('pull_request.head.sha')); + pushIfSha(prShas, (0, ref_helper_1.fromPayload)('pull_request.merge_commit_sha')); + } + else { + const wrEvent = (0, ref_helper_1.fromPayload)('workflow_run.event'); + if (typeof wrEvent !== 'string' || !wrEvent.startsWith('pull_request')) { + return; + } + prHeadRepoId = (0, ref_helper_1.fromPayload)('workflow_run.head_repository.id'); + prHeadRepoFullName = (0, ref_helper_1.fromPayload)('workflow_run.head_repository.full_name'); + pushIfSha(prShas, (0, ref_helper_1.fromPayload)('workflow_run.head_commit.id')); + // For `pull_request_target`-triggered workflow_run, `head_sha` is the base + // default branch SHA (not the PR head) + if (wrEvent !== 'pull_request_target') { + pushIfSha(prShas, (0, ref_helper_1.fromPayload)('workflow_run.head_sha')); + } + } + // (A) Fork PR? + if (typeof prHeadRepoId !== 'number' || prHeadRepoId === baseRepoId) { + return; + } + // (B) We cannot check for all fork PR refs so check to see + // if the resolved input points to the fork PR sha we have in the payload + const repositoryMatchesPrHead = typeof prHeadRepoFullName === 'string' && + input.qualifiedRepository.toLowerCase() === prHeadRepoFullName.toLowerCase(); + const refMatchesPullPattern = PR_REF_PATTERN.test(input.ref); + const commitMatchesPrHeadSha = !!input.commit && prShas.includes(input.commit.toLowerCase()); + if (!repositoryMatchesPrHead && + !refMatchesPullPattern && + !commitMatchesPrHeadSha) { + return; + } + throw new Error(`Refusing to check out fork pull request code from a '${eventName}' workflow. ` + + `This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch ` + + `cache scope, and runner access. Fetching and executing a fork's code in that trusted ` + + `context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks ` + + `at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' ` + + `on the actions/checkout step.`); +} +exports.assertSafePrCheckout = assertSafePrCheckout; +function pushIfSha(target, value) { + if (typeof value === 'string' && value.length > 0) { + target.push(value.toLowerCase()); + } +} + + +/***/ }), + /***/ 558: /***/ (function(module, __unusedexports, __webpack_require__) { @@ -18372,6 +18469,7 @@ const core = __importStar(__webpack_require__(470)); const fsHelper = __importStar(__webpack_require__(618)); const github = __importStar(__webpack_require__(469)); const path = __importStar(__webpack_require__(622)); +const unsafePrCheckoutHelper = __importStar(__webpack_require__(554)); const workflowContextHelper = __importStar(__webpack_require__(642)); function getInputs() { return __awaiter(this, void 0, void 0, function* () { @@ -18465,6 +18563,17 @@ function getInputs() { // Set safe.directory in git global config. result.setSafeDirectory = (core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE'; + // Allow unsafe PR checkout (opt-in for pull_request_target / workflow_run fork PRs) + result.allowUnsafePrCheckout = + (core.getInput('allow-unsafe-pr-checkout') || 'false').toUpperCase() === + 'TRUE'; + core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`); + unsafePrCheckoutHelper.assertSafePrCheckout({ + qualifiedRepository, + ref: result.ref, + commit: result.commit, + allowUnsafePrCheckout: result.allowUnsafePrCheckout + }); return result; }); } |
