mirror of
https://github.com/actions/checkout.git
synced 2026-12-04 12:40:03 +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
f99369cddc
commit
a6d00f2c31
+2
-1
@@ -197,7 +197,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
ref: result.ref,
|
||||
commit: result.commit,
|
||||
allowUnsafePrCheckout: result.allowUnsafePrCheckout,
|
||||
githubServerUrl: result.githubServerUrl
|
||||
githubServerUrl: result.githubServerUrl,
|
||||
usesSsh: !!result.sshKey
|
||||
},
|
||||
result.authToken
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface IUnsafePrCheckoutInput {
|
||||
commit: string | undefined
|
||||
allowUnsafePrCheckout: boolean
|
||||
githubServerUrl?: string
|
||||
usesSsh?: boolean
|
||||
}
|
||||
|
||||
export function assertSafePrCheckout(
|
||||
@@ -79,13 +80,9 @@ export function assertSafePrCheckout(
|
||||
commit &&
|
||||
input.qualifiedRepository.toLowerCase() ===
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`.toLowerCase() &&
|
||||
getServerUrl(input.githubServerUrl).origin === getServerUrl().origin
|
||||
fetchesFromWorkflowServer(input)
|
||||
) {
|
||||
return commitIsInWorkflowHistory(
|
||||
authToken,
|
||||
commit,
|
||||
input.githubServerUrl
|
||||
).then(isInHistory => {
|
||||
return commitIsInWorkflowHistory(authToken, commit).then(isInHistory => {
|
||||
if (!isInHistory) {
|
||||
throw new Error(
|
||||
'Refusing to check out the requested commit for this fork pull request. ' +
|
||||
@@ -107,10 +104,19 @@ export function assertSafePrCheckout(
|
||||
)
|
||||
}
|
||||
|
||||
// SSH fetch URLs keep only the hostname, so the scheme and port cannot
|
||||
// distinguish the checkout server from the workflow server.
|
||||
function fetchesFromWorkflowServer(input: IUnsafePrCheckoutInput): boolean {
|
||||
const checkoutServer = getServerUrl(input.githubServerUrl)
|
||||
const workflowServer = getServerUrl()
|
||||
return input.usesSsh
|
||||
? checkoutServer.hostname === workflowServer.hostname
|
||||
: checkoutServer.origin === workflowServer.origin
|
||||
}
|
||||
|
||||
async function commitIsInWorkflowHistory(
|
||||
authToken: string,
|
||||
commit: string,
|
||||
githubServerUrl?: string
|
||||
commit: string
|
||||
): Promise<boolean> {
|
||||
const workflowSha = github.context.sha.toLowerCase()
|
||||
if (!/^[0-9a-f]{40}$/.test(workflowSha)) {
|
||||
@@ -125,7 +131,7 @@ async function commitIsInWorkflowHistory(
|
||||
const {owner, repo} = github.context.repo
|
||||
try {
|
||||
const {data} = await github
|
||||
.getOctokit(authToken, {baseUrl: getServerApiUrl(githubServerUrl)})
|
||||
.getOctokit(authToken, {baseUrl: getServerApiUrl()})
|
||||
.rest.repos.compareCommitsWithBasehead({
|
||||
owner,
|
||||
repo,
|
||||
|
||||
Reference in New Issue
Block a user