Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/__test__
diff options
context:
space:
mode:
Diffstat (limited to '__test__')
-rw-r--r--__test__/input-helper.test.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts
index b2f9074..27b023c 100644
--- a/__test__/input-helper.test.ts
+++ b/__test__/input-helper.test.ts
@@ -180,4 +180,50 @@ describe('input-helper tests', () => {
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.workflowOrganizationId).toBe(123456)
})
+
+ describe('unsafe PR checkout guard', () => {
+ const forkPayload = {
+ repository: {id: 100},
+ pull_request: {
+ head: {
+ sha: '1234567890123456789012345678901234567890',
+ repo: {id: 200, full_name: 'attacker/fork'}
+ },
+ merge_commit_sha: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ }
+ }
+
+ it('allows the default self-checkout on a fork pull_request_target', async () => {
+ const originalEvent = mockGithubContext.eventName
+ const originalPayload = mockGithubContext.payload
+ try {
+ mockGithubContext.eventName = 'pull_request_target'
+ mockGithubContext.payload = forkPayload
+ // Simulate a rebase/fast-forward merge where the base tip (event SHA)
+ // equals the PR head SHA. The default self-checkout must still succeed.
+ mockGithubContext.sha = '1234567890123456789012345678901234567890'
+ const settings: IGitSourceSettings = await inputHelper.getInputs()
+ expect(settings.commit).toBe('1234567890123456789012345678901234567890')
+ } finally {
+ mockGithubContext.eventName = originalEvent
+ mockGithubContext.payload = originalPayload
+ }
+ })
+
+ it('refuses an explicit fork repository on pull_request_target', async () => {
+ const originalEvent = mockGithubContext.eventName
+ const originalPayload = mockGithubContext.payload
+ try {
+ mockGithubContext.eventName = 'pull_request_target'
+ mockGithubContext.payload = forkPayload
+ inputs.repository = 'attacker/fork'
+ await expect(inputHelper.getInputs()).rejects.toThrow(
+ /Refusing to check out fork pull request code/
+ )
+ } finally {
+ mockGithubContext.eventName = originalEvent
+ mockGithubContext.payload = originalPayload
+ }
+ })
+ })
})