Skip to content

Commit d3ca61a

Browse files
fix: remove exact equality checks for matcher for /me and /my-org
1 parent 53871e1 commit d3ca61a

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/server/auth-client.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,9 @@ export class AuthClient {
417417
this.enableConnectAccountEndpoint
418418
) {
419419
return this.handleConnectAccount(req);
420-
} else if (
421-
sanitizedPathname === "/me" ||
422-
sanitizedPathname.startsWith("/me/")
423-
) {
420+
} else if (sanitizedPathname.startsWith("/me/")) {
424421
return this.handleMyAccount(req);
425-
} else if (
426-
sanitizedPathname === "/my-org" ||
427-
sanitizedPathname.startsWith("/my-org/")
428-
) {
422+
} else if (sanitizedPathname.startsWith("/my-org/")) {
429423
return this.handleMyOrg(req);
430424
} else {
431425
// no auth handler found, simply touch the sessions

src/server/proxy-handler.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,13 @@ describe("Authentication Client - Custom Proxy Handler", async () => {
489489

490490
// combine single level and multi level subpaths
491491
describe("Category 3: URL Path Matching & Transformation", () => {
492-
it("3.1 should proxy to root path", async () => {
492+
it("3.1 should reject exact proxy path without subpath (security)", async () => {
493+
// Security: The My Account and My Org APIs have no endpoints at exactly /me or /my-org
494+
// All real endpoints are like /me/v1/... or /my-org/v1/...
495+
// Accepting exact paths could lead to security issues
493496
const session = createInitialSessionData();
494497
const cookie = await createSessionCookie(session, secret);
495498

496-
server.use(
497-
http.get(`${DEFAULT.upstreamBaseUrl}`, () => {
498-
return HttpResponse.json({ path: "/" });
499-
})
500-
);
501-
502499
const request = new NextRequest(
503500
new URL(DEFAULT.proxyPath, DEFAULT.appBaseUrl),
504501
{
@@ -508,10 +505,11 @@ describe("Authentication Client - Custom Proxy Handler", async () => {
508505
);
509506

510507
const response = await authClient.handler(request);
508+
// Should not proxy - should just touch sessions and return Next response
511509
expect(response.status).toBe(200);
512-
513-
const data = await response.json();
514-
expect(data.path).toBe("/");
510+
// Should not have proxied content
511+
const text = await response.text();
512+
expect(text).not.toContain('{"path":"/"}');
515513
});
516514

517515
it("3.2 should proxy to single-level subpath", async () => {

0 commit comments

Comments
 (0)