⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(api): show gitlab token hint only to settings managers
zaralX413522070173
diff --git a/apps/api/src/gitlab-integration/controllers/get-gitlab-integration.ts b/apps/api/src/gitlab-integration/controllers/get-gitlab-integration.tsindex ab20c82c4..80b294413 100644--- a/apps/api/src/gitlab-integration/controllers/get-gitlab-integration.ts+++ b/apps/api/src/gitlab-integration/controllers/get-gitlab-integration.ts@@ -15,10 +15,7 @@ function maskToken(token: string): string {return `${token.slice(0, 4)}••••••${token.slice(-4)}`;}-async function getGitlabIntegration(- projectId: string,- includeWebhookSecret = false,-) {+async function getGitlabIntegration(projectId: string, includeSecrets = false) {const integration = await db.query.integrationTable.findFirst({where: and(eq(integrationTable.projectId, projectId),@@ -42,9 +39,9 @@ async function getGitlabIntegration(baseUrl: config.baseUrl,projectPath: config.projectPath,tokenType: tokenTypeOf(config),- maskedAccessToken: maskToken(config.accessToken),+ maskedAccessToken: includeSecrets ? maskToken(config.accessToken) : "",webhookUrl: `${apiBase.replace(/\/$/, "")}/gitlab-integration/webhook/${integration.id}`,- webhookSecret: includeWebhookSecret ? (config.webhookSecret ?? "") : "",+ webhookSecret: includeSecrets ? (config.webhookSecret ?? "") : "",branchPattern: config.branchPattern || defaultGitlabConfig.branchPattern,commentTaskLinkOnGitlabIssue: config.commentTaskLinkOnGitlabIssue !== false,isActive: integration.isActive,diff --git a/apps/api/src/gitlab-integration/index.ts b/apps/api/src/gitlab-integration/index.tsindex c3bef795d..e58449076 100644--- a/apps/api/src/gitlab-integration/index.ts+++ b/apps/api/src/gitlab-integration/index.ts@@ -108,7 +108,7 @@ const getIntegrationRoute = createRoute({tags: ["GitLab"],summary: "Get GitLab integration",description:- "Get the GitLab integration for a project, or null when none is configured. The webhook secret is included only for callers with workspace:manage_settings.",+ "Get the GitLab integration for a project, or null when none is configured. The masked access token and the webhook secret are included only for callers with workspace:manage_settings.",middleware: [workspaceAccess.fromProject("projectId")] as const,request: { params: projectIdParam },responses: {@@ -246,13 +246,10 @@ const gitlabIntegration = apiRouter<BaseVariables & { workspaceId: string }>()}).openapi(getIntegrationRoute, async (c) => {const { projectId } = c.req.valid("param");- const includeWebhookSecret = await hasWorkspacePermission(c, {+ const includeSecrets = await hasWorkspacePermission(c, {workspace: ["manage_settings"],});- const integration = await getGitlabIntegration(- projectId,- includeWebhookSecret,- );+ const integration = await getGitlabIntegration(projectId, includeSecrets);if (!integration) {return c.json(null, 200);}diff --git a/apps/api/src/gitlab-integration/response.ts b/apps/api/src/gitlab-integration/response.tsindex f6e9d82e0..bca701145 100644--- a/apps/api/src/gitlab-integration/response.ts+++ b/apps/api/src/gitlab-integration/response.ts@@ -12,7 +12,10 @@ export const gitlabIntegrationSchema = zdescription: "Full path of the linked project, nested groups included.",}),tokenType: z.enum(["private", "bearer"]),- maskedAccessToken: z.string(),+ maskedAccessToken: z.string().openapi({+ description:+ "First and last characters of the stored token, only returned to callers with workspace:manage_settings.",+ }),webhookUrl: z.string().optional().openapi({description: "Where GitLab should POST events for this project.",}),diff --git a/apps/docs/openapi.json b/apps/docs/openapi.jsonindex 0d453c232..bd81c2998 100644--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@ -2495,7 +2495,8 @@]},"maskedAccessToken": {- "type": "string"+ "type": "string",+ "description": "First and last characters of the stored token, only returned to callers with workspace:manage_settings."},"webhookUrl": {"type": "string",@@ -11667,7 +11668,7 @@"GitLab"],"summary": "Get GitLab integration",- "description": "Get the GitLab integration for a project, or null when none is configured. The webhook secret is included only for callers with workspace:manage_settings.",+ "description": "Get the GitLab integration for a project, or null when none is configured. The masked access token and the webhook secret are included only for callers with workspace:manage_settings.","parameters": [{"schema": {diff --git a/tests/api/gitlab-integration/get-gitlab-integration.test.ts b/tests/api/gitlab-integration/get-gitlab-integration.test.tsnew file mode 100644index 000000000..3063be965--- /dev/null+++ b/tests/api/gitlab-integration/get-gitlab-integration.test.ts@@ -0,0 +1,43 @@+import { describe, expect, it, vi } from "vitest";++vi.mock("../../../apps/api/src/database", () => ({+ default: {+ query: {+ integrationTable: {+ findFirst: async () => ({+ id: "integration-1",+ projectId: "project-1",+ isActive: true,+ createdAt: new Date(),+ updatedAt: new Date(),+ config: JSON.stringify({+ baseUrl: "https://gitlab.com",+ accessToken: "glpat-abcdefghijklmnop",+ projectPath: "acme/web",+ webhookSecret: "webhook-secret",+ }),+ }),+ },+ },+ },+}));++const { default: getGitlabIntegration } = await import(+ "../../../apps/api/src/gitlab-integration/controllers/get-gitlab-integration"+);++describe("getGitlabIntegration secrets", () => {+ it("returns no token hint or webhook secret to other members", async () => {+ const integration = await getGitlabIntegration("project-1");++ expect(integration?.maskedAccessToken).toBe("");+ expect(integration?.webhookSecret).toBe("");+ });++ it("returns the token hint and webhook secret to settings managers", async () => {+ const integration = await getGitlabIntegration("project-1", true);++ expect(integration?.maskedAccessToken).toBe("glpa••••••mnop");+ expect(integration?.webhookSecret).toBe("webhook-secret");+ });+});