Skip to content

feat(): enable CORS server-side for passwordless POST requests#20311

Merged
toufali merged 1 commit intomainfrom
passwordless-cors-server-side
Apr 2, 2026
Merged

feat(): enable CORS server-side for passwordless POST requests#20311
toufali merged 1 commit intomainfrom
passwordless-cors-server-side

Conversation

@toufali
Copy link
Copy Markdown
Member

@toufali toufali commented Apr 2, 2026

Because

  • We want to enable non-interactive challenges on the new passwordless endpoints

This pull request

  • replicates patterns from account/create and request_otp to enable CORS when set to specific allowed origins (not wildcard *)

Issue that this pull request solves

Closes: FXA-13329

Other information (Optional)

We "flipped the switch" for CORS client side here: #20293 but neglected to follow suit server-side, as the pattern shows here for account/create endpoint, for example: #20003

@toufali toufali requested a review from a team as a code owner April 2, 2026 19:45
Copilot AI review requested due to automatic review settings April 2, 2026 19:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the FxA auth-server passwordless routes to allow cross-origin POST requests to include credentials (cookies/auth headers) when CORS is configured with explicit allowlisted origins.

Changes:

  • Conditionally enables cors.credentials = true for passwordless POST routes when config.corsOrigin is not wildcard.
  • Applies the CORS credentials option to /send_code, /confirm_code, and /resend_code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

);

// Enable CORS credentials only when using explicit origins (not wildcard, per CORS spec)
const enableCredentials = config.corsOrigin && config.corsOrigin[0] !== '*';
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

enableCredentials is documented as disabling credentials when using a wildcard origin, but the implementation only checks corsOrigin[0] !== '*'. If corsOrigin ever contains '*' in a non-first position (e.g., via env parsing/ordering), credentials could be enabled while still effectively allowing wildcard origins, which violates the CORS credential rules. Consider computing this as “has at least one origin and does not include '*' anywhere” (and optionally guarding against an empty array).

Suggested change
const enableCredentials = config.corsOrigin && config.corsOrigin[0] !== '*';
const enableCredentials =
config.corsOrigin &&
config.corsOrigin.length > 0 &&
!config.corsOrigin.includes('*');

Copilot uses AI. Check for mistakes.
Comment on lines 562 to +567
...PASSWORDLESS_DOCS.PASSWORDLESS_SEND_CODE_POST,
...(enableCredentials && {
cors: {
credentials: true,
},
}),
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The new conditional cors: { credentials: true } behavior isn’t covered by tests. Since this changes cross-origin behavior for these endpoints, please add/update unit tests (e.g., in lib/routes/passwordless.spec.ts) to assert that route.options.cors.credentials is enabled when config.corsOrigin is an explicit allowlist and not enabled when it is ['*'].

Copilot uses AI. Check for mistakes.
@toufali toufali changed the title feat(): enable passwordless POST CORS requests feat(): enable CORS server-side for passwordless POST requests Apr 2, 2026
@toufali toufali merged commit e3b44e9 into main Apr 2, 2026
25 checks passed
@toufali toufali deleted the passwordless-cors-server-side branch April 2, 2026 20:14
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.

3 participants