diff --git a/.github/PROJECT_SYNC.md b/.github/PROJECT_SYNC.md index caab003bcb0..b05cbf53389 100644 --- a/.github/PROJECT_SYNC.md +++ b/.github/PROJECT_SYNC.md @@ -30,6 +30,8 @@ or deletes source Issues/PRs. not count. Populate PR links and actual release tag/URL, never guess a version. - Issue/PR lifecycle events read only their subject and bounded linked issues/PRs, including old/new body references and previously stored implementation links. + Fork-origin PR events are skipped to avoid spending an Actions run per fork event; + the scheduled reconciliation still observes their final repository-visible state. They do not scan repository Issues, PRs, Project items, or releases. Six-hour scheduled and manual runs do full reconciliation; changes discovered only by broad push/release scans wait until the next scheduled or manual run. diff --git a/.github/workflows/project-sync.yml b/.github/workflows/project-sync.yml index cae724a1934..143469108da 100644 --- a/.github/workflows/project-sync.yml +++ b/.github/workflows/project-sync.yml @@ -26,7 +26,11 @@ concurrency: jobs: sync: - if: github.repository == 'AstrBotDevs/AstrBot' && vars.ASTRBOT_PROJECT_ID != '' + if: >- + github.repository == 'AstrBotDevs/AstrBot' && + vars.ASTRBOT_PROJECT_ID != '' && + (github.event_name != 'pull_request_target' || + github.event.pull_request.head.repo.full_name == github.repository) # Configure this environment to allow only the default branch before adding secrets. environment: project-sync runs-on: ubuntu-latest diff --git a/tests/test_sync_github_project.py b/tests/test_sync_github_project.py index 692348b0696..6810e903488 100644 --- a/tests/test_sync_github_project.py +++ b/tests/test_sync_github_project.py @@ -303,6 +303,19 @@ def test_schedule_uses_configured_default_branch(self): class WorkflowSecurityTests(unittest.TestCase): + def test_fork_pull_request_events_are_filtered_at_job_boundary(self): + workflow = ( + SCRIPT.parents[1] / ".github/workflows/project-sync.yml" + ).read_text() + job_condition = workflow.split(" sync:\n", 1)[1].split( + " environment:", 1 + )[0] + self.assertIn("github.event_name != 'pull_request_target'", job_condition) + self.assertIn( + "github.event.pull_request.head.repo.full_name == github.repository", + job_condition, + ) + def test_sync_job_requires_environment_before_any_steps(self): workflow = ( SCRIPT.parents[1] / ".github/workflows/project-sync.yml"