From 98e6cf2ba919cb57dcb37b14df17fc4a8baee370 Mon Sep 17 00:00:00 2001 From: Haileyesus <118998054+blackmammoth@users.noreply.github.com> Date: Mon, 6 Jul 2026 21:37:15 +0300 Subject: [PATCH] fix: use CodeQL-recognized containment check for image reads Replace the path.relative guard in isPathInsideDirectory with the resolve + startsWith(root + sep) idiom so the path-injection barrier is visible to code scanning; behavior is unchanged. --- server/shared/image-attachments.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/shared/image-attachments.ts b/server/shared/image-attachments.ts index b843481c..94cc85a6 100644 --- a/server/shared/image-attachments.ts +++ b/server/shared/image-attachments.ts @@ -91,8 +91,12 @@ export function resolveImageAbsolutePath(cwd: string | undefined, imagePath: str } function isPathInsideDirectory(candidate: string, directory: string): boolean { - const relative = path.relative(path.resolve(directory), candidate); - return relative.length > 0 && !relative.startsWith('..') && !path.isAbsolute(relative); + // resolve + startsWith(root + separator) is the containment idiom CodeQL + // recognizes as a path-injection barrier, and matches the check used by + // resolveImageAssetFile in the assets module. The root itself never + // matches (no trailing separator after resolve), only entries below it. + const resolvedRoot = path.resolve(directory) + path.sep; + return path.resolve(candidate).startsWith(resolvedRoot); } /**