@devries-cameron20 / t3code Mirror · read-only / commits / b4744496f8
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, 09:45 UTC

fix(server): validate resolved HTML preview dependencies (#37821)

Julius Marminge committed Nov 16, 2026 at 16:38 UTC b4744496f8a30d30daa4cc22af251516d38d47c8
2 files changed +44 -10
apps/server/src/assets/AssetAccess.test.ts
+28
@@ -1001,6 +1001,34 @@ describe("AssetAccess", () => {
1001 }).pipe(Effect.provide(layerTest)),
1002 );
1003
1004 + it.effect.skipIf(!symlinksSupported)("validates canonical preview dependency paths", () =>
1005 + Effect.gen(function* () {
1006 + const fs = yield* FileSystem.FileSystem;
1007 + const path = yield* Path.Path;
1008 + const root = yield* fs.makeTempDirectoryScoped();
1009 + const page = path.join(root, "report.html");
1010 + yield* fs.writeFileString(page, "<!doctype html>");
1011 + for (const name of ["report.css", ".internal.css", "notes.txt"]) {
1012 + yield* fs.writeFileString(path.join(root, name), "fixture");
1013 + }
1014 + yield* fs.symlink(path.join(root, "report.css"), path.join(root, "theme.css"));
1015 + yield* fs.symlink(path.join(root, ".internal.css"), path.join(root, "internal.css"));
1016 + yield* fs.symlink(path.join(root, "notes.txt"), path.join(root, "notes.css"));
1017 +
1018 + const result = yield* issueAssetUrl({
1019 + resource: { _tag: "workspace-file", threadId: ThreadId.make("thread-1"), path: page },
1020 + workspaceRoot: root,
1021 + });
1022 + const suffix = result.relativeUrl.slice(ASSET_ROUTE_PREFIX.length + 1);
1023 + const token = suffix.slice(0, suffix.indexOf("/"));
1024 + expect(yield* resolveAsset(token, "theme.css")).toMatchObject({
1025 + path: yield* fs.realPath(path.join(root, "report.css")),
1026 + });
1027 + expect(yield* resolveAsset(token, "internal.css")).toBeNull();
1028 + expect(yield* resolveAsset(token, "notes.css")).toBeNull();
1029 + }).pipe(Effect.provide(layerTest)),
1030 + );
1031 +
1032 it.effect("issues workspace URLs that resolve the entry file and sibling assets", () =>
1033 Effect.gen(function* () {
1034 const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/assets/AssetAccess.ts
+16 -10
@@ -117,6 +117,12 @@ const PREVIEW_ASSET_EXTENSIONS = new Set([
117 ".woff2",
118 ]);
119
120 +const isPreviewDependencyPath = (filePath: string, path: Path.Path) =>
121 + filePath.length > 0 &&
122 + !filePath.includes("\0") &&
123 + !filePath.split(/[\\/]/).some((segment) => segment.startsWith(".")) &&
124 + PREVIEW_ASSET_EXTENSIONS.has(path.extname(filePath).toLowerCase());
125 +
126 const AssetClaimsSchema = Schema.Union([
127 Schema.Struct({
128 version: Schema.Literal(1),
@@ -305,7 +311,11 @@ const resolveCanonicalFile = Effect.fn("AssetAccess.resolveCanonicalFile")(funct
311 });
312
313 const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWorkspaceFile")(
308 - function* (input: { readonly workspaceRoot: string; readonly relativePath: string }) {
314 + function* (input: {
315 + readonly workspaceRoot: string;
316 + readonly relativePath: string;
317 + readonly previewDependency?: true;
318 + }) {
319 const fileSystem = yield* FileSystem.FileSystem;
320 const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
321 const resolved = yield* workspacePaths.resolveRelativePathWithinRoot(input).pipe(
@@ -326,6 +336,8 @@ const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWor
336 const relative = path.relative(canonicalRoot.value, canonicalFile.value);
337 if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) return null;
338
339 + if (input.previewDependency && !isPreviewDependencyPath(relative, path)) return null;
340 +
341 const info = yield* ProjectFaviconResolver.optionOnNotFound(
342 fileSystem.stat(canonicalFile.value),
343 );
@@ -338,6 +350,7 @@ const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWor
350 const resolveCanonicalWorkspaceFileForRequest = (input: {
351 readonly workspaceRoot: string;
352 readonly relativePath: string;
353 + readonly previewDependency?: true;
354 }) =>
355 resolveCanonicalWorkspaceFile(input).pipe(
356 Effect.tapError((cause) =>
@@ -1070,20 +1083,13 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
1083 ? ({ kind: "file", path: exactWorkspaceFile } satisfies ResolvedAsset)
1084 : null;
1085 }
1073 - const segments = decodedPath.split(/[\\/]/);
1074 - if (
1075 - decodedPath.length === 0 ||
1076 - decodedPath.includes("\0") ||
1077 - segments.some((segment) => segment === "." || segment === ".." || segment.startsWith(".")) ||
1078 - !PREVIEW_ASSET_EXTENSIONS.has(path.extname(decodedPath).toLowerCase())
1079 - ) {
1080 - return null;
1081 - }
1086 + if (!isPreviewDependencyPath(decodedPath, path)) return null;
1087 const joinedRelativePath =
1088 claims.baseRelativePath === "." ? decodedPath : path.join(claims.baseRelativePath, decodedPath);
1089 const workspaceFile = yield* resolveCanonicalWorkspaceFileForRequest({
1090 workspaceRoot: claims.workspaceRoot,
1091 relativePath: joinedRelativePath,
1092 + previewDependency: true,
1093 });
1094 return workspaceFile ? ({ kind: "file", path: workspaceFile } satisfies ResolvedAsset) : null;
1095 });