ppkarwasz commented on PR #552:
URL: https://github.com/apache/commons-io/pull/552#issuecomment-3383436374

   Hi @govind-gupta-tfs,
   
   Apache Commons IO already provides utilities to guard against path-traversal 
and invalid names:
   
   * 
[`FilenameUtils.getName(...)`](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FilenameUtils.html#getName%28java.lang.String%29):
 strips any path components from user input, preventing multiple segments 
(e.g., `../../evil.txt` → `evil.txt`).
   * 
[`FileSystem.isLegalFileName(...)`](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileSystem.html#isLegalFileName%28java.lang.CharSequence%29):
 lets you detect illegal characters and reserved file names for the current 
platform.
   * 
[`FileSystem.toLegalFileName(...)`](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileSystem.html#toLegalFileName%28java.lang.String,char%29):
 normalizes a user-supplied name to a safe form.
   
   One note: `toLegalFileName(...)` doesn’t currently replace Windows reserved 
device names (e.g., `CON`, `NUL`, `PRN`). If you think that would help here, 
we’d welcome a contribution adding that behavior.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to