Skip to content

fix(cors): allow requests without an Origin header - #2821

Open
Oumnya wants to merge 1 commit into
evolution-foundation:developfrom
thecloudstation:fix/cors-allow-requests-without-origin
Open

Oumnya wants to merge 1 commit into
evolution-foundation:developfrom
thecloudstation:fix/cors-allow-requests-without-origin

Conversation

@Oumnya

@Oumnya Oumnya commented Dec 5, 2026 •

Copy link
Copy Markdown

📋 Description

When CORS_ORIGIN is set to anything other than *, every request without an Origin header is refused with Not allowed by CORS (HTTP 500), because ORIGIN.indexOf(undefined) is -1.

Requests without Origin are never cross-site browser requests: they come from servers, bots, webhooks, curl and 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 Origin header 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

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🔒 Security fix (lets operators restrict CORS without breaking server access)

🧪 Testing

  • Manual testing completed: on 2.3.8 with CORS_ORIGIN=<own origin>, before the change GET / without Origin returned 500; after it, 200. A foreign Origin is still refused with no Access-Control-Allow-Origin header; the configured origin gets the header.
  • Functionality verified in a production deployment behind a health-checked load balancer.
  • No breaking changes introduced: with CORS_ORIGIN=* behaviour is unchanged.
  • npx eslint src/main.ts src/utils/corsOrigin.ts passes on develop.

✅ Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

Summary by Sourcery

Bug Fixes:

  • Allow requests without an Origin header when CORS origins are restricted, while continuing to enforce the configured allowlist for requests with an Origin.

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.
@sourcery-ai

sourcery-ai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Uses of the API

Import the helper and use it in the CORS callback to decide whether to allow each request.

  • src/main.ts L25, L66

Implementation

Add a helper that allows requests without an Origin header while preserving the configured-origin and wildcard checks.

  • src/utils/corsOrigin.ts L1-9

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/utils/corsOrigin.ts
* 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread src/utils/corsOrigin.ts
* 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 => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ 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;
  }
}…

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant