title: Filtering upwards path traversal in Java (or Scala)
body: <p>Are there any standard library methods that can filter out paths which include special traversal sequences, such as <code>../</code> and all other convoluted forms of upwards directory traversal, to safeguard a file path API input from traversing <em>upwards</em> of a given "root" path?</p>
  
  <p>I have a class that contains a root folder value member, and a member function that accepts paths to recursively delete. My goal is to make this API safe, in filtering out any input path provided to it - which would translate to a path <em>upwards</em> of the root folder value. The aim is that this class would be liberally used to delete files under the root path, but it would never touch anything upwards of the root path. </p>
  
  <p>This is similar to the broader <a href="https://www.owasp.org/index.php/Path_Traversal">path traversal attack</a>.</p>
  
  <p>Methods that are too restrictive (i.e. may result in false negatives) may be fine for my specific use case, if this simplifies things, and also, my current needs are for file system paths not web ones (although, a web module for the equivalent sake might theoretically work here).</p>