Skip to content

Commit 64a3651

Browse files
committed
Fixes for test db extraction on windows
1 parent 2128505 commit 64a3651

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

client/src/lib/integration-test-runner.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,11 @@ export class IntegrationTestRunner {
739739
if (!fs.existsSync(absoluteDbPath) && dbPath.endsWith(".testproj")) {
740740
// For paths like "test/ExpressSqlInjection/ExpressSqlInjection.testproj",
741741
// the test source directory is "test/ExpressSqlInjection"
742-
const parts = dbPath.split(path.sep);
742+
// Always split on "/" because fixture paths use forward slashes regardless of OS.
743+
const parts = dbPath.split("/");
743744
const lastPart = parts[parts.length - 1];
744745
const testName = lastPart.replace(".testproj", "");
745-
const parentDir = parts.slice(0, -1).join(path.sep);
746+
const parentDir = parts.slice(0, -1).join("/");
746747

747748
// Check if the parent directory name matches the test name
748749
const parentDirName = parts[parts.length - 2];
@@ -788,10 +789,22 @@ export class IntegrationTestRunner {
788789
// Clean up stale interpretedOutput from prior test runs so that
789790
// directory comparisons only see output from this invocation.
790791
if (toolName === "codeql_query_run" && params.interpretedOutput) {
791-
try {
792-
fs.rmSync(params.interpretedOutput, { recursive: true, force: true });
793-
} catch {
794-
// Ignore — path may not exist yet
792+
const outputPath = String(params.interpretedOutput);
793+
const normalizedOutput = path.normalize(outputPath);
794+
// Safety: reject absolute paths and directory traversals to prevent
795+
// accidental deletion of files outside the working directory (CWE-22).
796+
if (
797+
path.isAbsolute(normalizedOutput) ||
798+
normalizedOutput.startsWith("..") ||
799+
normalizedOutput.includes(`${path.sep}..`)
800+
) {
801+
this.logger.log(` Skipping interpretedOutput cleanup: unsafe path "${outputPath}"`);
802+
} else {
803+
try {
804+
fs.rmSync(outputPath, { recursive: true, force: true });
805+
} catch {
806+
// Ignore — path may not exist yet
807+
}
795808
}
796809
}
797810

server/scripts/extract-test-databases.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ Usage: $0 [OPTIONS]
1111
1212
Extract test databases for CodeQL queries associated with the MCP server.
1313
14-
By default, only databases needed by client integration tests are extracted
15-
(currently: javascript/examples only). Query unit tests (codeql test run)
16-
auto-extract their own databases, so full extraction is rarely needed.
14+
By default, only a minimal set of databases for client integration tests is
15+
pre-extracted (currently: javascript/examples only). This is not an
16+
exhaustive list of databases the integration test suite may use; additional
17+
databases may be extracted on demand, so full extraction is rarely needed.
1718
1819
OPTIONS:
1920
--scope <scope> Extract databases for a specific use case

0 commit comments

Comments
 (0)