Package fr.gouv.vitam.common.security

# Class SafeFileChecker

java.lang.Object
fr.gouv.vitam.common.security.SafeFileChecker

public class SafeFileChecker extends Object
Checker for Sanity of file manipulation to avoid Path Traversal vulnerability

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Pattern`
  `FILENAME_PATTERN`
  `static final String`
  `LOCAL_ENVIRONMENT`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static File`
  `checkSafeDirPath(String safeRootPath, String... subPaths)`
  Directory path sanity checker.
  `static File`
  `checkSafeFilePath(String safeRootPath, String... subPaths)`
  File path sanity checker.
  `static void`
  `checkSafeRessourceFilePath(String resourceName)`
  Path sanity for class-path resources Checks filename authorized patterns, path traversal attacks invalid input: '&' ESAPI sanity checks

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### FILENAME_PATTERN

    public static final Pattern FILENAME_PATTERN

  - ### LOCAL_ENVIRONMENT

    public static final String LOCAL_ENVIRONMENT
    See Also:
      - Constant Field Values

- ## Method Details

  - ### checkSafeFilePath

    public static File checkSafeFilePath(String safeRootPath, String... subPaths) throws IllegalPathException
    File path sanity checker. Checks folder invalid input: '&' filename authorized patterns, path traversal attacks invalid input: '&' ESAPI sanity checks
    Parameters:
      `safeRootPath` - first or initial part(s) of a path representing a FileSystem resource
      `subPaths` - sub path parts. Every part should be a single folder level, except last part which is the actual filename.
    Returns:
      the resolved `File`
    Throws:
      `IllegalPathException` - thrown when any check fails with UnChecked or Runtime exception

  - ### checkSafeDirPath

    public static File checkSafeDirPath(String safeRootPath, String... subPaths) throws IllegalPathException
    Directory path sanity checker. Checks folder authorized patterns, path traversal attacks invalid input: '&' ESAPI sanity checks
    Parameters:
      `safeRootPath` - first or initial part(s) of a path representing a FileSystem resource
      `subPaths` - sub path parts. Every part should be a single folder level.
    Returns:
      the resolved directory `File`
    Throws:
      `IllegalPathException` - thrown when any check fails with UnChecked or Runtime exception

  - ### checkSafeRessourceFilePath

    public static void checkSafeRessourceFilePath(String resourceName) throws IllegalPathException
    Path sanity for class-path resources Checks filename authorized patterns, path traversal attacks invalid input: '&' ESAPI sanity checks
    Parameters:
      `resourceName` - the resource file name to check
    Throws:
      `IllegalPathException` - thrown when any check fails with UnChecked or Runtime exception