fix: allow trust portal subdomains and custom domains through CORS#2354
fix: allow trust portal subdomains and custom domains through CORS#2354
Conversation
Trust portals are served on dynamic subdomains (e.g. security.trycomp.ai, acme.trust.inc) and verified custom domains (e.g. trust.acmecorp.com), but the CORS config only had a static allowlist. This caused browsers to block requests from trust portals to api.trycomp.ai. - Add isStaticTrustedOrigin() for sync checks (*.trycomp.ai, *.trust.inc) - Add async isTrustedOrigin() that also checks verified custom domains from the DB via Upstash Redis cache (5-min TTL) - Update CORS origin callback, origin-check middleware, and cors-exception filter to use the new functions - Update tests to cover subdomain matching and async behavior Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Adds Written by Cursor Bugbot for commit 63b4bd8. This will update automatically on new commits. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| const corsRedisClient = new Redis({ | ||
| url: process.env.UPSTASH_REDIS_REST_URL!, | ||
| token: process.env.UPSTASH_REDIS_REST_TOKEN!, | ||
| }); |
There was a problem hiding this comment.
Redis client missing env var guard breaks dev environments
Medium Severity
The corsRedisClient is unconditionally created with process.env.UPSTASH_REDIS_REST_URL! and process.env.UPSTASH_REDIS_REST_TOKEN! at module load time, without checking if the env vars exist. Every other Redis client in the codebase (admin-rate-limit.middleware.ts, upstash-redis.client.ts, device-agent-kv.ts) guards with a hasUpstashConfig check and provides a fallback (either null or InMemoryRedis). In local development or test environments without Upstash configured, this will either crash at module load time (older library versions) or cause every custom-domain CORS check to fail with noisy error logs.
| ]; | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Unused export getTrustedOrigins after refactor to new functions
Low Severity
getTrustedOrigins is still exported but is no longer imported anywhere outside auth.server.ts. The only external consumers (main.ts, origin-check.middleware.ts) were updated to use isTrustedOrigin or isStaticTrustedOrigin. The function is now only used internally by isStaticTrustedOrigin and the betterAuth config within the same file, so the export keyword is unnecessary.
|
🎉 This PR is included in version 3.10.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |


Trust portals are served on dynamic subdomains (e.g. security.trycomp.ai, acme.trust.inc) and verified custom domains (e.g. trust.acmecorp.com), but the CORS config only had a static allowlist. This caused browsers to block requests from trust portals to api.trycomp.ai.
What does this PR do?
Visual Demo (For contributors especially)
A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).
Video Demo (if applicable):
Image Demo (if applicable):
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist