fix(web): allow relay WSS origin in CSP for canary/prod#4577
Conversation
RELAY_URL wasn't plumbed into the deploy-web build env, so `process.env.RELAY_URL` was undefined at build time and the relay origin never made it into `connect-src`. Browsers then blocked `wss://relay.superset.sh`, breaking remote-control terminals. Plumb RELAY_URL into deploy-web in both deploy-preview and deploy-production, and add a `wss://relay.superset.sh` fallback in next.config.ts so the header stays correct if the env is ever missing again.
|
Capy auto-review is paused for this organization because the monthly auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds environment variable support for configurable relay WebSocket origins. GitHub Actions workflows now pass ChangesRelay URL Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryFixes broken remote-control WebSocket connections in canary/prod by plumbing
Confidence Score: 5/5Safe to merge — a minimal, targeted fix that adds a missing build-time secret and a self-documenting fallback with no side effects on other headers or routes. The change is small and well-scoped: two one-line workflow additions and a three-line ternary in No files require special attention. The only file with non-trivial logic is
|
| Filename | Overview |
|---|---|
| .github/workflows/deploy-preview.yml | Adds RELAY_URL secret as a build-time env var for the deploy-web Vercel step so next.config.ts can include the relay WSS origin in the CSP header. |
| .github/workflows/deploy-production.yml | Same RELAY_URL secret addition as deploy-preview.yml, applied to the production Vercel build step. |
| apps/web/next.config.ts | Adds a hard-coded wss://relay.superset.sh production fallback for relayWsOrigin so the CSP connect-src stays correct even if RELAY_URL is missing from the build environment. |
Sequence Diagram
sequenceDiagram
participant GHA as GitHub Actions
participant Vercel as Vercel Build
participant Config as next.config.ts
participant CSP as HTTP Header (CSP)
participant Browser as Browser
GHA->>Vercel: vercel build (env: RELAY_URL from secret)
Vercel->>Config: process.env.RELAY_URL available
alt RELAY_URL is set
Config->>CSP: "relayWsOrigin = new URL(RELAY_URL).origin replaced to wss://relay.superset.sh"
else RELAY_URL is empty and isProduction
Config->>CSP: "relayWsOrigin = wss://relay.superset.sh (hard-coded fallback)"
else dev non-production
Config->>CSP: "relayWsOrigin = null, ws:/wss: blanket rules cover it"
end
CSP-->>Browser: connect-src includes wss://relay.superset.sh
Browser->>Browser: WSS connection to relay allowed, no CSP violation
Reviews (1): Last reviewed commit: "fix(web): allow relay WSS origin in CSP ..." | Re-trigger Greptile
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
connect-srcdirective didn't include the relay WSS origin. Root cause:RELAY_URLwasn't plumbed into thedeploy-webbuild env, soprocess.env.RELAY_URLwas undefined whennext.config.tscomputed the CSP, and the browser blockedwss://relay.superset.sh.RELAY_URLto thedeploy-webenv in bothdeploy-preview.ymlanddeploy-production.yml.wss://relay.superset.shproduction fallback inapps/web/next.config.tsso the header stays correct even if the env isn't plumbed in the future.Test plan
Content-Security-Policyheader on the web app —connect-srcshould includewss://relay.superset.sh.Summary by cubic
Fixes CSP to allow the relay WebSocket origin in canary and production, restoring remote-control terminals. Adds env wiring and a safe production fallback so the header stays correct.
RELAY_URLintodeploy-webfor preview and production builds in.github/workflows/deploy-preview.ymland.github/workflows/deploy-production.yml.apps/web/next.config.ts, setrelayWsOriginwith a production fallback towss://relay.superset.shsoconnect-srcalways allows the relay.Written for commit f390b17. Summary will update on new commits.
Summary by CodeRabbit