From 420adb8c2f961ff1e2447e40d4f87b1adc7efd37 Mon Sep 17 00:00:00 2001 From: rishabhx29 Date: Sat, 21 Nov 2026 07:15:35 +0530 Subject: [PATCH 1/3] fix(server): issue URLs on an unconfigured port no longer resolve to another server --- apps/server/src/issue/IssueService.test.ts | 16 ++++++++++++++++ apps/server/src/issue/IssueService.ts | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 1251729b5bbac..51c0ba0439e81 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -274,6 +274,22 @@ describe("IssueService", () => { host: "gitea.test", }); + // A port-bearing link names a distinct server; a default-port-only binding must not serve it. + const defaultPortOnly = yield* makeService({ + projects: [ + project({ id: "plain", repository: "acme/web", provider: "forgejo", host: "gitea.test" }), + ], + trackers: [fakeTracker({ kind: IssueTrackerKind.make("forgejo") })], + }); + expect( + yield* defaultPortOnly + .resolveUrl("https://gitea.test:8443/acme/web/issues/3") + .pipe(Effect.result), + ).toMatchObject({ + _tag: "Failure", + failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, + }); + // A GitHub Enterprise Server's hostname need not say "github"; its project vouches for it. const enterprise = yield* makeService({ projects: [project({ id: "ghes", repository: "acme/web", host: "code.acme.test" })], diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 56712954a49cb..4be8924d66d97 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -716,11 +716,16 @@ const make = Effect.gen(function* () { } const { tracker, link } = parsed; // A link names its server's port; a binding does only when its remote or web URL did. - const authority = new URL(url).host.toLowerCase(); + const parsedUrl = new URL(url); + const authority = parsedUrl.host.toLowerCase(); const { supported } = yield* listProjects({ host: link.host, authority }); const onHost = supported.filter((project) => project.tracker === tracker); const onAuthority = onHost.filter((project) => project.host === authority); - const onTracker = onAuthority.length > 0 ? onAuthority : onHost; + // A port-bearing link names a server of its own. Without a binding for that authority it + // names a server nobody configured, so it must not fall back to a default-port server on + // the same host. A port-less link may still be served by whichever binding has the host. + let onTracker = onAuthority; + if (onTracker.length === 0 && parsedUrl.port === "") onTracker = onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; const scope = link.scope.toLowerCase(); From 48fa3988bcf83441c8fe0a5cb6e04fdefc640ba2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 03:19:32 +0000 Subject: [PATCH 2/3] refactor(server): tighten unconfigured-port issue URL check Co-Authored-By: Claude Opus 5.5 --- apps/server/src/issue/IssueService.test.ts | 12 +----------- apps/server/src/issue/IssueService.ts | 7 ++----- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 51c0ba0439e81..7329ac7b768ec 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -273,18 +273,8 @@ describe("IssueService", () => { projectId: "plain", host: "gitea.test", }); - - // A port-bearing link names a distinct server; a default-port-only binding must not serve it. - const defaultPortOnly = yield* makeService({ - projects: [ - project({ id: "plain", repository: "acme/web", provider: "forgejo", host: "gitea.test" }), - ], - trackers: [fakeTracker({ kind: IssueTrackerKind.make("forgejo") })], - }); expect( - yield* defaultPortOnly - .resolveUrl("https://gitea.test:8443/acme/web/issues/3") - .pipe(Effect.result), + yield* ported.resolveUrl("https://gitea.test:9443/acme/web/issues/3").pipe(Effect.result), ).toMatchObject({ _tag: "Failure", failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 4be8924d66d97..9df52eae32d4e 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -721,11 +721,8 @@ const make = Effect.gen(function* () { const { supported } = yield* listProjects({ host: link.host, authority }); const onHost = supported.filter((project) => project.tracker === tracker); const onAuthority = onHost.filter((project) => project.host === authority); - // A port-bearing link names a server of its own. Without a binding for that authority it - // names a server nobody configured, so it must not fall back to a default-port server on - // the same host. A port-less link may still be served by whichever binding has the host. - let onTracker = onAuthority; - if (onTracker.length === 0 && parsedUrl.port === "") onTracker = onHost; + // An explicit port names its own server; only a port-less link may borrow another binding's. + const onTracker = onAuthority.length > 0 || parsedUrl.port !== "" ? onAuthority : onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; const scope = link.scope.toLowerCase(); From 35a59673d32e006c8fbdd4e8159f5207f3d2f95c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 04:44:23 +0000 Subject: [PATCH 3/3] fix(server): keep the hostname fallback for trackers whose bindings drop ports Co-Authored-By: Claude Opus 5.5 --- apps/server/src/issue/IssueService.test.ts | 10 ++++++++++ apps/server/src/issue/IssueService.ts | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 7329ac7b768ec..ed7d6a97921dd 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -279,6 +279,16 @@ describe("IssueService", () => { _tag: "Failure", failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" }, }); + // GitLab bindings drop the remote's port, so a ported link still finds its hostname's project. + const gitlab = yield* makeService({ + projects: [ + project({ id: "gl", repository: "acme/web", provider: "gitlab", host: "gitlab.corp" }), + ], + trackers: [fakeTracker({ kind: IssueTrackerKind.make("gitlab") })], + }); + expect( + yield* gitlab.resolveUrl("https://gitlab.corp:8443/acme/web/-/issues/3"), + ).toMatchObject({ projectId: "gl", host: "gitlab.corp", key: "3", writable: true }); // A GitHub Enterprise Server's hostname need not say "github"; its project vouches for it. const enterprise = yield* makeService({ diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 9df52eae32d4e..0108961713010 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -721,8 +721,10 @@ const make = Effect.gen(function* () { const { supported } = yield* listProjects({ host: link.host, authority }); const onHost = supported.filter((project) => project.tracker === tracker); const onAuthority = onHost.filter((project) => project.host === authority); - // An explicit port names its own server; only a port-less link may borrow another binding's. - const onTracker = onAuthority.length > 0 || parsedUrl.port !== "" ? onAuthority : onHost; + // Only a host with its own `changeRequestHost` keeps ports, so only its ported links are exact. + const portIsExact = + parsedUrl.port !== "" && gitHost?.definition.changeRequestHost !== undefined; + const onTracker = onAuthority.length > 0 || portIsExact ? onAuthority : onHost; const preferFirst = (projects: ReadonlyArray) => projects.find((project) => project.project.id === preferredProjectId) ?? projects[0]; const scope = link.scope.toLowerCase();