@devries-cameron20 / t3code Mirror · read-only / commits / bdcca0d703
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

fix(server): a linked workspace file is served only if its target is previewable (#39491)

Julius Marminge committed Nov 19, 2026 at 19:47 UTC bdcca0d703b3c87785bb5371836d619936873134
2 files changed +48 -1
apps/server/src/assets/AssetAccess.test.ts
+40
@@ -733,6 +733,46 @@ describe("AssetAccess", () => {
733 }).pipe(Effect.provide(layerTest)),
734 );
735
736 + it.effect.skipIf(!symlinksSupported)(
737 + "serves a linked workspace file only while its target is previewable",
738 + () =>
739 + Effect.gen(function* () {
740 + const fs = yield* FileSystem.FileSystem;
741 + const path = yield* Path.Path;
742 + const root = yield* fs.realPath(yield* fs.makeTempDirectoryScoped({ prefix: "t3-link-" }));
743 + yield* fs.writeFileString(path.join(root, "payload.xhtml"), "<html/>");
744 + yield* fs.writeFileString(path.join(root, "real.pdf"), "%PDF-1.4");
745 + const link = path.join(root, "report.pdf");
746 + const issue = issueAssetUrl({
747 + resource: {
748 + _tag: "workspace-file",
749 + threadId: ThreadId.make("thread-1"),
750 + path: "report.pdf",
751 + },
752 + workspaceRoot: root,
753 + });
754 + const resolveIssued = (relativeUrl: string) => {
755 + const suffix = relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
756 + const separator = suffix.indexOf("/");
757 + return resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1));
758 + };
759 +
760 + yield* fs.symlink(path.join(root, "payload.xhtml"), link);
761 + expect((yield* issue.pipe(Effect.flip))._tag).toBe("AssetPreviewTypeValidationError");
762 +
763 + yield* fs.remove(link);
764 + yield* fs.symlink(path.join(root, "real.pdf"), link);
765 + const issued = yield* issue;
766 + expect(yield* resolveIssued(issued.relativeUrl)).toMatchObject({
767 + path: path.join(root, "real.pdf"),
768 + });
769 +
770 + yield* fs.remove(link);
771 + yield* fs.symlink(path.join(root, "payload.xhtml"), link);
772 + expect(yield* resolveIssued(issued.relativeUrl)).toBeNull();
773 + }).pipe(Effect.provide(layerTest)),
774 + );
775 +
776 it.effect.skipIf(!symlinksSupported)("does not issue URLs for server state files", () =>
777 Effect.gen(function* () {
778 const fs = yield* FileSystem.FileSystem;
apps/server/src/assets/AssetAccess.ts
+8 -1
@@ -538,6 +538,12 @@ const finalizeWorkspaceFileAsset = Effect.fn("AssetAccess.finalizeWorkspaceFileA
538 expectedCanonicalPath: canonicalFile,
539 });
540 }
541 + // The response type follows the file a link points at, so that file must be previewable too.
542 + if (!isWorkspacePreviewEntryPath(canonicalFile)) {
543 + return yield* new AssetPreviewTypeValidationError({
544 + resource: input.resource,
545 + });
546 + }
547 const canonicalWorkspaceRoot = yield* fileSystem.realPath(input.workspaceRoot).pipe(
548 Effect.mapError(
549 (cause) =>
@@ -1091,7 +1097,8 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
1097 workspaceRoot: claims.workspaceRoot,
1098 relativePath: claims.relativePath,
1099 });
1094 - return exactWorkspaceFile
1100 + // Checked again here: a link can be repointed after its URL was issued.
1101 + return exactWorkspaceFile && isWorkspacePreviewEntryPath(exactWorkspaceFile)
1102 ? ({ kind: "file", path: exactWorkspaceFile } satisfies ResolvedAsset)
1103 : null;
1104 }