Skip to content

Commit af615b8

Browse files
authored
fix(backend): Derive origin from request URL (#6393)
1 parent 2803133 commit af615b8

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

.changeset/tidy-windows-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Fixes an issue where the Clerk SDK was improperly detecting the request's origin.

packages/backend/src/tokens/__tests__/request.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,6 @@ describe('tokens.authenticateRequest(options)', () => {
14111411
{
14121412
referer: 'https://satellite.com/signin',
14131413
'sec-fetch-dest': 'document',
1414-
origin: 'https://primary.com',
14151414
},
14161415
{
14171416
__session: mockJwt,
@@ -1441,7 +1440,6 @@ describe('tokens.authenticateRequest(options)', () => {
14411440
referer: 'https://satellite.com/signin',
14421441
'sec-fetch-dest': 'document',
14431442
'sec-fetch-site': 'cross-site',
1444-
origin: 'https://primary.com',
14451443
},
14461444
{
14471445
__session: mockJwt,
@@ -1468,9 +1466,9 @@ describe('tokens.authenticateRequest(options)', () => {
14681466
test('does not trigger handshake when referer is same origin', async () => {
14691467
const request = mockRequestWithCookies(
14701468
{
1469+
host: 'primary.com',
14711470
referer: 'https://primary.com/signin',
14721471
'sec-fetch-dest': 'document',
1473-
origin: 'https://primary.com',
14741472
},
14751473
{
14761474
__session: mockJwt,

packages/backend/src/tokens/authenticateContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class AuthenticateContext implements AuthenticateContext {
174174
* @returns {boolean} True if referrer exists and is from a different origin, false otherwise.
175175
*/
176176
public isCrossOriginReferrer(): boolean {
177-
if (!this.referrer || !this.origin) {
177+
if (!this.referrer || !this.clerkUrl.origin) {
178178
return false;
179179
}
180180

@@ -184,7 +184,7 @@ class AuthenticateContext implements AuthenticateContext {
184184
}
185185

186186
const referrerOrigin = new URL(this.referrer).origin;
187-
return referrerOrigin !== this.origin;
187+
return referrerOrigin !== this.clerkUrl.origin;
188188
} catch {
189189
// Invalid referrer URL format
190190
return false;

0 commit comments

Comments
 (0)