@devries-cameron20 / t3code Mirror · read-only / commits / 5f4c7161fa
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 24, 10:15 UTC

fix(server): canonicalise media paths the same way their callers do (#9575)

Co-authored-by: Claude Code <noreply@anthropic.com>

Julius Marminge committed Sep 4, 2026 at 13:33 UTC 5f4c7161fa7782ea93b63fe934d43229742e7ec8
3 files changed +22 -11
apps/server/src/assets/AssetAccess.test.ts
+2 -2
@@ -754,7 +754,7 @@ describe("AssetAccess", () => {
754 projectFaviconPath: "brand/custom.svg",
755 });
756
757 - expect(result.sourcePath).toBe("brand/custom.svg");
757 + expect(result.sourcePath).toBe(path.join("brand", "custom.svg"));
758 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-custom\.svg$/);
759 }).pipe(Effect.provide(testLayer)),
760 );
@@ -813,7 +813,7 @@ describe("AssetAccess", () => {
813 projectFaviconPath: "brand/saved.svg",
814 });
815
816 - expect(result.sourcePath).toBe("brand/saved.svg");
816 + expect(result.sourcePath).toBe(path.join("brand", "saved.svg"));
817 expect(result.relativeUrl).toMatch(/\/v[0-9a-f]{64}-saved\.svg$/);
818 }).pipe(Effect.provide(testLayer)),
819 );
apps/server/src/assets/MediaFile.ts
+10 -1
@@ -37,6 +37,11 @@ export interface OpenMediaFile {
37 readonly info: NodeFS.BigIntStats;
38 }
39
40 +const realpathLikeFileSystem = (filePath: string) =>
41 + new Promise<string>((resolve, reject) => {
42 + NodeFS.realpath(filePath, (error, resolved) => (error ? reject(error) : resolve(resolved)));
43 + });
44 +
45 /** Opens a canonical media path once. Replacements cannot change the response's source. */
46 export const openMediaFile = Effect.fn("openMediaFile")(function* (
47 filePath: string,
@@ -71,7 +76,11 @@ export const openMediaFile = Effect.fn("openMediaFile")(function* (
76 ) {
77 return null;
78 }
74 - if ((await NodeFSP.realpath(filePath)) !== filePath) return null;
79 + // Callers canonicalise with Effect's FileSystem.realPath, which is
80 + // Node's JS realpath. fs/promises.realpath is the native binding and
81 + // on Windows also expands 8.3 short names, so a path that is already
82 + // canonical by the caller's rules would still look swapped here.
83 + if ((await realpathLikeFileSystem(filePath)) !== filePath) return null;
84 const after = await NodeFSP.lstat(filePath, { bigint: true });
85 if (!after.isFile() || info.dev !== after.dev || info.ino !== after.ino) return null;
86 accepted = true;
apps/server/src/project/ProjectFaviconResolver.test.ts
+10 -8
@@ -126,6 +126,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
126 it.effect("prefers a t3.json iconPath over well-known files", () =>
127 Effect.gen(function* () {
128 const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;
129 + const path = yield* Path.Path;
130 const cwd = yield* makeTempDir;
131 yield* writeTextFile(cwd, "t3.json", '{ "iconPath": "brand/mark.svg" }');
132 yield* writeTextFile(cwd, "brand/mark.svg", "<svg>mark</svg>");
@@ -134,13 +135,14 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
135 const resolved = yield* resolver.resolvePath(cwd);
136
137 expect(resolved).not.toBeNull();
137 - expect(resolved).toContain("brand/mark.svg");
138 + expect(resolved).toBe(path.join(cwd, "brand", "mark.svg"));
139 }),
140 );
141
142 it.effect("uses a saved project favicon override", () =>
143 Effect.gen(function* () {
144 const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;
145 + const path = yield* Path.Path;
146 const cwd = yield* makeTempDir;
147 yield* writeTextFile(cwd, "brand/custom.svg", "<svg>custom</svg>");
148 yield* writeTextFile(cwd, "favicon.svg", "<svg>automatic</svg>");
@@ -148,7 +150,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
150 const resolved = yield* resolver.resolvePath(cwd, "brand/custom.svg");
151
152 expect(resolved).not.toBeNull();
151 - expect(resolved).toContain("brand/custom.svg");
153 + expect(resolved).toBe(path.join(cwd, "brand", "custom.svg"));
154 }),
155 );
156
@@ -232,7 +234,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
234 const resolved = yield* resolver.resolvePath(cwd);
235
236 expect(resolved).not.toBeNull();
235 - expect(resolved).toContain("public/brand/logo.svg");
237 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
238 }),
239 );
240
@@ -257,7 +259,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
259 const resolved = yield* resolver.resolvePath(cwd);
260
261 expect(resolved).not.toBeNull();
260 - expect(resolved).toContain("public/brand/logo.svg");
262 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
263 }),
264 );
265
@@ -275,7 +277,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
277 const resolved = yield* resolver.resolvePath(cwd);
278
279 expect(resolved).not.toBeNull();
278 - expect(resolved).toContain("public/brand/logo.svg");
280 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
281 }),
282 );
283
@@ -293,7 +295,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
295 const resolved = yield* resolver.resolvePath(cwd);
296
297 expect(resolved).not.toBeNull();
296 - expect(resolved).toContain("public/brand/logo.svg");
298 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
299 }),
300 );
301
@@ -311,7 +313,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
313 const resolved = yield* resolver.resolvePath(cwd);
314
315 expect(resolved).not.toBeNull();
314 - expect(resolved).toContain("public/brand/logo.svg");
316 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
317 }),
318 );
319
@@ -459,7 +461,7 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => {
461 const resolved = yield* resolver.resolvePath(cwd);
462
463 expect(resolved).not.toBeNull();
462 - expect(resolved).toContain("public/brand/logo.svg");
464 + expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
465 }),
466 );
467 });