TypeScript
fix(server): refuse symlinked theme files on Windows too (#9580)
Julius Marminge781f41ef1f6b
diff --git a/apps/server/src/environmentTheme.ts b/apps/server/src/environmentTheme.tsindex c038af065bd..b7eb11940ce 100644--- a/apps/server/src/environmentTheme.ts+++ b/apps/server/src/environmentTheme.ts@@ -95,13 +95,23 @@ export class EnvironmentThemeService extends Context.Service<* usable, a symlinked file inside it does not), O_NONBLOCK keeps a FIFO from* blocking the open, and the fstat type and size gate examines the open* descriptor. Returns null for anything that is not a small regular file.+ *+ * Windows has neither flag (the constants are undefined, and OR-ing them in+ * is a no-op), so the symlink check there is an lstat before the open. That+ * leaves a window a swap could slip through, which the descriptor-bound+ * checks below then narrow to "a regular file at that path".*/export const readThemeFileGuarded = (filePath: string, maxBytes: number): string | null => {let fd: number;try {+ if (NodeFS.constants.O_NOFOLLOW === undefined && NodeFS.lstatSync(filePath).isSymbolicLink()) {+ return null;+ }fd = NodeFS.openSync(filePath,- NodeFS.constants.O_RDONLY | NodeFS.constants.O_NOFOLLOW | NodeFS.constants.O_NONBLOCK,+ NodeFS.constants.O_RDONLY |+ (NodeFS.constants.O_NOFOLLOW ?? 0) |+ (NodeFS.constants.O_NONBLOCK ?? 0),);} catch {return null;