fix: skip Sonar analysis for fork PRs to prevent code execution#330
Conversation
Fork PRs could execute untrusted build scripts (build.gradle.kts, buildSrc) with access to SONAR_TOKEN. Skip Sonar for fork PRs entirely and only checkout from the base repository.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Unit Tests 62 files ±0 62 suites ±0 3m 2s ⏱️ -6s Results for commit 2c13029. ± Comparison against base commit 81b9952. This pull request removes 39 and adds 39 tests. Note that renamed tests count towards both. |
Summary
repository:from checkout since we now only run for the base repoContext
SonarCloud security hotspot flagged that the
sonarjob inanalysis.ymlchecks out fork code (github.event.workflow_run.head_repository.full_name) and then executes./gradlew sonar— which runs the fork'sbuild.gradle.ktsandbuildSrc/with access toSONAR_TOKEN. A malicious fork contributor could exfiltrate the token.The fix adds a condition to skip the sonar job when the triggering workflow comes from a fork. Fork PRs still get the full build and test suite from the main
build-and-test.ymlworkflow — they just don't get Sonar analysis. The push-to-main Sonar run after merge catches any issues.The
coverage-commentjob is unaffected — it doesn't checkout or execute any code.Test plan
Summary by CodeRabbit