mirror of
https://github.com/actions/checkout.git
synced 2026-12-04 03:22:56 +08: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:
@@ -196,7 +196,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
qualifiedRepository,
|
||||
ref: result.ref,
|
||||
commit: result.commit,
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
|
||||
githubServerUrl: result.githubServerUrl
|
||||
},
|
||||
result.authToken
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as github from '@actions/github'
|
||||
import {fromPayload} from './ref-helper'
|
||||
import {getServerApiUrl, getServerUrl} from './url-helper'
|
||||
|
||||
const PR_REF_PATTERN = /^refs\/pull\/[0-9]+\/(?:head|merge)$/
|
||||
|
||||
@@ -8,6 +9,7 @@ export interface IUnsafePrCheckoutInput {
|
||||
ref: string
|
||||
commit: string | undefined
|
||||
allowUnsafePrCheckout: boolean
|
||||
githubServerUrl?: string
|
||||
}
|
||||
|
||||
export function assertSafePrCheckout(
|
||||
@@ -76,9 +78,14 @@ export function assertSafePrCheckout(
|
||||
!input.ref &&
|
||||
commit &&
|
||||
input.qualifiedRepository.toLowerCase() ===
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase()
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase() &&
|
||||
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin
|
||||
) {
|
||||
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
|
||||
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. ' +
|
||||
@@ -102,7 +109,8 @@ export function assertSafePrCheckout(
|
||||
|
||||
async function commitIsInWorkflowHistory(
|
||||
authToken: string,
|
||||
commit: string
|
||||
commit: string,
|
||||
githubServerUrl?: string
|
||||
): Promise<boolean> {
|
||||
const workflowSha = github.context.sha.toLowerCase()
|
||||
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(workflowSha)) {
|
||||
@@ -117,7 +125,7 @@ async function commitIsInWorkflowHistory(
|
||||
const {owner, repo} = github.context.repo
|
||||
try {
|
||||
const {data} = await github
|
||||
.getOctokit(authToken)
|
||||
.getOctokit(authToken, {baseUrl: getServerApiUrl(githubServerUrl)})
|
||||
.rest.repos.compareCommitsWithBasehead({
|
||||
owner,
|
||||
repo,
|
||||
|
||||
Reference in New Issue
Block a user