feat(deploy): Phase 4 — CORS allowlist + prompt-length cap on canonical demo proxy#324
Merged
Merged
Conversation
Tightens CORS from wildcard to single-origin allowlist (demo.cacheplane.ai) and caps request body at 8 KB. Both gates fire before the rate-limit + upstream fetch so they're cost-free. Configurable via env vars (ALLOWED_ORIGINS, MAX_PROMPT_BYTES) on the demo wrapper. Examples wrapper unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends ProxyConfig with optional allowedOrigins and maxBodyBytes fields (the latter wired in the next commit). When allowedOrigins is configured, the handler echoes a matching Origin (with vary: origin) or returns 403 for a mismatch. Requests without an Origin header (server-to-server) are passed through with no CORS headers set — CORS only matters in browser context. When allowedOrigins is undefined (cockpit-examples), the handler keeps the legacy access-control-allow-origin: * behavior. No change for examples. 5 new unit tests cover: matching origin echoed, mismatch returns 403, missing Origin allowed without CORS headers, OPTIONS preflight echoes, and the wildcard-preserved-when-unset legacy path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds an optional maxBodyBytes check between the _proxy_debug
endpoint and the rate-limit gate. Checks Content-Length first
(short-circuit); falls back to JSON.stringify(req.body).length.
Returns 413 with { error: 'payload_too_large', maxBytes,
actualBytes } when over the cap.
Skipped entirely when maxBodyBytes is undefined (cockpit-examples).
3 new unit tests cover the JSON.stringify path, Content-Length
short-circuit, and the legacy-unset path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reads two new env vars at module load and passes them to createProxyHandler: - ALLOWED_ORIGINS (comma-separated; default: https://demo.cacheplane.ai) - MAX_PROMPT_BYTES (integer; default: 8192) The cockpit-examples wrapper does not pass these fields, so its behavior stays exactly as today (* CORS, no body cap). Also adds --external:@neondatabase/serverless to the assemble-demo esbuild command so the Vercel function bundles correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Phase 4 of the canonical-demo deployment plan. Two new defensive gates on the demo proxy, both firing BEFORE rate-limit and upstream fetch (cost-free):
Both gates skip entirely when their config field is undefined → `scripts/examples-middleware.ts` (cockpit-examples) is unaffected.
External setup
Already done:
Spec & Plan
Test plan
Notes on reviewer comments
The code-quality reviewer flagged a missing `--external:@neondatabase/serverless` in `scripts/assemble-demo.ts`. That's intentional. Vercel Build Output API functions get only the bundled `index.js` — no `node_modules` at runtime. `--external` would cause runtime `Cannot find module '@neondatabase/serverless'`. Phase 3 already verified the inlined-driver approach works.
🤖 Generated with Claude Code