Properly support previews in GitHub Actions #410
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.
We need access to the Cloudflare token to write the preview page, but we don't want this token to be available to code controlled by the pull request. Before this change the action used
pull_request_target
to get has write permissions, but as a consequence, it ran on the target branch so that it didn't run untrusted code from the pull request, so it didn't preview the right thing.Instead, follow the approach outlined in
https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ by splitting the work into two workflows in the pull request case. The first runs the build without access to secrets and stores the build result as a GHA artifact, and the second fetches the artifact and publishes the preview without running untrusted code.
This is untested and will probably need some tweaking once it lands to see if it's working right.