Skip to content

Fix web preview proxy hardening#100

Merged
Just-Insane merged 13 commits into
mainfrom
codex/pr98-web-preview-followup
Jul 9, 2026
Merged

Fix web preview proxy hardening#100
Just-Insane merged 13 commits into
mainfrom
codex/pr98-web-preview-followup

Conversation

@Just-Insane

Copy link
Copy Markdown
Contributor

Description

Follow-up to #98 for the unresolved web-preview review threads:

  • Replace the unsupported external _redirects proxy with a Pages Function under /api/*.
  • Keep Cloudflare deploy secrets out of the checkout/install/build steps; only config/deploy steps receive deploy credentials.
  • Disable checkout credential persistence and pass GH_TOKEN only to the comment step.
  • Generate the preview comment body without leading Markdown indentation.

Related to #98:

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • pnpm lint, pnpm fmt:check, pnpm typecheck, pnpm test:coverage, pnpm knip, and pnpm build all pass locally

Validation run for this workflow-only change:

  • actionlint .github/workflows/web-preview.yml
  • pnpm fmt:check
  • node --check 'functions/api/[[path]].js'
  • npx --yes wrangler@4.107.1 pages functions build functions --outfile /tmp/charm-pr98-web-preview-functions.js

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

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 _redirects external proxying.

Copilot AI review requested due to automatic review settings July 9, 2026 11:43
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 11:43 — with GitHub Actions Inactive
Comment thread functions/api/[[path]].js Outdated
Comment thread functions/api/[[path]].js Outdated
@Just-Insane Just-Insane enabled auto-merge July 9, 2026 11:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]].js to proxy same-origin /api/* requests to a configured companion API base URL at runtime.
  • Harden .github/workflows/web-preview.yml by scoping Cloudflare credentials to only the configuration/deploy steps, disabling checkout credential persistence, and passing GH_TOKEN only 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.

Comment thread functions/api/[[path]].js
Comment thread functions/api/[[path]].js Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 11:49
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 11:49 — with GitHub Actions Inactive
Comment thread functions/api/[[path]].js Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread functions/api/[[path]].js Outdated
Comment thread functions/api/[[path]].js Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread functions/api/[[path]].js
Comment thread functions/api/[[path]].js Outdated
Comment thread functions/api/[[path]].js Outdated
Comment thread .github/workflows/web-preview.yml
Copilot AI review requested due to automatic review settings July 9, 2026 11:56
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 11:57 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread functions/api/[[path]].js
Comment thread .github/workflows/web-preview.yml
Comment thread functions/api/[[path]].js Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 12:04
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 12:04 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread functions/api/[[path]].js Outdated
Comment thread functions/api/[[path]].js
Comment thread .github/workflows/web-preview.yml Outdated
Comment thread functions/api/[[path]].js Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 12:12
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 12:12 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread functions/api/[[path]].js
Comment thread functions/api/[[path]].js
Copilot AI review requested due to automatic review settings July 9, 2026 13:02
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 13:12 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread functions/api/[[path]].js
Comment thread functions/api/[[path]].js Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 13:15
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 13:20 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread functions/api/[[path]].js Outdated
Comment thread functions/api/[[path]].js
Copilot AI review requested due to automatic review settings July 9, 2026 13:21
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 13:23 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread functions/api/[[path]].js Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/web-preview.yml Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread functions/api/[[path]].js Outdated
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 13:34 — with GitHub Actions Inactive
@Just-Insane Just-Insane added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit 30e618b Jul 9, 2026
27 checks passed
@Just-Insane Just-Insane deleted the codex/pr98-web-preview-followup branch July 9, 2026 13:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread functions/api/[[path]].js
} catch {
return true;
}
if (decodedSegment.split(/[\\/]/).some((part) => part === "." || part === "..")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants