Skip to content

Commit cfba259

Browse files
lucianholtclaude
andcommitted
fix(gitlab): claim uploads on self-hosted GitLab under any hostname
A self-hosted instance such as code.<company>.com has no `gitlab` label, so its uploads were never routed through the server and showed as unavailable. The fetcher only sends a token to a host `glab auth status` lists, so the hostname check added no safety and is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 35d121e commit cfba259

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎packages/source-control-gitlab/src/shared/definition.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ describe("GitLab uploads", () => {
143143
).toBe(`https://gitlab.example.com/api/v4/projects/42/uploads/${SECRET}/shot.png`);
144144
});
145145

146-
it("claims no other host, route, or plain-HTTP link", () => {
146+
it("claims uploads on a self-hosted GitLab whose hostname does not say gitlab", () => {
147+
expect(media(`https://code.acme.com/team/app/uploads/${SECRET}/shot.png`)?.fetchUrl).toBe(
148+
`https://code.acme.com/api/v4/projects/team%2Fapp/uploads/${SECRET}/shot.png`,
149+
);
150+
});
151+
152+
it("claims no other route or plain-HTTP link", () => {
147153
for (const url of [
148-
`https://example.com/group/project/uploads/${SECRET}/shot.png`,
149154
`http://gitlab.com/group/project/uploads/${SECRET}/shot.png`,
150155
`https://gitlab.com/group/project/-/blob/main/uploads/${SECRET}/shot.png`,
151156
`https://gitlab.com/project/uploads/${SECRET}/shot.png`,

‎packages/source-control-gitlab/src/shared/definition.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
projectChangeRequestHost,
1111
remoteWebOrigin,
1212
} from "@t3tools/source-control-core/shared/definition";
13-
import { gitLabMediaUrl, isGitLabHostname } from "./gitLabMedia.ts";
13+
import { gitLabMediaUrl } from "./gitLabMedia.ts";
1414
import { icon } from "./icon.ts";
1515
import { gitLabReferenceAutolinks } from "./referenceAutolinks.ts";
1616

@@ -75,7 +75,7 @@ export const definition = defineSourceControl({
7575
checkoutChangeRequestHost: () => null,
7676
changeRequestHeadRef: (number) => `refs/merge-requests/${number}/head`,
7777
recognizeRemote: ({ host, hostname }) =>
78-
isGitLabHostname(hostname)
78+
hostname === "gitlab.com" || hostname.split(".").includes("gitlab")
7979
? {
8080
kind: KIND,
8181
name: hostname === "gitlab.com" ? "GitLab" : "GitLab Self-Hosted",

‎packages/source-control-gitlab/src/shared/gitLabMedia.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ function upload(origin: string, project: string, secret: string, file: string) {
4141
} satisfies SourceControlMediaUrl;
4242
}
4343

44-
/** The hosts `recognizeRemote` reads as GitLab, the only ones a GitLab account can be signed in to. */
45-
export function isGitLabHostname(hostname: string): boolean {
46-
return hostname === "gitlab.com" || hostname.split(".").includes("gitlab");
47-
}
48-
44+
/**
45+
* Any host may run GitLab, so the path alone claims an upload. The server fetches it only from a
46+
* host `glab` is logged in to, and that check is what keeps a token on hosts the user trusts.
47+
*/
4948
export function gitLabMediaUrl(url: URL): SourceControlMediaUrl | null {
5049
// A token is only ever sent over TLS.
51-
if (url.protocol !== "https:" || !isGitLabHostname(url.hostname.toLowerCase())) return null;
50+
if (url.protocol !== "https:") return null;
5251
const api = API_UPLOAD.exec(url.pathname);
5352
if (api) return upload(url.origin, api[1]!, api[2]!, api[3]!);
5453
const byId = PROJECT_ID_UPLOAD.exec(url.pathname);

0 commit comments

Comments
 (0)