@devries-cameron20 / t3code-1 / commits / 16a8876dd7
Fork 0

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

fix(server): bound favicon source scans (#37870)

Julius Marminge committed Nov 17, 2026 at 01:36 UTC 16a8876dd77f3fba72a5d1458e083442de3b1ff9
2 files changed +47 -8
apps/server/src/project/ProjectFaviconResolver.test.ts
+15
@@ -215,6 +215,21 @@ it.layer(layerTest)("ProjectFaviconResolverLive", (it) => {
215 }),
216 );
217
218 + it.effect("skips source metadata beyond the favicon scan limit", () =>
219 + Effect.gen(function* () {
220 + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;
221 + const cwd = yield* makeTempDir;
222 + yield* writeTextFile(
223 + cwd,
224 + "index.html",
225 + `<!-- ${" ".repeat(128 * 1024)} --><link rel="icon" href="/brand/logo.svg">`,
226 + );
227 + yield* writeTextFile(cwd, "public/brand/logo.svg", "<svg>brand</svg>");
228 +
229 + expect(yield* resolver.resolvePath(cwd)).toBeNull();
230 + }),
231 + );
232 +
233 it.effect("resolves icon hrefs from object-literal route metadata", () =>
234 Effect.gen(function* () {
235 const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver;
apps/server/src/project/ProjectFaviconResolver.ts
+32 -8
@@ -16,6 +16,7 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
16 import * as T3ProjectFileLoader from "./T3ProjectFileLoader.ts";
17
18 const FAVICON_CACHE_CAPACITY = 512;
19 +const ICON_SOURCE_SCAN_BYTES = 128 * 1024;
20 const FAVICON_POSITIVE_CACHE_TTL = Duration.minutes(10);
21 const FAVICON_NEGATIVE_CACHE_TTL = Duration.minutes(1);
22
@@ -72,9 +73,9 @@ const ICON_SOURCE_FILES = [
73 "src/index.html",
74 ] as const;
75
75 -// Anchor HTML at <link and scan brace-free metadata runs to avoid quadratic regex rescans.
76 -const LINK_ICON_HTML_RE =
77 - /<link\b(?=[^>]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i;
76 +const HTML_LINK_RE = /<link\b[^<>]*>/gi;
77 +const HTML_ICON_REL_RE = /\brel=["'](?:icon|shortcut icon)["']/i;
78 +const HTML_ICON_HREF_RE = /\bhref=["']([^"'?]+)/i;
79 const ICON_REL_RE = /\brel\s*:\s*["'](?:icon|shortcut icon)["']/i;
80 const ICON_HREF_RE = /\bhref\s*:\s*["']([^"'?]+)/i;
81
@@ -116,8 +117,11 @@ export class ProjectFaviconResolver extends Context.Service<
117 >()("t3/project/ProjectFaviconResolver") {}
118
119 function extractIconHref(source: string): string | null {
119 - const htmlMatch = source.match(LINK_ICON_HTML_RE);
120 - if (htmlMatch?.[1]) return htmlMatch[1];
120 + for (const [tag] of source.matchAll(HTML_LINK_RE)) {
121 + if (!HTML_ICON_REL_RE.test(tag)) continue;
122 + const hrefMatch = tag.match(HTML_ICON_HREF_RE);
123 + if (hrefMatch?.[1]) return hrefMatch[1];
124 + }
125 for (const run of source.split("}")) {
126 if (!ICON_REL_RE.test(run)) continue;
127 const hrefMatch = run.match(ICON_HREF_RE);
@@ -213,7 +217,27 @@ export const make = Effect.gen(function* () {
217 }),
218 ),
219 );
216 - const source = yield* optionOnNotFound(fileSystem.readFileString(sourcePath.absolutePath)).pipe(
220 + const stats = yield* optionOnNotFound(fileSystem.stat(sourcePath.absolutePath)).pipe(
221 + Effect.mapError(
222 + (cause) =>
223 + new ProjectFaviconResolutionError({
224 + operation: "stat-candidate",
225 + workspaceRoot: projectCwd,
226 + relativePath: sourceFile,
227 + absolutePath: sourcePath.absolutePath,
228 + cause,
229 + }),
230 + ),
231 + );
232 + if (Option.isNone(stats) || stats.value.type !== "File") {
233 + return null;
234 + }
235 + const source = yield* optionOnNotFound(
236 + fileSystem.open(sourcePath.absolutePath, { flag: "r" }).pipe(
237 + Effect.flatMap((file) => file.readAlloc(ICON_SOURCE_SCAN_BYTES)),
238 + Effect.scoped,
239 + ),
240 + ).pipe(
241 Effect.mapError(
242 (cause) =>
243 new ProjectFaviconResolutionError({
@@ -225,10 +249,10 @@ export const make = Effect.gen(function* () {
249 }),
250 ),
251 );
228 - if (Option.isNone(source)) {
252 + if (Option.isNone(source) || Option.isNone(source.value)) {
253 return null;
254 }
231 - const href = extractIconHref(source.value);
255 + const href = extractIconHref(new TextDecoder().decode(source.value.value));
256 if (!href) {
257 return null;
258 }