Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(security): close permission and integration gaps (#1802)

Tin Sever1196880139f3
diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml
index 75fdb1718..ab9abce3e 100644
--- a/.github/workflows/auto-merge.yml
+++ b/.github/workflows/auto-merge.yml
@@ -6,7 +6,7 @@ on:
# request content; merges via the GitHub API only after required checks pass
# and the head commit is pinned.
pull_request_target:
- types: [opened, synchronize, reopened, ready_for_review]
+ types: [opened, synchronize]
permissions:
contents: read
@@ -16,9 +16,10 @@ jobs:
dependabot:
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 45
- # The pull request author's login is authoritative for this check;
- # github.actor would be spoofable and adds nothing on top of it.
+ # Only bot-created updates opt into automation. A maintainer reopening or
+ # marking a rejected PR ready must not override the earlier decision.
if: >-
+ github.actor == 'dependabot[bot]' &&
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.head.repo.full_name == github.repository
@@ -46,6 +47,9 @@ jobs:
EXPECTED_HEAD: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
+ # A later bot update must not re-enable automation on a rejected PR.
+ gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/events" \
+ | jq -se 'add | all(.[]; .event != "closed")'
# Only manifests and the lockfile are eligible, including on renames.
gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files" \
| jq -se 'add | length > 0 and all(.[];
diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml
index 5cdbbf173..bc8605446 100644
--- a/.github/workflows/build-images.yml
+++ b/.github/workflows/build-images.yml
@@ -54,7 +54,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
fetch-depth: 0
@@ -68,7 +68,7 @@ jobs:
run: node scripts/security/verify-release-source.mjs "$SOURCE_MODE" "$RELEASE_VERSION"
- name: Checkout verified source
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
ref: ${{ steps.source.outputs.source_sha }}
@@ -85,7 +85,7 @@ jobs:
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- name: Setup Blacksmith Builder
- uses: useblacksmith/setup-docker-builder@v1
+ uses: useblacksmith/setup-docker-builder@e4c1c000c95f9cc255f72940e9c56bcbd1239436 # v1
- name: Log in to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
@@ -111,7 +111,7 @@ jobs:
chmod 600 /tmp/sentry-build-secrets/SENTRY_AUTH_TOKEN
- name: Build and push
- uses: useblacksmith/build-push-action@v2 # v7
+ uses: useblacksmith/build-push-action@9b0579bbec7a6cad2f171596c57e7ac1e7658850 # v2
with:
context: .
file: ${{ matrix.dockerfile }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9c25fcfd3..e1ae4f2b7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -19,7 +19,7 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 5
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
@@ -36,7 +36,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -60,7 +60,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
@@ -86,7 +86,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
@@ -112,7 +112,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -136,7 +136,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -168,7 +168,7 @@ jobs:
timeout-minutes: 15
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -216,7 +216,7 @@ jobs:
DISABLE_GUEST_ACCESS: "false"
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -240,13 +240,13 @@ jobs:
timeout-minutes: 30
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup Blacksmith Builder
- uses: useblacksmith/setup-docker-builder@v1
+ uses: useblacksmith/setup-docker-builder@e4c1c000c95f9cc255f72940e9c56bcbd1239436 # v1
- name: Build bundled image for runtime tests
- uses: useblacksmith/build-push-action@v2 # v7
+ uses: useblacksmith/build-push-action@9b0579bbec7a6cad2f171596c57e7ac1e7658850 # v2
with:
context: .
file: ./Dockerfile.kaneo
@@ -302,7 +302,7 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 5
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- name: Install verified actionlint
@@ -343,7 +343,7 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 10
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
@@ -385,13 +385,13 @@ jobs:
matrix:
name: [api, web]
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- name: Setup Blacksmith Builder
- uses: useblacksmith/setup-docker-builder@v1
+ uses: useblacksmith/setup-docker-builder@e4c1c000c95f9cc255f72940e9c56bcbd1239436 # v1
- name: Build standalone image
- uses: useblacksmith/build-push-action@v2 # v7
+ uses: useblacksmith/build-push-action@9b0579bbec7a6cad2f171596c57e7ac1e7658850 # v2
with:
context: .
file: ./apps/${{ matrix.name }}/Dockerfile
@@ -409,7 +409,7 @@ jobs:
security-events: write
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
# TruffleHog resolves the diff base locally, so the base commit must exist.
diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml
index da69d0518..f7f0cb68a 100644
--- a/.github/workflows/code-review.yml
+++ b/.github/workflows/code-review.yml
@@ -26,7 +26,7 @@ jobs:
allowed: ${{ steps.request.outputs.allowed }}
pr: ${{ steps.request.outputs.pr }}
steps:
- - uses: useblacksmith/checkout@v1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
persist-credentials: false
@@ -49,7 +49,7 @@ jobs:
group: peekareview-${{ needs.authorize.outputs.pr }}
cancel-in-progress: false
steps:
- - uses: useblacksmith/checkout@v1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 0
diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml
index d2becc00b..ca470061d 100644
--- a/.github/workflows/deploy-site.yml
+++ b/.github/workflows/deploy-site.yml
@@ -29,7 +29,7 @@ jobs:
steps:
- name: Checkout
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
diff --git a/.github/workflows/helm-chart.yml b/.github/workflows/helm-chart.yml
index e54a12d53..2ecb41ef3 100644
--- a/.github/workflows/helm-chart.yml
+++ b/.github/workflows/helm-chart.yml
@@ -42,7 +42,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
fetch-depth: 0
@@ -55,7 +55,7 @@ jobs:
run: node scripts/security/verify-release-source.mjs released "$RELEASE_VERSION"
- name: Checkout verified release tag
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
ref: ${{ steps.source.outputs.source_sha }}
diff --git a/.github/workflows/helm-validate.yml b/.github/workflows/helm-validate.yml
index 336557294..214906a0b 100644
--- a/.github/workflows/helm-validate.yml
+++ b/.github/workflows/helm-validate.yml
@@ -50,7 +50,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index f51e6b3dd..43735fb21 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -24,7 +24,7 @@ jobs:
security-events: write
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
# The entire-branch scan needs the full commit history.
@@ -109,7 +109,7 @@ jobs:
security-events: write
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- name: Install zizmor
diff --git a/.github/workflows/pr-size-labeler.yml b/.github/workflows/pr-size-labeler.yml
index 0cb572c98..4f56a61af 100644
--- a/.github/workflows/pr-size-labeler.yml
+++ b/.github/workflows/pr-size-labeler.yml
@@ -21,7 +21,7 @@ jobs:
steps:
# Only read trusted base-branch configuration, including for fork PRs.
- name: Checkout size configuration
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.event.pull_request.base.sha }}
persist-credentials: false
diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml
index 817760e96..0fdc97154 100644
--- a/.github/workflows/pr-title.yml
+++ b/.github/workflows/pr-title.yml
@@ -17,7 +17,7 @@ jobs:
timeout-minutes: 5
steps:
# Validate using the target branch's policy, not code supplied by the PR.
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.event.pull_request.base.sha }}
persist-credentials: false
diff --git a/.github/workflows/publish-mcp.yml b/.github/workflows/publish-mcp.yml
index 3824128a1..be817ae84 100644
--- a/.github/workflows/publish-mcp.yml
+++ b/.github/workflows/publish-mcp.yml
@@ -27,7 +27,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
fetch-depth: 0
@@ -123,7 +123,7 @@ jobs:
id-token: write
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
diff --git a/.github/workflows/publish-planka-import.yml b/.github/workflows/publish-planka-import.yml
index 0496dfb6c..ca7f972c7 100644
--- a/.github/workflows/publish-planka-import.yml
+++ b/.github/workflows/publish-planka-import.yml
@@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
fetch-depth: 0
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index bc5590c8e..c36931236 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -46,7 +46,7 @@ jobs:
fi
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
fetch-depth: 0
@@ -105,7 +105,7 @@ jobs:
contents: read
actions: read
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
@@ -159,7 +159,7 @@ jobs:
# The same token the API calls use, so the release commit and tag are not
# pushed under a different identity than the one that was verified.
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/ui-review-run.yml b/.github/workflows/ui-review-run.yml
index b93cb8738..a429fb868 100644
--- a/.github/workflows/ui-review-run.yml
+++ b/.github/workflows/ui-review-run.yml
@@ -26,7 +26,7 @@ jobs:
outputs:
artifact: ${{ steps.plan-artifact.outputs.artifact-id }}
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 0
@@ -59,7 +59,7 @@ jobs:
outputs:
artifact: ${{ steps.capture-artifact.outputs.artifact-id }}
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
fetch-depth: 0
@@ -95,7 +95,7 @@ jobs:
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
persist-credentials: false
diff --git a/.github/workflows/ui-review.yml b/.github/workflows/ui-review.yml
index c962fefc1..720e38164 100644
--- a/.github/workflows/ui-review.yml
+++ b/.github/workflows/ui-review.yml
@@ -33,7 +33,7 @@ jobs:
pr: ${{ steps.request.outputs.pr }}
model: ${{ steps.request.outputs.model }}
steps:
- - uses: useblacksmith/checkout@v1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
ref: ${{ github.workflow_sha }}
persist-credentials: false
diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml
index 174ecb6e7..d25a4c5b8 100644
--- a/.github/workflows/update-contributors.yml
+++ b/.github/workflows/update-contributors.yml
@@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout repository
- uses: useblacksmith/checkout@v1 # v7.0.1
+ uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
- name: Generate Contributors Images
uses: jaywcjlove/github-action-contributors@86707f6d4c2469ce6b46bc3367253ebd41ee242c # main
diff --git a/apps/api/src/comment/schema.ts b/apps/api/src/comment/schema.ts
index 9144dfe5d..c05f4971e 100644
--- a/apps/api/src/comment/schema.ts
+++ b/apps/api/src/comment/schema.ts
@@ -5,7 +5,7 @@ export const taskIdParam = z.object({ taskId: z.string() });
export const commentParam = z.object({ id: z.string() });
export const createCommentBody = z.object({
- content: z.string().min(1),
+ content: z.string().min(1).max(10_000),
// Both or neither: a name without a source would render as an unattributed
// impersonation of a real account.
externalUserName: z.string().max(120).optional().openapi({
@@ -18,4 +18,6 @@ export const createCommentBody = z.object({
}),
});
-export const updateCommentBody = z.object({ content: z.string().min(1) });
+export const updateCommentBody = z.object({
+ content: z.string().min(1).max(10_000),
+});
diff --git a/apps/api/src/gitea-integration/controllers/list-gitea-repositories.ts b/apps/api/src/gitea-integration/controllers/list-gitea-repositories.ts
index 16782845b..02f600b1d 100644
--- a/apps/api/src/gitea-integration/controllers/list-gitea-repositories.ts
+++ b/apps/api/src/gitea-integration/controllers/list-gitea-repositories.ts
@@ -26,7 +26,7 @@ async function listGiteaRepositories({
try {
await verifyGiteaToken(normalized, accessToken);
} catch {
- throw new HTTPException(401, {
+ throw new HTTPException(400, {
message: "Invalid Gitea token or could not reach instance.",
});
}
diff --git a/apps/api/src/gitea-integration/controllers/verify-gitea-access.ts b/apps/api/src/gitea-integration/controllers/verify-gitea-access.ts
index 8e51b6689..97e78d1e0 100644
--- a/apps/api/src/gitea-integration/controllers/verify-gitea-access.ts
+++ b/apps/api/src/gitea-integration/controllers/verify-gitea-access.ts
@@ -102,7 +102,7 @@ async function verifyGiteaAccess({
}
if (err.status === 401) {
- throw new HTTPException(401, {
+ throw new HTTPException(400, {
message: "Invalid Gitea token or unauthorized.",
});
}
diff --git a/apps/api/src/gitea-integration/index.ts b/apps/api/src/gitea-integration/index.ts
index 74bf98838..5ff687705 100644
--- a/apps/api/src/gitea-integration/index.ts
+++ b/apps/api/src/gitea-integration/index.ts
@@ -63,7 +63,9 @@ const listRepositoriesRoute = createRoute({
},
responses: {
200: jsonResponse("Accessible repositories", giteaRepositoryListSchema),
- 400: errorResponse("Invalid body, or unknown project"),
+ 400: errorResponse(
+ "Invalid body, unknown project, or invalid Gitea credentials",
+ ),
403: errorResponse(
"No workspace access, or missing workspace:manage_settings",
),
@@ -87,9 +89,11 @@ const verifyRoute = createRoute({
},
responses: {
200: jsonResponse("Verification result", giteaVerificationResultSchema),
- 401: errorResponse("Gitea rejected the token"),
+ 401: errorResponse("Kaneo authentication required"),
500: errorResponse("Gitea verification failed"),
- 400: errorResponse("Invalid body, or unknown project"),
+ 400: errorResponse(
+ "Invalid body, unknown project, or invalid Gitea credentials",
+ ),
403: errorResponse(
"No workspace access, or missing workspace:manage_settings",
),
diff --git a/apps/api/src/gitlab-integration/controllers/create-gitlab-integration.ts b/apps/api/src/gitlab-integration/controllers/create-gitlab-integration.ts
index 22ec8f7cb..35d307a3c 100644
--- a/apps/api/src/gitlab-integration/controllers/create-gitlab-integration.ts
+++ b/apps/api/src/gitlab-integration/controllers/create-gitlab-integration.ts
@@ -82,7 +82,22 @@ async function createGitlabIntegration({
}
}
- const resolvedToken = accessToken?.trim() || previousConfig.accessToken || "";
+ const suppliedToken = accessToken?.trim();
+ // A saved credential is only authorized for its original server and path.
+ if (!suppliedToken && previousConfig.accessToken) {
+ let savedBase: string | undefined;
+ try {
+ savedBase = normalizeGitlabBaseUrl(previousConfig.baseUrl ?? "");
+ } catch {
+ // Invalid legacy destinations cannot authorize credential reuse.
+ }
+ if (savedBase !== normalizedBase) {
+ throw new HTTPException(400, {
+ message: "Enter a new access token when changing the GitLab URL",
+ });
+ }
+ }
+ const resolvedToken = suppliedToken || previousConfig.accessToken || "";
if (!resolvedToken) {
throw new HTTPException(400, {
diff --git a/apps/api/src/gitlab-integration/schema.ts b/apps/api/src/gitlab-integration/schema.ts
index 9631bab30..ba7074aaf 100644
--- a/apps/api/src/gitlab-integration/schema.ts
+++ b/apps/api/src/gitlab-integration/schema.ts
@@ -25,7 +25,8 @@ export const verifyGitlabBody = z.object({
export const createGitlabBody = z.object({
baseUrl: z.url(),
accessToken: z.string().optional().openapi({
- description: "Omit to keep the token already stored for this project.",
+ description:
+ "Omit to keep the stored token only when the GitLab base URL is unchanged. A changed URL requires a new token.",
}),
tokenType,
projectPath: z.string().min(1),
diff --git a/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts b/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts
index 8d072c4a6..42bd1dbae 100644
--- a/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts
+++ b/apps/api/src/plugins/gitlab/utils/sync-label-to-gitlab.ts
@@ -92,11 +92,22 @@ async function getGitlabIssueContext(taskId: string) {
};
}
+function containsTaskFieldLabel(labelName: string) {
+ // GitLab interprets add_labels/remove_labels as comma-separated names.
+ return labelName.split(",").some((name) => {
+ const label = name.trim();
+ return label.startsWith("priority:") || label.startsWith("status:");
+ });
+}
+
export async function syncLabelToGitlab(
taskId: string,
labelName: string,
labelColor: string,
) {
+ // These labels drive task fields on the webhook return path. Ordinary label
+ // permissions must not grant the ability to update status or priority.
+ if (containsTaskFieldLabel(labelName)) return;
const ctx = await getGitlabIssueContext(taskId);
if (!ctx) return;
@@ -131,6 +142,7 @@ export async function syncLabelToGitlab(
}
export async function removeLabelFromGitlab(taskId: string, labelName: string) {
+ if (containsTaskFieldLabel(labelName)) return;
const ctx = await getGitlabIssueContext(taskId);
if (!ctx) return;
diff --git a/apps/api/src/task/controllers/duplicate-task.ts b/apps/api/src/task/controllers/duplicate-task.ts
index 7ed63f24a..d9c770695 100644
--- a/apps/api/src/task/controllers/duplicate-task.ts
+++ b/apps/api/src/task/controllers/duplicate-task.ts
@@ -119,10 +119,12 @@ async function duplicateDescriptionAssets({
async function duplicateTask({
taskId,
currentUserId,
+ canUpdateTasks,
title,
}: {
taskId: string;
currentUserId: string;
+ canUpdateTasks: boolean;
title?: string;
}) {
const sourceTask = await db.query.taskTable.findFirst({
@@ -231,6 +233,12 @@ async function duplicateTask({
),
);
+ if (parentRelations.length > 0 && !canUpdateTasks) {
+ throw new HTTPException(403, {
+ message: "Duplicating parent links requires task:update permission",
+ });
+ }
+
// The destination object keys embed the new task id, so it is generated up front
// instead of being left to the insert.
const duplicatedTaskId = createId();
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 20cc805ab..878c4cf53 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -24,7 +24,10 @@ import {
verifyTaskAssetUpload,
} from "../storage/s3";
import { normalizeApiServerUrl } from "../utils/openapi-spec";
-import { requireWorkspacePermission } from "../utils/require-workspace-permission";
+import {
+ hasWorkspacePermission,
+ requireWorkspacePermission,
+} from "../utils/require-workspace-permission";
import {
validateAndParseDate,
validateDateRange,
@@ -177,7 +180,7 @@ const duplicateTaskRoute = createRoute({
tags: ["Tasks"],
summary: "Duplicate a task",
description:
- "Copy a task into the same project and column, including custom fields, labels, description assets and same-workspace parent links. Comments, time entries and child tasks are not copied.",
+ "Copy a task into the same project and column, including custom fields, labels, description assets and same-workspace parent links. Copying parent links also requires task:update. Comments, time entries and child tasks are not copied.",
middleware: [
workspaceAccess.fromTask(),
requireWorkspacePermission({ task: ["create"] }),
@@ -194,7 +197,9 @@ const duplicateTaskRoute = createRoute({
200: jsonResponse("The duplicated task", taskSchema),
400: errorResponse("Invalid task fields or request"),
401: errorResponse("Unauthorized"),
- 403: errorResponse("No workspace access or task:create permission"),
+ 403: errorResponse(
+ "No workspace access, missing task:create, or missing task:update when copying parent links",
+ ),
404: errorResponse("Task or project not found"),
409: errorResponse("Task column has reached its capacity"),
503: errorResponse("Unable to copy task attachments"),
@@ -720,6 +725,7 @@ const task = apiRouter<BaseVariables & { workspaceId: string }>()
taskId: id,
title,
currentUserId: c.get("userId"),
+ canUpdateTasks: await hasWorkspacePermission(c, { task: ["update"] }),
}),
200,
);
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index b2b0d2878..ec2f6ea71 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -8580,7 +8580,7 @@
"Tasks"
],
"summary": "Duplicate a task",
- "description": "Copy a task into the same project and column, including custom fields, labels, description assets and same-workspace parent links. Comments, time entries and child tasks are not copied.",
+ "description": "Copy a task into the same project and column, including custom fields, labels, description assets and same-workspace parent links. Copying parent links also requires task:update. Comments, time entries and child tasks are not copied.",
"parameters": [
{
"schema": {
@@ -8638,7 +8638,7 @@
}
},
"403": {
- "description": "No workspace access or task:create permission",
+ "description": "No workspace access, missing task:create, or missing task:update when copying parent links",
"content": {
"text/plain": {
"schema": {
@@ -10663,7 +10663,8 @@
"properties": {
"content": {
"type": "string",
- "minLength": 1
+ "minLength": 1,
+ "maxLength": 10000
},
"externalUserName": {
"type": "string",
@@ -10751,7 +10752,8 @@
"properties": {
"content": {
"type": "string",
- "minLength": 1
+ "minLength": 1,
+ "maxLength": 10000
}
},
"required": [
@@ -12995,7 +12997,7 @@
}
},
"400": {
- "description": "Invalid body, or unknown project",
+ "description": "Invalid body, unknown project, or invalid Gitea credentials",
"content": {
"text/plain": {
"schema": {
@@ -13079,7 +13081,7 @@
}
},
"400": {
- "description": "Invalid body, or unknown project",
+ "description": "Invalid body, unknown project, or invalid Gitea credentials",
"content": {
"text/plain": {
"schema": {
@@ -13089,7 +13091,7 @@
}
},
"401": {
- "description": "Gitea rejected the token",
+ "description": "Kaneo authentication required",
"content": {
"text/plain": {
"schema": {
@@ -13747,7 +13749,7 @@
},
"accessToken": {
"type": "string",
- "description": "Omit to keep the token already stored for this project."
+ "description": "Omit to keep the stored token only when the GitLab base URL is unchanged. A changed URL requires a new token."
},
"tokenType": {
"type": "string",
diff --git a/apps/web/src/lib/normalize-comment-markdown.test.ts b/apps/web/src/lib/normalize-comment-markdown.test.ts
index 071a65d7d..4ce2e7e9b 100644
--- a/apps/web/src/lib/normalize-comment-markdown.test.ts
+++ b/apps/web/src/lib/normalize-comment-markdown.test.ts
@@ -53,3 +53,22 @@ describe("normalizeCommentMarkdown", () => {
);
});
});
+
+it("preserves unequal and nested backtick runs without rescanning suffixes", () => {
+ const value = "Before&nbsp; ``a`&nbsp;b`` after&nbsp; `unmatched&nbsp;";
+ expect(normalizeCommentMarkdown(value)).toBe(
+ "Before ``a`&nbsp;b`` after `unmatched ",
+ );
+});
+
+it("handles a stored comment with thousands of unmatched delimiter lengths promptly", () => {
+ const delimiters = Array.from(
+ { length: 3000 },
+ (_, i) => `${"`".repeat(3000 - i)}&nbsp;`,
+ ).join(" ");
+ const value = `prefix ${delimiters}`;
+ const start = performance.now();
+ const result = normalizeCommentMarkdown(value);
+ expect(performance.now() - start).toBeLessThan(1000);
+ expect(result).toBe(value.replaceAll("&nbsp;", " "));
+});
diff --git a/apps/web/src/lib/normalize-comment-markdown.ts b/apps/web/src/lib/normalize-comment-markdown.ts
index 9d74b12bf..0a6bbd8b8 100644
--- a/apps/web/src/lib/normalize-comment-markdown.ts
+++ b/apps/web/src/lib/normalize-comment-markdown.ts
@@ -2,64 +2,34 @@ function normalizeSpaces(markdown: string) {
return markdown.replace(/&nbsp;/g, " ").replace(/\u00A0/g, " ");
}
-function findClosingBacktickRun(
- markdown: string,
- start: number,
- delimiterLength: number,
-) {
- let index = start;
-
- while (index < markdown.length) {
- if (markdown[index] !== "`") {
- index += 1;
- continue;
- }
-
- let runLength = 1;
- while (markdown[index + runLength] === "`") {
- runLength += 1;
- }
-
- if (runLength === delimiterLength) return index;
- index += runLength;
+function normalizeInlineMarkdown(markdown: string) {
+ const runs = Array.from(markdown.matchAll(/`+/g), (match) => ({
+ index: match.index,
+ length: match[0].length,
+ next: -1,
+ }));
+ // Index matching delimiters once. Restarting a suffix scan for each unmatched
+ // run makes descending run lengths quadratic in the number of delimiters.
+ const nextByLength = new Map<number, number>();
+ for (let index = runs.length - 1; index >= 0; index -= 1) {
+ const run = runs[index];
+ run.next = nextByLength.get(run.length) ?? -1;
+ nextByLength.set(run.length, index);
}
- return -1;
-}
-
-function normalizeInlineMarkdown(markdown: string) {
- let output = "";
+ const output: string[] = [];
let textStart = 0;
- let index = 0;
-
- while (index < markdown.length) {
- if (markdown[index] !== "`") {
- index += 1;
- continue;
- }
-
- let delimiterLength = 1;
- while (markdown[index + delimiterLength] === "`") {
- delimiterLength += 1;
- }
-
- const closingIndex = findClosingBacktickRun(
- markdown,
- index + delimiterLength,
- delimiterLength,
- );
- if (closingIndex === -1) {
- index += delimiterLength;
- continue;
- }
-
- output += normalizeSpaces(markdown.slice(textStart, index));
- output += markdown.slice(index, closingIndex + delimiterLength);
- index = closingIndex + delimiterLength;
- textStart = index;
+ for (let index = 0; index < runs.length; index += 1) {
+ const opening = runs[index];
+ if (opening.next === -1) continue;
+ const closing = runs[opening.next];
+ output.push(normalizeSpaces(markdown.slice(textStart, opening.index)));
+ textStart = closing.index + closing.length;
+ output.push(markdown.slice(opening.index, textStart));
+ index = opening.next;
}
-
- return output + normalizeSpaces(markdown.slice(textStart));
+ output.push(normalizeSpaces(markdown.slice(textStart)));
+ return output.join("");
}
export function normalizeCommentMarkdown(markdown: string) {
diff --git a/scripts/security/workflows.test.mjs b/scripts/security/workflows.test.mjs
index c9155b721..1c9caa3e9 100644
--- a/scripts/security/workflows.test.mjs
+++ b/scripts/security/workflows.test.mjs
@@ -1,6 +1,12 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import {
+ mkdtempSync,
+ readdirSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { test } from "node:test";
@@ -69,7 +75,11 @@ test("issue notifications preserve untrusted text without Discord mentions", ()
const ghMock = `#!/bin/sh
set -eu
case "$1 $2" in
- 'api --paginate') printf '%s' "$MOCK_FILES" ;;
+ 'api --paginate')
+ case "$3" in
+ */events) printf '%s' "$MOCK_EVENTS" ;;
+ *) printf '%s' "$MOCK_FILES" ;;
+ esac ;;
'pr checks')
case "$*" in
*--watch*) exit "$MOCK_WATCH_STATUS" ;;
@@ -86,6 +96,11 @@ const manifest = [
];
for (const [name, overrides, allowed] of [
["passing required checks permit the verified head", {}, true],
+ [
+ "a previously closed PR rejects even after a bot update",
+ { events: [{ event: "closed" }, { event: "reopened" }] },
+ false,
+ ],
["missing required checks reject", { checks: [] }, false],
["failing checks reject", { checks: [{ bucket: "fail" }] }, false],
["pending checks reject", { checks: [{ bucket: "pending" }] }, false],
@@ -124,6 +139,7 @@ for (const [name, overrides, allowed] of [
PR_NUMBER: "1",
EXPECTED_HEAD: "reviewed-head",
MOCK_FILES: JSON.stringify(overrides.files ?? manifest),
+ MOCK_EVENTS: JSON.stringify(overrides.events ?? []),
MOCK_CHECKS: JSON.stringify(
"checks" in overrides ? overrides.checks : success,
),
@@ -258,3 +274,31 @@ test("release packages reject a tag outside reviewed main history", () => {
rmSync(dir, { recursive: true, force: true });
}
});
+
+test("Dependabot automation excludes human reopens and ready events", () => {
+ const source = readFileSync(
+ path.join(root, ".github/workflows/auto-merge.yml"),
+ "utf8",
+ );
+ assert.match(source, /types: \[opened, synchronize\]/);
+ assert.match(source, /github\.actor == 'dependabot\[bot\]'/);
+});
+
+test("Blacksmith actions use immutable commits with no scanner exemption", () => {
+ for (const file of readdirSync(path.join(root, ".github/workflows"))) {
+ if (!file.endsWith(".yml")) continue;
+ const source = readFileSync(
+ path.join(root, ".github/workflows", file),
+ "utf8",
+ );
+ for (const match of source.matchAll(
+ /uses: (useblacksmith\/[^@\s]+)@([^\s]+)/g,
+ )) {
+ assert.match(match[2], /^[a-f0-9]{40}$/, `${file}: ${match[1]}`);
+ }
+ }
+ assert.doesNotMatch(
+ readFileSync(path.join(root, "zizmor.yml"), "utf8"),
+ /ref-pin/,
+ );
+});
diff --git a/tests/api-integration/comment-bounds.test.ts b/tests/api-integration/comment-bounds.test.ts
new file mode 100644
index 000000000..cc2e7c8a2
--- /dev/null
+++ b/tests/api-integration/comment-bounds.test.ts
@@ -0,0 +1,57 @@
+import { beforeEach, expect, it } from "vitest";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+beforeEach(resetTestDatabase);
+
+it.each(["comment", "activity"])(
+ "bounds both writes on the %s API without changing stored content",
+ async (surface) => {
+ const member = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Comment bounds",
+ status: "to-do",
+ })
+ .returning();
+ mockAuthenticatedSession(member.user);
+ const { app } = createApp();
+ const request = (method: string, content: string, id = task.id) =>
+ app.request(
+ surface === "comment" ? `/api/comment/${id}` : "/api/activity/comment",
+ {
+ method,
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(
+ surface === "comment"
+ ? { content }
+ : {
+ comment: content,
+ ...(method === "POST" ? { taskId: id } : { activityId: id }),
+ },
+ ),
+ },
+ );
+ expect((await request("POST", "x".repeat(10_001))).status).toBe(400);
+ expect(await db.query.activityTable.findMany()).toHaveLength(0);
+ const created = await request("POST", "x".repeat(10_000));
+ expect(created.status).toBe(200);
+ const { id } = (await created.json()) as { id: string };
+ expect((await request("PUT", "x".repeat(10_001), id)).status).toBe(400);
+ expect(await db.query.activityTable.findMany()).toMatchObject([
+ { id, content: "x".repeat(10_000) },
+ ]);
+ expect((await request("PUT", "edited", id)).status).toBe(200);
+ },
+);
diff --git a/tests/api-integration/gitea-credential-errors.test.ts b/tests/api-integration/gitea-credential-errors.test.ts
new file mode 100644
index 000000000..90b805dfe
--- /dev/null
+++ b/tests/api-integration/gitea-credential-errors.test.ts
@@ -0,0 +1,63 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { createApp } from "../../apps/api/src/index";
+import {
+ GiteaApiError,
+ verifyGiteaToken,
+} from "../../apps/api/src/plugins/gitea/utils/gitea-api";
+import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+vi.mock(
+ "../../apps/api/src/plugins/gitea/utils/gitea-api",
+ async (original) => ({
+ ...(await original<object>()),
+ verifyGiteaToken: vi.fn(),
+ }),
+);
+
+beforeEach(async () => {
+ await resetTestDatabase();
+ vi.clearAllMocks();
+ vi.mocked(verifyGiteaToken).mockRejectedValue(
+ new GiteaApiError("Invalid token", 401, "HTTP_ERROR"),
+ );
+});
+
+describe("Gitea credentials are not Kaneo session credentials", () => {
+ it.each(["verify", "repositories"])(
+ "returns 400 for invalid upstream credentials on %s, but 401 for a missing session",
+ async (endpoint) => {
+ const owner = await createWorkspaceMember({ role: "owner" });
+ const { project } = await createProjectFixture({
+ workspaceId: owner.workspace.id,
+ });
+ const { app } = createApp();
+ const request = () =>
+ app.request(`/api/gitea-integration/${endpoint}`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ projectId: project.id,
+ baseUrl: "https://gitea.example",
+ accessToken: "invalid-secret",
+ repositoryOwner: "owner",
+ repositoryName: "repo",
+ }),
+ });
+ mockAuthenticatedSession(owner.user);
+ const response = await request();
+ expect(response.status).toBe(400);
+ const body = await response.text();
+ expect(body).toContain("Invalid Gitea token");
+ expect(body).not.toContain("invalid-secret");
+ vi.mocked(verifyGiteaToken).mockClear();
+ mockAnonymousSession();
+ expect((await request()).status).toBe(401);
+ expect(verifyGiteaToken).not.toHaveBeenCalled();
+ },
+ );
+});
diff --git a/tests/api-integration/task-duplicate.test.ts b/tests/api-integration/task-duplicate.test.ts
index 9a0d38fa8..b524b37c5 100644
--- a/tests/api-integration/task-duplicate.test.ts
+++ b/tests/api-integration/task-duplicate.test.ts
@@ -1,4 +1,4 @@
-import { randomUUID } from "node:crypto";
+import { createHash, randomUUID } from "node:crypto";
import { and, eq } from "drizzle-orm";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -76,11 +76,13 @@ function requestDuplicate(
app: ReturnType<typeof createApp>["app"],
taskId: string,
body: { title?: string } = {},
+ headers: Record<string, string> = {},
) {
return app.request(`/api/task/duplicate/${taskId}`, {
method: "POST",
headers: {
"content-type": "application/json",
+ ...headers,
},
body: JSON.stringify(body),
});
@@ -351,6 +353,66 @@ describe("API integration: task duplication", () => {
expect(childrenOfCopy).toEqual([]);
});
+ it.each(["custom-role", "api-key"] as const)(
+ "%s cannot copy parent links without task:update but can copy standalone tasks",
+ async (authentication) => {
+ const member = await createWorkspaceMember({
+ role: authentication === "custom-role" ? "creator" : "admin",
+ });
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const parent = await seedTask({
+ projectId: project.id,
+ columnId: columns.todo.id,
+ });
+ const child = await seedTask({
+ projectId: project.id,
+ columnId: columns.todo.id,
+ overrides: { number: 2 },
+ });
+ await db.insert(schema.taskRelationTable).values({
+ sourceTaskId: parent.id,
+ targetTaskId: child.id,
+ relationType: "subtask",
+ });
+ const permissions = { task: ["create", "read"] };
+ const headers: Record<string, string> = {};
+ if (authentication === "custom-role") {
+ await db.insert(schema.workspaceRoleTable).values({
+ workspaceId: member.workspace.id,
+ role: "creator",
+ permission: JSON.stringify(permissions),
+ });
+ mockAuthenticatedSession(member.user);
+ } else {
+ mockAnonymousSession();
+ const key = `kaneo_test_${randomUUID()}`;
+ await db.insert(schema.apikeyTable).values({
+ referenceId: member.user.id,
+ userId: member.user.id,
+ key: createHash("sha256").update(key).digest("base64url"),
+ name: "create-only",
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ permissions: JSON.stringify(permissions),
+ enabled: true,
+ });
+ headers.Authorization = `Bearer ${key}`;
+ }
+ const { app } = createApp();
+ const rejected = await requestDuplicate(app, child.id, {}, headers);
+ expect(rejected.status).toBe(403);
+ expect(await db.query.taskTable.findMany()).toHaveLength(2);
+ expect(await db.query.taskRelationTable.findMany()).toHaveLength(1);
+ expect(copyTaskAssetObject).not.toHaveBeenCalled();
+ expect(publishEvent).not.toHaveBeenCalled();
+ expect((await requestDuplicate(app, parent.id, {}, headers)).status).toBe(
+ 200,
+ );
+ },
+ );
+
it("copies the description assets and repoints the copy at them", async () => {
const member = await createWorkspaceMember();
const { project, columns } = await createProjectFixture({
diff --git a/tests/api/gitlab-integration/create-gitlab-integration.test.ts b/tests/api/gitlab-integration/create-gitlab-integration.test.ts
index fb173f794..955dad839 100644
--- a/tests/api/gitlab-integration/create-gitlab-integration.test.ts
+++ b/tests/api/gitlab-integration/create-gitlab-integration.test.ts
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
existingIntegration: vi.fn(),
updateSet: vi.fn(),
+ verifyToken: vi.fn(),
}));
vi.mock("../../../apps/api/src/database", () => ({
@@ -39,7 +40,7 @@ vi.mock("../../../apps/api/src/database", () => ({
vi.mock("../../../apps/api/src/plugins/gitlab/utils/gitlab-api", () => ({
GitlabApiError: class GitlabApiError extends Error {},
- verifyGitlabToken: async () => ({ id: 1 }),
+ verifyGitlabToken: (...args: unknown[]) => mocks.verifyToken(...args),
createGitlabClient: () => ({ getProject: async () => ({ id: 1 }) }),
}));
@@ -54,6 +55,7 @@ function savedConfig() {
beforeEach(() => {
vi.clearAllMocks();
+ mocks.verifyToken.mockResolvedValue({ id: 1 });
});
describe("createGitlabIntegration on an existing integration", () => {
@@ -135,3 +137,61 @@ describe("createGitlabIntegration input", () => {
expect(mocks.updateSet).not.toHaveBeenCalled();
});
});
+
+describe("saved GitLab credential destination", () => {
+ const input = {
+ projectId: "project-1",
+ baseUrl: "https://gitlab.example/forge",
+ accessToken: undefined,
+ tokenType: "private" as const,
+ projectPath: "acme/web",
+ };
+
+ beforeEach(() => {
+ mocks.existingIntegration.mockResolvedValue({
+ id: "integration-1",
+ config: JSON.stringify({
+ baseUrl: input.baseUrl,
+ accessToken: "saved-secret",
+ projectPath: input.projectPath,
+ }),
+ });
+ });
+
+ it.each([
+ "https://attacker.example/forge",
+ "https://gitlab.example/other",
+ "https://gitlab.example:8443/forge",
+ ])(
+ "rejects changed destination %s before sending the saved credential",
+ async (baseUrl) => {
+ await expect(
+ createGitlabIntegration({ ...input, baseUrl }),
+ ).rejects.toMatchObject({ status: 400 });
+ expect(mocks.verifyToken).not.toHaveBeenCalled();
+ expect(mocks.updateSet).not.toHaveBeenCalled();
+ },
+ );
+
+ it("allows normalized equivalents of the saved destination", async () => {
+ await createGitlabIntegration({ ...input, baseUrl: `${input.baseUrl}/` });
+ expect(mocks.verifyToken).toHaveBeenCalledWith(
+ input.baseUrl,
+ "saved-secret",
+ "private",
+ );
+ });
+
+ it("uses only the freshly supplied token for a changed destination", async () => {
+ await createGitlabIntegration({
+ ...input,
+ baseUrl: "https://other.example",
+ accessToken: "new-token",
+ });
+ expect(mocks.verifyToken).toHaveBeenCalledWith(
+ "https://other.example",
+ "new-token",
+ "private",
+ );
+ });
+});
diff --git a/tests/api/plugins/gitlab/utils/sync-label-to-gitlab.test.ts b/tests/api/plugins/gitlab/utils/sync-label-to-gitlab.test.ts
index efc2479e0..91a9c45e1 100644
--- a/tests/api/plugins/gitlab/utils/sync-label-to-gitlab.test.ts
+++ b/tests/api/plugins/gitlab/utils/sync-label-to-gitlab.test.ts
@@ -77,3 +77,27 @@ describe("GitLab label sync", () => {
expect(mocks.client.updateIssue).not.toHaveBeenCalled();
});
});
+
+it.each([
+ "priority:urgent",
+ "status:done",
+ "bug,priority:urgent",
+ "bug, status:done",
+])(
+ "does not add or remove task-field label %s with ordinary label permissions",
+ async (name) => {
+ mocks.externalLinkFindMany.mockResolvedValue([issueLink(true)]);
+ await syncLabelToGitlab("task-1", name, "red");
+ await removeLabelFromGitlab("task-1", name);
+ expect(mocks.createGitlabClient).not.toHaveBeenCalled();
+ expect(mocks.client.updateIssue).not.toHaveBeenCalled();
+ },
+);
+
+it("still removes ordinary labels", async () => {
+ mocks.externalLinkFindMany.mockResolvedValue([issueLink(true)]);
+ await removeLabelFromGitlab("task-1", "bug");
+ expect(mocks.client.updateIssue).toHaveBeenCalledWith("acme/web", 3, {
+ remove_labels: "bug",
+ });
+});
diff --git a/zizmor.yml b/zizmor.yml
index 7ff98a853..97926932e 100644
--- a/zizmor.yml
+++ b/zizmor.yml
@@ -3,8 +3,4 @@ rules:
unpinned-uses:
config:
policies:
- # Blacksmith's actions are pinned by tag with a version comment,
- # matching this repository's existing pinning convention.
- useblacksmith/*: ref-pin
- # Everything else must be pinned to a commit hash.
"*": hash-pin