@@ -318,31 +318,20 @@ public static int _main(String[] _args) throws Exception {
318318 throw new AssertionError ();
319319 }
320320
321- private static File validateAndSanitizePath (String userInput ) {
322- // Define a base directory for validation
323- String baseDir = "/safe/base/directory" ;
324- Path basePath = Paths .get (baseDir ).toAbsolutePath ().normalize ();
325- Path userPath = Paths .get (userInput ).toAbsolutePath ().normalize ();
326-
327- // Check if the user path is within the base directory
328- if (!userPath .startsWith (basePath )) {
329- throw new IllegalArgumentException ("Invalid file path" );
330- }
331-
332- // Sanitize the path (e.g., remove dangerous characters)
333- String sanitizedPath = userPath .toString ().replaceAll ("[^a-zA-Z0-9./_-]" , "" );
334- return new File (sanitizedPath );
335- }
336-
337- @ SuppressFBWarnings ("PATH_TRAVERSAL_IN" )
321+ @ SuppressFBWarnings (value = "PATH_TRAVERSAL_IN" , justification = "User provided value for running the program." )
338322 private static String readAuthFromFile (String auth ) throws IOException {
339- Path path = validateAndSanitizePath (auth .substring (1 )).toPath ();
323+ Path path ;
324+ try {
325+ path = Paths .get (auth .substring (1 ));
326+ } catch (InvalidPathException e ) {
327+ throw new IOException (e );
328+ }
340329 return Files .readString (path , Charset .defaultCharset ());
341330 }
342331
343- @ SuppressFBWarnings ("PATH_TRAVERSAL_IN" )
332+ @ SuppressFBWarnings (value = "PATH_TRAVERSAL_IN" , justification = "User provided value for running the program. " )
344333 private static File getFileFromArguments (List <String > args ) {
345- return validateAndSanitizePath (args .get (1 ));
334+ return new File (args .get (1 ));
346335 }
347336
348337 private static int webSocketConnection (String url , List <String > args , CLIConnectionFactory factory ) throws Exception {
@@ -354,17 +343,20 @@ public void onOpen(Session session, EndpointConfig config) {}
354343
355344 class Authenticator extends ClientEndpointConfig .Configurator {
356345 HandshakeResponse hr ;
346+
357347 @ Override
358348 public void beforeRequest (Map <String , List <String >> headers ) {
359349 if (factory .authorization != null ) {
360350 headers .put ("Authorization" , List .of (factory .authorization ));
361351 }
362352 }
353+
363354 @ Override
364355 public void afterResponse (HandshakeResponse hr ) {
365356 this .hr = hr ;
366357 }
367358 }
359+
368360 var authenticator = new Authenticator ();
369361
370362 ClientManager client = ClientManager .createClient (JdkClientContainer .class .getName ()); // ~ ContainerProvider.getWebSocketContainer()
0 commit comments