⚡ 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): reject traversal in finalized task image keys
Andrej704daeb43c1d
diff --git a/apps/api/src/storage/s3.ts b/apps/api/src/storage/s3.tsindex c6ff6fe43..7858dc425 100644--- a/apps/api/src/storage/s3.ts+++ b/apps/api/src/storage/s3.ts@@ -324,7 +324,15 @@ export function assertTaskImageKeyMatchesContext(const config = getStorageConfig();const objectPrefix = buildObjectKeyPrefix(context);const fullPrefix = `${applyKeyPrefix(config.keyPrefix, objectPrefix)}/`;- return key.startsWith(fullPrefix);++ if (!key.startsWith(fullPrefix)) {+ return false;+ }++ // The prefix alone is not enough: gateways that normalize paths would let+ // a traversal suffix walk back out into another workspace's objects.+ const suffix = key.slice(fullPrefix.length);+ return /^[A-Za-z0-9._-]+$/.test(suffix) && !suffix.startsWith(".");}export async function getPrivateObject(key: string): Promise<AssetObject> {diff --git a/tests/api/storage/s3.test.ts b/tests/api/storage/s3.test.tsindex d317a3627..adb95b6ea 100644--- a/tests/api/storage/s3.test.ts+++ b/tests/api/storage/s3.test.ts@@ -143,6 +143,38 @@ describe("S3 helpers", () => {).toBe(true);});+ it("assertTaskImageKeyMatchesContext rejects traversal past the prefix", () => {+ process.env.S3_ENDPOINT = "https://storage.example.test";+ process.env.S3_BUCKET = "kaneo";+ process.env.S3_ACCESS_KEY_ID = "test-access-key";+ process.env.S3_SECRET_ACCESS_KEY = "test-secret-key";+ delete process.env.S3_KEY_PREFIX;++ const ctx = {+ workspaceId: "ws1",+ projectId: "p1",+ taskId: "t1",+ surface: "description" as const,+ };+ const prefix = "workspace/ws1/project/p1/task/t1/descriptions";++ expect(+ assertTaskImageKeyMatchesContext(`${prefix}/image-1-abc.png`, ctx),+ ).toBe(true);++ for (const suffix of [+ "../../../../../../workspace/victim/secret.png",+ "nested/deeper.png",+ "..%2Fescape.png",+ ".hidden",+ "back\\slash.png",+ ]) {+ expect(assertTaskImageKeyMatchesContext(`${prefix}/${suffix}`, ctx)).toBe(+ false,+ );+ }+ });+it("applyKeyPrefix prepends prefix and trims trailing slashes", () => {expect(applyKeyPrefix("", "workspace/a/file.png")).toBe("workspace/a/file.png",