fix(ci): record and use the PR number to post the comment#286
Conversation
polarathene
left a comment
There was a problem hiding this comment.
At a glance I think these changes would introduce an exploit to enable an attacker access to a trusted workflow environment with access to secrets?
I've linked an alternative approach that demonstrates how to get a PR number more safely.
There was a problem hiding this comment.
Short version:
⚠️ Careful with expression use for action inputs likerun. The contents is interpolated by GHA before processed by the action (in this case shell script execution). An attacker can manipulate their branch name to compromise this workflow and gain access to secrets.- I've provided two suggested revisions with notes, but the
gh pr list(GraphQL) suggestion is more strict on searching for the intended PR and should be less at risk to trigger secondary rate limits (but for this repo I don't think you have the activity for that to be a real concern).
| uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8 # v2 | ||
| with: | ||
| message-path: benchmark-report.txt | ||
| issue: ${{ github.event.workflow_run.pull_requests[0].number }} |
There was a problem hiding this comment.
Just for context of this removal for anyone interested, github.event.workflow_run.pull_requests is only present when the PR is not a branch from a fork of the repo IIRC, so it's an unreliable source.
There was a problem hiding this comment.
I'm missing something the context for this PR... how come we have the PR at hand and not the number?
This whole workflow is conditioning on github.event.workflow_run.event == 'pull_request'.
I realize that this is all being done in the name of security, but the amout of fiddling with stuff that supposedly should be simple really makes it feel like we'll see more serious issues soon.
There was a problem hiding this comment.
I'm missing something the context for this PR... how come we have the PR at hand and not the number?
This workflow is triggered by the other one and is receiving a github.event.workflow_run payload. However github.event.workflow_run.pull_requests is empty when triggered from a fork. This issue was raised to GitHub multiple times, but AFAIK they never really answered nor addressed it. So we have to work around that and resort to a more convoluted method to get the PR number.
letFunny
left a comment
There was a problem hiding this comment.
A couple of questions only. Sad state of affairs for Github, honestly. Thanks for the work here!
letFunny
left a comment
There was a problem hiding this comment.
Thanks for working on this Paul, we discussed offline and this looks like one of the safest and simplest approaches. It is a bit sad that:
- There is not a good way in Github to do something as trivial as posting a comment securely.
- There is no standardized action in Canonical that has been vetted by security.
For now, let's move forward with this.
| uses: mshick/add-pr-comment@dd126dd8c253650d181ad9538d8b4fa218fc31e8 # v2 | ||
| with: | ||
| message-path: benchmark-report.txt | ||
| issue: ${{ github.event.workflow_run.pull_requests[0].number }} |
There was a problem hiding this comment.
I'm missing something the context for this PR... how come we have the PR at hand and not the number?
This whole workflow is conditioning on github.event.workflow_run.event == 'pull_request'.
I realize that this is all being done in the name of security, but the amout of fiddling with stuff that supposedly should be simple really makes it feel like we'll see more serious issues soon.
|
@niemeyer If you are aware of a better way to approach this, let me know. Review already addressed two concerns where the contributor could have gained access to secrets 😓 If you would like to simplify it in this case you could just upload the PR number from Below is just extra context on the security decisions if it's helpful.
As mentioned in earlier review comment (which yours appears associated to but Github shows it disjoint on my end at least), the information is not available from PRs coming from other forks.
It's an unfortunate issue with public CI running with third-party contributions that can add untrusted code (a contributor can modify the Thus if you need access to secrets, you must do this fiddling to volley over into a trusted workflow. For a common scenario like needing a PR number as you switch between the untrusted If you'd like me to direct you to advice from the Github Security Labs team, let me know. It's possible to do an alternative with the
The approach taken in this PR here is much safer as only the PR number is needed to add a comment (paired with a markdown document that the PR author could manipulate the file content of). The approach taken here is more important if you did have execution of untrusted code occurring (which you'd handle that in the |
Properly get the PR number associated to the benchmark run to post the comment
in the right place.
The approach tries to limit injection risk, applying the strategy recommended in
https://securitylab.github.com/resources/github-actions-untrusted-input
Tested with upils#12 after merging this change in my fork.