Repository navigation
Fix connector asset routing deploy config - #443
Conversation
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR rejects unmatched /connectors/* requests with 404 in the worker, updates docs and tests, adds wrangler config path helpers and integrates them into wrangler-env, and copies env..assets into generated wrangler configs with validation and tests. ChangesConnector Security and Wrangler Config Hardening
Sequence Diagram(s)sequenceDiagram
participant Client
participant Worker.Handler
participant Request.Router
Client->>Worker.Handler: GET /connectors/home/default
Worker.Handler->>Request.Router: inspect url.pathname
Request.Router->>Worker.Handler: pathname startsWith /connectors/
Worker.Handler->>Client: 404 Not Found
Client->>Worker.Handler: WS upgrade /connectors/home/default
Worker.Handler->>Request.Router: inspect url.pathname
Request.Router->>Worker.Handler: pathname startsWith /connectors/
Worker.Handler->>Client: 404 Not Found
sequenceDiagram
participant WranglerEnv as wrangler-env.ts
participant PathHelpers as tools/wrangler-env-config.ts
participant Environment as process.env
participant FileSystem as fs
WranglerEnv->>PathHelpers: getDefaultWranglerConfigPath()
PathHelpers->>Environment: read WRANGLER_CONFIG
alt WRANGLER_CONFIG set
Environment-->>PathHelpers: trimmed value
else
PathHelpers-->>WranglerEnv: defaultWranglerConfigPath
end
WranglerEnv->>PathHelpers: resolveWranglerConfigPath(path, cwd)
PathHelpers->>PathHelpers: return absolute or join(cwd, relative)
PathHelpers-->>WranglerEnv: resolvedPath
WranglerEnv->>FileSystem: existsSync(resolvedPath)
FileSystem-->>WranglerEnv: boolean
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
🔎 Preview deployed: https://kody-pr-443.kentcdodds.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tools/ci/resource-utils.ts`:
- Around line 318-324: The current guard treating targetAssets with typeof ===
'object' allows arrays through; update the validation around targetAssets (the
value used to set config.assets in the code that calls config.assets = {
...(targetAssets as Record<string, unknown>) }) to explicitly reject arrays by
checking Array.isArray(targetAssets) and calling fail(...) with the same
diagnostic (including baseConfigPath and envName) when targetAssets is an array
or otherwise invalid; ensure you still allow plain objects (Record<string,
unknown>) and only proceed to assign config.assets after the array check passes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b5b27e58-eb16-4e4d-acde-6c5153932e0d
📒 Files selected for processing (8)
docs/contributing/security.mdpackages/worker/src/index.tspackages/worker/src/security/public-route-hardening.workers.test.tstools/ci/resource-utils.node.test.tstools/ci/resource-utils.tstools/wrangler-env-config.node.test.tstools/wrangler-env-config.tswrangler-env.ts
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Summary
assets.run_worker_firstfor/connectors/*at the shape Cloudflare Assets documents.wrangler-env.tshonorWRANGLER_CONFIG, so the pre-deploy build step in production/preview workflows uses the same generated config as the final deploy./connectors/*paths before the static asset / SPA fallback, while keeping user-scoped connector WebSocket ingress on/connectors/u/{userId}/{kind}/{instanceId}.Investigation notes
9545255df1c6dc930e9e179471dccdab2d7657af./connectors/home/defaultis a legacy, non-user-scoped path; current code recognizes/connectors/u/{userId}/{kind}/{instanceId}.server.ping, which shows/connectors/*is reaching the Worker; the unsafe part was unmatched connector paths falling through to the SPA shell.Evidence / commands
curl -sS "https://heykody.dev/health"->{"ok":true,"commitSha":"9545255df1c6dc930e9e179471dccdab2d7657af"}curl -sS -D - -o /tmp/kody-prod-legacy-connector.html "https://heykody.dev/connectors/home/default"-> current prodHTTP/2 200,content-type: text/html; charset=UTF-8curl -sS -D - -o /tmp/kody-prod-user-scoped-connector.txt "https://heykody.dev/connectors/u/probe-user/home/default"->HTTP/2 404,content-length: 9node --input-type=module -e "const ws = new WebSocket('wss://heykody.dev/connectors/u/probe-user/home/default'); const finish = (code) => { clearTimeout(timeout); try { ws.close(); } catch {} setTimeout(() => process.exit(code), 20); }; const timeout = setTimeout(() => { console.error('timeout waiting for websocket'); finish(1); }, 5000); ws.addEventListener('open', () => console.log('open')); ws.addEventListener('message', (event) => { console.log(String(event.data)); finish(0); }); ws.addEventListener('error', (event) => { console.error('websocket error', event.message ?? event.type); finish(1); });"->open,{"type":"server.ping"}node tools/ci/production-resources.ts ensure --dry-run --out-config packages/worker/wrangler-production.generated.json && CLOUDFLARE_ENV=production WRANGLER_CONFIG=/workspace/packages/worker/wrangler-production.generated.json node --env-file=packages/worker/.env ./wrangler-env.ts deploy --dry-run --outdir /tmp/kody-wrangler-dry-run-after --var APP_COMMIT_SHA:dry-run->env.ASSETSbinding present, production D1/KV dry-run IDs loaded,--dry-run: exiting now.node tools/ci/preview-resources.ts ensure --dry-run --worker-name kody-pr-dry-run --out-config packages/worker/wrangler-preview.generated.json && CLOUDFLARE_ENV=preview WRANGLER_CONFIG=/workspace/packages/worker/wrangler-preview.generated.json node --env-file=packages/worker/.env ./wrangler-env.ts deploy --dry-run --name kody-pr-dry-run --outdir /tmp/kody-wrangler-preview-dry-run-after --var APP_COMMIT_SHA:dry-run->env.ASSETSbinding present, preview D1/KV dry-run IDs loaded,--dry-run: exiting now.npx vitest run --project node-unit tools/ci/resource-utils.node.test.ts tools/wrangler-env-config.node.test.ts-> 2 files / 7 tests passednpx vitest run --project workers-unit packages/worker/src/security/public-route-hardening.workers.test.ts-> 1 file / 4 tests passednpm run format:check-> passednpm run lint-> passed with 4 existing warnings in unrelated filesnpm run typecheck-> passedSummary by CodeRabbit
Security
Documentation
Tests
Chores