Skip to content

Commit a36b386

Browse files
committed
fix: validate projected attachment ownership
1 parent 6d49bb1 commit a36b386

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,20 @@ it.layer(
798798
const { attachmentsDir } = yield* ServerConfig;
799799
const now = "2026-01-01T00:00:00.000Z";
800800
const threadId = ThreadId.make("Thread Revert.Files");
801-
const keepAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000001";
802-
const removeAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000002";
801+
const keepAttachmentId = createAttachmentId(threadId);
802+
const removeAttachmentId = createAttachmentId(threadId);
803803
const keepTextAttachmentId = createAttachmentId(threadId);
804804
const removeTextAttachmentId = createAttachmentId(threadId);
805+
assert.isNotNull(keepAttachmentId);
806+
assert.isNotNull(removeAttachmentId);
805807
assert.isNotNull(keepTextAttachmentId);
806808
assert.isNotNull(removeTextAttachmentId);
807-
if (!keepTextAttachmentId || !removeTextAttachmentId) {
809+
if (
810+
!keepAttachmentId ||
811+
!removeAttachmentId ||
812+
!keepTextAttachmentId ||
813+
!removeTextAttachmentId
814+
) {
808815
return;
809816
}
810817
const keepTextPath = path.join(attachmentsDir, keepTextAttachmentId, "keep.md");
@@ -1038,13 +1045,14 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
10381045
const { attachmentsDir } = yield* ServerConfig;
10391046
const now = "2026-01-01T00:00:00.000Z";
10401047
const threadId = ThreadId.make("Thread Delete.Files");
1041-
const attachmentId = "thread-delete-files-00000000-0000-4000-8000-000000000001";
1048+
const attachmentId = createAttachmentId(threadId);
10421049
const otherThreadAttachmentId = "thread-delete-files-00000000-0000-4000-8000-000000000002";
10431050
const orphanAttachmentId = createAttachmentId(threadId);
10441051
const collidingThreadAttachmentId = createAttachmentId("Thread Delete/Files");
1052+
assert.isNotNull(attachmentId);
10451053
assert.isNotNull(orphanAttachmentId);
10461054
assert.isNotNull(collidingThreadAttachmentId);
1047-
if (!orphanAttachmentId || !collidingThreadAttachmentId) {
1055+
if (!attachmentId || !orphanAttachmentId || !collidingThreadAttachmentId) {
10481056
return;
10491057
}
10501058

‎apps/server/src/orchestration/Layers/ProjectionPipeline.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
type OrchestrationProjectionPipelineShape,
5050
} from "../Services/ProjectionPipeline.ts";
5151
import {
52+
attachmentIdBelongsToThread,
5253
attachmentRelativePath,
5354
collectTextAttachmentRelativePaths,
5455
parseAttachmentIdFromRootEntry,
@@ -346,6 +347,9 @@ function collectThreadAttachmentRelativePaths(
346347
if (attachment.type !== "image") {
347348
continue;
348349
}
350+
if (!attachmentIdBelongsToThread(attachment.id, threadId)) {
351+
continue;
352+
}
349353
relativePaths.add(attachmentRelativePath(attachment));
350354
}
351355
}

0 commit comments

Comments
 (0)