feat: Add wildcard trusted origins for cannaiq.co and cannabrands.app
Add *.cannaiq.co and *.cannabrands.app patterns to both: - auth/middleware.ts (admin routes) - public-api.ts (consumer /api/v1/* routes) This allows any subdomain of these domains to access the API without requiring an API key. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,7 @@ const TRUSTED_ORIGINS = [
|
|||||||
// Pattern-based trusted origins (wildcards)
|
// Pattern-based trusted origins (wildcards)
|
||||||
const TRUSTED_ORIGIN_PATTERNS = [
|
const TRUSTED_ORIGIN_PATTERNS = [
|
||||||
/^https:\/\/.*\.cannabrands\.app$/, // *.cannabrands.app
|
/^https:\/\/.*\.cannabrands\.app$/, // *.cannabrands.app
|
||||||
|
/^https:\/\/.*\.cannaiq\.co$/, // *.cannaiq.co
|
||||||
];
|
];
|
||||||
|
|
||||||
// Trusted IPs for internal pod-to-pod communication
|
// Trusted IPs for internal pod-to-pod communication
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ const CONSUMER_TRUSTED_ORIGINS = [
|
|||||||
'http://localhost:3002',
|
'http://localhost:3002',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Wildcard trusted origin patterns (*.domain.com)
|
||||||
|
const CONSUMER_TRUSTED_PATTERNS = [
|
||||||
|
/^https:\/\/([a-z0-9-]+\.)?cannaiq\.co$/,
|
||||||
|
/^https:\/\/([a-z0-9-]+\.)?cannabrands\.app$/,
|
||||||
|
];
|
||||||
|
|
||||||
// Trusted IPs for local development (bypass API key auth)
|
// Trusted IPs for local development (bypass API key auth)
|
||||||
const TRUSTED_IPS = ['127.0.0.1', '::1', '::ffff:127.0.0.1'];
|
const TRUSTED_IPS = ['127.0.0.1', '::1', '::ffff:127.0.0.1'];
|
||||||
|
|
||||||
@@ -150,8 +156,17 @@ function isConsumerTrustedRequest(req: Request): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const origin = req.headers.origin;
|
const origin = req.headers.origin;
|
||||||
if (origin && CONSUMER_TRUSTED_ORIGINS.includes(origin)) {
|
if (origin) {
|
||||||
return true;
|
// Check exact matches
|
||||||
|
if (CONSUMER_TRUSTED_ORIGINS.includes(origin)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Check wildcard patterns
|
||||||
|
for (const pattern of CONSUMER_TRUSTED_PATTERNS) {
|
||||||
|
if (pattern.test(origin)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const referer = req.headers.referer;
|
const referer = req.headers.referer;
|
||||||
if (referer) {
|
if (referer) {
|
||||||
@@ -160,6 +175,18 @@ function isConsumerTrustedRequest(req: Request): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check wildcard patterns against referer origin
|
||||||
|
try {
|
||||||
|
const refererUrl = new URL(referer);
|
||||||
|
const refererOrigin = refererUrl.origin;
|
||||||
|
for (const pattern of CONSUMER_TRUSTED_PATTERNS) {
|
||||||
|
if (pattern.test(refererOrigin)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Invalid referer URL, ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user