Repository navigation
Conversation
With CORS_ORIGIN set to anything but *, a request with no Origin header was refused with 'Not allowed by CORS' (HTTP 500). Servers, bots and health checks send no Origin, so restricting CORS broke every server call and kept a new deployment from ever passing its health check. CORS only governs browsers, which always send Origin on cross-site requests.
Reviewer's GuideUses of the APIImport the helper and use it in the CORS callback to decide whether to allow each request.
ImplementationAdd a helper that allows requests without an Origin header while preserving the configured-origin and wildcard checks.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Sourcery assessment
Needs a human reviewer. 1 finding to address first, and requests without an Origin header now pass the CORS check and reach handlers that were previously rejected, including potentially state-changing endpoints. Reverting stops future requests but cannot undo any actions already processed; this is a blanket access-policy decision with no built-in signal if it is too permissive.
Blocking findings: src/utils/corsOrigin.ts:6
| * server, a bot or a health check, never from a cross-site page, so it is always allowed. | ||
| */ | ||
| export const isCorsOriginAllowed = (allowed: string[], requestOrigin: string | undefined): boolean => { | ||
| if (!requestOrigin) return true; |
There was a problem hiding this comment.
🟡 Medium · Cross-site requests alter license state
When a cross-site browser request omits Origin on /license/activate or /license/register, isCorsOriginAllowed returns true, so the CORS middleware passes the request to the unauthenticated licensing routes. /license/register lets initRegistration replace pending registration state using an attacker-chosen redirect_uri; /license/activate lets completeActivation save a supplied code’s API key and activate the instance, replacing pending license state when the instance is inactive and the code is valid.
Do not treat a missing Origin as trusted for these licensing routes; reject it or require an explicitly allowed origin.
| * Whether a CORS request may proceed. CORS governs browsers only: a request without an Origin header comes from a | ||
| * server, a bot or a health check, never from a cross-site page, so it is always allowed. | ||
| */ | ||
| export const isCorsOriginAllowed = (allowed: string[], requestOrigin: string | undefined): boolean => { |
There was a problem hiding this comment.
⚪ Low · Utility misses required export
isCorsOriginAllowed is exported only by name and has no default export, so the new utility does not follow the repository’s required utility pattern. The file also omits that pattern’s prescribed logger and failure handling.
Add the required default export and follow the utility pattern’s logger and failure-handling requirements.
From .cursor/rules/specialized-rules/util-rules.mdc L12-29:
### Standard Utility Pattern
```typescript
import { Logger } from '@config/logger.config';
const logger = new Logger('UtilityName');
export function utilityFunction(param: ParamType): ReturnType {
try {
// Utility logic
return result;
} catch (error) {
logger.error(`Utility function failed: ${error.message}`);
throw error;
}
}…
📋 Description
When
CORS_ORIGINis set to anything other than*, every request without anOriginheader is refused withNot allowed by CORS(HTTP 500), becauseORIGIN.indexOf(undefined)is-1.Requests without
Originare never cross-site browser requests: they come from servers, bots, webhooks,curland health checks. So restricting CORS today breaks every server-to-server API call and the container health check (a deployment behind a health-checked orchestrator never becomes healthy).This change allows requests that carry no
Originheader and keeps the existing rules for browser requests. The check moves into a small helper,src/utils/corsOrigin.ts.🔗 Related Issue
None found.
🧪 Type of Change
🧪 Testing
CORS_ORIGIN=<own origin>, before the changeGET /without Origin returned 500; after it, 200. A foreignOriginis still refused with noAccess-Control-Allow-Originheader; the configured origin gets the header.CORS_ORIGIN=*behaviour is unchanged.npx eslint src/main.ts src/utils/corsOrigin.tspasses ondevelop.✅ Checklist
Summary by Sourcery
Bug Fixes: