fix(server): refuse symlinked theme files on Windows too (#9580)
Co-authored-by: Claude Code <[email protected]>
This commit is contained in:
1 parent
b123cbb317
commit
781f41ef1f
1 file changed
+11
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user