title: How to fix Fortify Path Manipulation ( Input Validation and Representation , Data Flow ) vulnerability
body: <p>I am getting fortify path manipulation vulnerability for creating a file with new keyword </p>
  
  <p>I have tried to sanitize the path before passing it to File object, but the problem persists.
  Tried this link also:
  <a href="https://www.securecoding.cert.org/confluence/display/java/FIO00-J.+Do+not+operate+on+files+in+shared+directories" rel="nofollow noreferrer">https://www.securecoding.cert.org/confluence/display/java/FIO00-J.+Do+not+operate+on+files+in+shared+directories</a></p>
  
  <pre><code>public static String sanitizePath(String sUnsanitized) throws URISyntaxException, EncodingException {
  
     String sSanitized = SAPI.encoder().canonicalize(sUnsanitized);
     return sSanitized;
  
  }
  
  
  //// the main method code snippet /////
  
  String sSanitizedPath = Utils.sanitizePath(file.getOriginalFilename());
  
  -- fortify scan detects problem here ..in below line --
  
  File filePath = new File(AppInitializer.UPLOAD_LOCATION, sSanitizedPath);
  
  String canonicalPath = filePath.getCanonicalPath();
  FileOutputStream fileOutputStream = new FileOutputStream(canonicalPath);
  </code></pre>
  
  <p>After the santizePath , I thought the scan will be not pick ,vulnerabilit but , it did.</p>