Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit d0e2def

Browse files
committed
fix: refactor
1 parent 4c19360 commit d0e2def

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

performance-tests/wrap-performance-test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Output } from "../src/implementations/utils/disk";
33
import { performance } from "perf_hooks";
44
import { existsSync, mkdirSync, rmSync, promises } from "fs";
55
import { SchemaId } from "@tradetrust-tt/tradetrust";
6-
import { join, parse, resolve } from "path";
6+
import { join, parse, resolve, relative, isAbsolute } from "path";
77

88
const DEFAULT_NUMBER_OF_FILE = 2;
99
const DEFAULT_ITERATION = 1;
@@ -20,7 +20,11 @@ const validateFilePath = async (filePath: string, baseDir: string): Promise<stri
2020
}
2121

2222
const canonicalPath = await promises.realpath(resolvedFilePath);
23-
if (!canonicalPath.startsWith(resolve(baseDir))) {
23+
const canonicalBaseDir = await promises.realpath(resolve(baseDir));
24+
25+
// Use relative path check to prevent prefix matching false positives
26+
const relativePath = relative(canonicalBaseDir, canonicalPath);
27+
if (relativePath.startsWith("..") || isAbsolute(relativePath)) {
2428
throw new Error("File path is outside the allowed directory.");
2529
}
2630

0 commit comments

Comments
 (0)