-
Notifications
You must be signed in to change notification settings - Fork 53
ci(swift-sdk): add workflow permissions for PR comment posting #3158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
thepastaclaw
wants to merge
1
commit into
dashpay:v3.1-dev
from
thepastaclaw:ci/swift-sdk-comment-permissions
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: dashpay/platform
Length of output: 1475
🌐 Web query:
GitHub Actions permissions block fork pull request write access token restrictions official documentation💡 Result:
GITHUB_TOKENand do not receive secrets (exceptGITHUB_TOKEN). [1]permissions: write-all(or specificwritescopes), fork PR workflows typically still can’t get write access—the repo/admin setting overrides this. [2]pull_request_target): If you usepull_request_target, GitHub grants read/write repo permission toGITHUB_TOKENeven when triggered from a public fork, because the workflow runs in the base repository context (this is powerful and risky if you execute untrusted PR code). [2]Official docs to cite for this behavior:
permissionsbehavior + fork limitation +pull_request_targetread/write note: GitHub “Workflow syntax” [2]Sources: [1] (docs.github.com) [2] (docs.github.com) [3] (docs.github.com)
Citations:
🌐 Web query:
GitHub pull_request_target event workflow write permissions fork security💡 Result:
pull_request_targetis the “privileged” PR trigger in GitHub Actions, and it’s risky with forks because it runs in the base repo context (trusted workflow from the base branch) but is triggered by activity coming from an untrusted fork PR.What changes vs
pull_request(fork security model)pull_requestfrom forks:GITHUB_TOKENis read-only and no secrets are provided (safe-by-default for untrusted contributions). (docs.github.com)pull_request_target:GITHUB_TOKENis read/write by default (unless you restrict viapermissions:) and the workflow can access secrets, even when triggered from a fork. (docs.github.com)The core vulnerability (“pwn request”)
If a
pull_request_targetworkflow checks out the PR’s head commit/branch and then builds/tests/executes anything from it, an attacker can run code with base-repo privileges (exfiltrate secrets, push commits, create releases, poison caches, etc.). (docs.github.com)When
pull_request_targetis appropriateUse it only for actions that treat PR content as data, not executable code—e.g., labeling, commenting, triage, metadata updates. (docs.github.com)
Safer patterns
pull_request, then do privileged actions in a separate workflow triggered byworkflow_run. (codeql.github.com)permissions:(don’t rely on defaults), granting only what the job needs. (docs.github.com)If you share your workflow YAML (especially any
actions/checkoutusage andpermissions:blocks), I can point out the exact fork-to-write escalation paths and how to restructure it safely.Citations:
🏁 Script executed:
Repository: dashpay/platform
Length of output: 996
🏁 Script executed:
Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
Repository: dashpay/platform
Length of output: 441
🏁 Script executed:
Repository: dashpay/platform
Length of output: 3677
🏁 Script executed:
Repository: dashpay/platform
Length of output: 140
🏁 Script executed:
Repository: dashpay/platform
Length of output: 42
🏁 Script executed:
Repository: dashpay/platform
Length of output: 129
The
permissionsblock cannot grant write access for external fork PRs—this fix is incomplete.GitHub's security model mandates that pull requests from public forks always receive a read-only
GITHUB_TOKEN, regardless of thepermissionsblock settings in the workflow. This means the addedpermissionsblock will only fix the 403 for PRs opened from same-repo branches (i.e., from collaborators with push access).If PR
#3137originated from an external fork, theissues: writepermission will be silently downgraded to read-only by GitHub, and the comment step will continue to fail with a 403.To reliably post comments for fork PRs, use one of these approaches:
Split workflow (recommended): Create a separate
workflow_run-triggered job that runs in the base-repo context:pull_requestjob builds artifacts and uploads them (no write needed).workflow_runjob then runs after completion, retrieves the artifact, and posts the comment with write access.Repository setting: Enable "Send write tokens to workflows from pull requests" in the repo settings. This grants write permissions to fork PR workflows—note that this carries security implications, especially with self-hosted runners.
pull_request_targetevent: Usepull_request_targetinstead ofpull_requestto run in the base-repo context with write access. Only use this if the workflow does not check out and execute untrusted PR code, as it creates a "pwn request" vulnerability.🤖 Prompt for AI Agents