Package de.wwu.scdh.saxon.harden
Class FilesystemFilter
- java.lang.Object
-
- de.wwu.scdh.saxon.harden.FilesystemFilter
-
public class FilesystemFilter extends Object
A filter that restricts access to the file system to a specific paths given by configuration. Requests to URI schemes other thanfile
will pass the check. URIs without a specified scheme will be treated as in the file scheme.
-
-
Constructor Summary
Constructors Constructor Description FilesystemFilter()
The standard constructor sets no allowed locations at all.FilesystemFilter(String[] allowedLocations)
Make a newFilesystemFilter
from an array of file system paths.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check(String href, String base)
This checks if the givenhref
points to an allowed file system location or is a non-file URI.boolean
check(URI absolute)
Check if the given absoluteURI
is allowed.static FilesystemFilter
fromPropertiesOrEnvironment()
This static method returns aFilesystemFilter
and sets its allowed locations from a system property or an environment variable, which define a list of paths.String[]
getAllowedLocations()
Returns the allowed locations.protected static String[]
getPropOrEnv()
Get an array of paths from a system property or environment variable.protected static void
notifyEmpty()
Notify users that no allowed paths are configured.
-
-
-
Field Detail
-
SEPARATOR
public static final String SEPARATOR
- See Also:
- Constant Field Values
-
PROPERTY
public static final String PROPERTY
-
ENVIRON
public static final String ENVIRON
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FilesystemFilter
public FilesystemFilter()
The standard constructor sets no allowed locations at all.
-
FilesystemFilter
public FilesystemFilter(String[] allowedLocations) throws FilesystemFilterException
Make a newFilesystemFilter
from an array of file system paths. The paths should follow the OS-specific form, e.g.c:\\users\\
on Windows or
~/projects/xsl
on *nix. Paths are converted to healty URIs internally. Relative paths are converted to absolute paths.~
can be used to point to the user's home directory.- Parameters:
allowedLocations
- locations (paths) on the file system allowed for read and write access- Throws:
FilesystemFilterException
-
-
Method Detail
-
fromPropertiesOrEnvironment
public static FilesystemFilter fromPropertiesOrEnvironment()
This static method returns aFilesystemFilter
and sets its allowed locations from a system property or an environment variable, which define a list of paths. The name of the system property isFileSystemFilter.PROPERTY
. The name of the environment variable isFilesystemFilter.ENVIRON
. Paths are separated byFilesystemFilter.SEPARATOR
.Configuration errors result in an empty set of allowed paths, but will be notified on stderr.
~
can be used to point to the user's home directory.
-
getPropOrEnv
protected static String[] getPropOrEnv()
Get an array of paths from a system property or environment variable.
-
notifyEmpty
protected static void notifyEmpty()
Notify users that no allowed paths are configured.
-
getAllowedLocations
public String[] getAllowedLocations()
Returns the allowed locations.
-
check
public boolean check(URI absolute)
Check if the given absoluteURI
is allowed. URIs in the file system scheme will pass the check if the file is under one of the allowed paths. All relative file URIs will fail. If there is no scheme given for the URI, then it is treated as a file URI. All other URIs will pass the check.- Parameters:
absolute
-URI
to check- Returns:
- false if and only if a file URI pointing outside of allowed locations
-
check
public boolean check(String href, String base)
This checks if the givenhref
points to an allowed file system location or is a non-file URI. A relative reference is first resolved against the URI given in the second parameter.- Parameters:
href
- the reference to be checkedbase
- the base URI to be used to resolve a relative href- Returns:
- false if and only if a file URI pointing outside of allowed locations
-
-