Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): Sanitize slashes in URL paths #3982

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-goats-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/backend": patch
---

Fix error from duplicate leading slashes in URL path on Cloudflare Pages
8 changes: 8 additions & 0 deletions packages/backend/src/tokens/__tests__/clerkRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ export default (QUnit: QUnit) => {
});
assert.equal(createClerkRequest(req).clerkUrl.toString(), 'https://example.com/path?foo=bar');
});

it('with duplicate leading slashes in URL path', assert => {
const req1 = new Request('http://localhost:3000//path');
assert.equal(createClerkRequest(req1).clerkUrl.toString(), 'http://localhost:3000//path');

const req2 = new Request('http://localhost:3000////path');
assert.equal(createClerkRequest(req2).clerkUrl.toString(), 'http://localhost:3000////path');
});
});

module('toJSON', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/tokens/clerkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ClerkRequest extends Request {
const resolvedProtocol = this.getFirstValueFromHeader(forwardedProto) ?? protocol?.replace(/[:/]/, '');
const origin = resolvedHost && resolvedProtocol ? `${resolvedProtocol}://${resolvedHost}` : initialUrl.origin;

if (origin === initialUrl.origin) {
return createClerkUrl(initialUrl);
}
return createClerkUrl(initialUrl.pathname + initialUrl.search, origin);
}

Expand Down
Loading