Package com.atlassian.jira.util
Class PathUtils
java.lang.Object
com.atlassian.jira.util.PathUtils
This class contains utility methods for manipulating paths.
- Since:
- v4.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringappendFileSeparator(String filePath) static voidensurePathInSecureDir(String secureDir, String untrustedPath) Checks if usinguntrustedPathwould result in path traversal.static booleanisChildPath(File parentPath, File childPath) Checks if thechildPathis in fact a child path of the providedparentPath.static booleanisPathInSecureDir(File secureDir, File untrustedPath) Checks if usinguntrustedPathwould result in path traversal.static booleanisPathInSecureDir(String secureDir, String untrustedPath) Checks if usinguntrustedPathwould result in path traversal.static String
-
Method Details
-
appendFileSeparator
-
joinPaths
-
ensurePathInSecureDir
public static void ensurePathInSecureDir(String secureDir, String untrustedPath) throws PathTraversalException, IOException Checks if usinguntrustedPathwould result in path traversal. We consider that a path traversal occurs if the file or directory referred to inuntrustedPathis not contained insecureDir. This method uses the technique described in IDS02-J in the CERT Secure Coding Standard.Note that
secureDiris assumed to be secure, so this parameter must never contain user-supplied input.- Parameters:
secureDir- a String containing the path to a "secure" base directoryuntrustedPath- a String containing a path that was built using user-supplied input (relative or absolute)- Throws:
PathTraversalException- ifuntrustedPathis not belowsecureDirIOException- if there is an I/O problem callingjava.io.File.getCanonicalPath()
-
isPathInSecureDir
Checks if usinguntrustedPathwould result in path traversal. We consider that a path traversal occurs if the file or directory referred to inuntrustedPathis not contained insecureDir. This method uses the technique described in IDS02-J in the CERT Secure Coding Standard.Note that
secureDiris assumed to be secure, so this parameter must never contain user-supplied input.- Parameters:
secureDir- a String containing the path to a "secure" base directoryuntrustedPath- a String containing a path that was built using user-supplied input (relative or absolute)- Returns:
- a boolean indicating whether
untrustedPathinsecureDir - Throws:
IOException- if there is an I/O problem callingjava.io.File.getCanonicalPath()
-
isPathInSecureDir
Checks if usinguntrustedPathwould result in path traversal. We consider that a path traversal occurs if the file or directory referred to inuntrustedPathis not contained insecureDir. This method uses the technique described in IDS02-J in the CERT Secure Coding Standard.Note that
secureDiris assumed to be secure, so this parameter must never contain user-supplied input.- Parameters:
secureDir- a File representing the path to a "secure" base directoryuntrustedPath- a File representing a path that was built using user-supplied input (relative or absolute)- Returns:
- a boolean indicating whether
untrustedPathinsecureDir - Throws:
IOException- if there is an I/O problem callingjava.io.File.getCanonicalPath()
-
isChildPath
Checks if thechildPathis in fact a child path of the providedparentPath.- Parameters:
parentPath- a File representing the path to the parent directorychildPath- a File representing the path to the child directory- Returns:
- a boolean indicating whether
childPathis inparentPath - Throws:
IOException- if there is an I/O problem callingjava.io.File.getCanonicalPath()
-