Fix web preview proxy hardening#100
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Cloudflare Pages “web preview” pipeline by moving the same-origin /api/* proxying logic into a Pages Function and tightening GitHub Actions secret exposure and commenting behavior.
Changes:
- Add a Cloudflare Pages Function at
functions/api/[[path]].jsto proxy same-origin/api/*requests to a configured companion API base URL at runtime. - Harden
.github/workflows/web-preview.ymlby scoping Cloudflare credentials to only the configuration/deploy steps, disabling checkout credential persistence, and passingGH_TOKENonly to the PR comment step. - Generate the preview comment body without leading indentation to avoid unintended Markdown formatting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| functions/api/[[path]].js | Introduces the /api/* Pages Function proxy used by web previews. |
| .github/workflows/web-preview.yml | Restricts credential exposure and improves preview comment generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e24117a609
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c4c71a124
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b1ffff10f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } catch { | ||
| return true; | ||
| } | ||
| if (decodedSegment.split(/[\\/]/).some((part) => part === "." || part === "..")) { |
There was a problem hiding this comment.
Allow slash-dot MXID localparts
The fresh evidence in this revision is that decodedSegment.split(/[\\/]) still treats an encoded slash inside a single route parameter as path hierarchy. When a valid Matrix user ID localpart contains /./ or /../ (the Matrix grammar allows both . and / as opaque localpart characters), matrixTransport sends it as one percent-encoded segment such as /api/presence/%40a%2F.%2Fb%3Aexample.org, but this check returns 400 before the companion sees it; since the target URL keeps %2F encoded, this blocks legal MXIDs rather than preventing traversal.
Useful? React with 👍 / 👎.
Description
Follow-up to #98 for the unresolved web-preview review threads:
_redirectsproxy with a Pages Function under/api/*.GH_TOKENonly to the comment step.Related to #98:
Fixes #
Type of change
Checklist:
pnpm lint,pnpm fmt:check,pnpm typecheck,pnpm test:coverage,pnpm knip, andpnpm buildall pass locallyValidation run for this workflow-only change:
actionlint .github/workflows/web-preview.ymlpnpm fmt:checknode --check 'functions/api/[[path]].js'npx --yes wrangler@4.107.1 pages functions build functions --outfile /tmp/charm-pr98-web-preview-functions.jsAI disclosure:
Codex assisted with the workflow hardening and Pages Function proxy follow-up. The function forwards same-origin
/api/*preview requests to the configured companion API base at runtime, keeping authenticated preview traffic same-site for the browser while avoiding unsupported_redirectsexternal proxying.