@@ -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
0 commit comments