Ignore a .git suffix when matching checkout repositories

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Francesco Renzi
2026-12-04 11:08:08 +01:00
co-authored by Copilot App
parent 152ac2d544
commit e3c9da6753
4 changed files with 59 additions and 6 deletions
+8 -3
View File
@@ -42012,8 +42012,9 @@ async function assertSafePrCheckout(input, authToken) {
}
// (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 repository = repositoryIdentity(input.qualifiedRepository);
const repositoryMatchesPrHead = typeof prHeadRepoFullName === 'string' &&
input.qualifiedRepository.toLowerCase() === prHeadRepoFullName.toLowerCase();
repository === prHeadRepoFullName.toLowerCase();
const refMatchesPullPattern = PR_REF_PATTERN.test(input.ref);
const commit = input.commit?.toLowerCase();
const commitMatchesPrHeadSha = !!commit && prShas.includes(commit);
@@ -42022,8 +42023,7 @@ async function assertSafePrCheckout(input, authToken) {
!commitMatchesPrHeadSha) {
if (eventName === 'workflow_run' && !input.ref && commit) {
const { owner, repo } = github_context.repo;
if (input.qualifiedRepository.toLowerCase() ===
`${owner}/${repo}`.toLowerCase() &&
if (repository === `${owner}/${repo}`.toLowerCase() &&
fetchesFromWorkflowServer(input) &&
!(await commitIsInWorkflowHistory(authToken, owner, repo, commit))) {
throw new Error('Refusing to check out the requested commit for this fork pull request. ' +
@@ -42039,6 +42039,11 @@ async 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.`);
}
// Git transports resolve 'owner/repo.git' to 'owner/repo', so compare
// repositories without one terminal '.git' suffix.
function repositoryIdentity(qualifiedRepository) {
return qualifiedRepository.replace(/\.git$/, '').toLowerCase();
}
// SSH fetch URLs keep only the hostname, so the scheme and port cannot
// distinguish the checkout server from the workflow server.
function fetchesFromWorkflowServer(input) {