Class SecurityUtils
java.lang.Object
com.amazonaws.serverless.proxy.internal.SecurityUtils
This class contains utility methods to address FSB security issues found in the application, such as string sanitization
and file path validation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplaces CRLF characters in a string with empty string ("").static StringEscapes all special characters in a java stringstatic StringgetValidFilePath(String inputPath) static StringgetValidFilePath(String inputPath, boolean isWrite) Returns an absolute file path given an input path and validates that it is not trying to write/read from a directory other than /tmp.static booleanisValidHost(String host, String apiId, AlbContext elb, String region) static booleanisValidPort(String port) static booleanisValidScheme(String scheme)
-
Constructor Details
-
SecurityUtils
public SecurityUtils()
-
-
Method Details
-
isValidPort
-
isValidScheme
-
isValidHost
-
crlf
Replaces CRLF characters in a string with empty string ("").- Parameters:
s- The string to be cleaned- Returns:
- A copy of the original string without CRLF characters
-
encode
Escapes all special characters in a java string- Parameters:
s- The string to be cleaned- Returns:
- The escaped string
-
getValidFilePath
-
getValidFilePath
Returns an absolute file path given an input path and validates that it is not trying to write/read from a directory other than /tmp. We suppress the path traversal warnings because this method is used to validate paths passed to the servlet implementation methods such asAwsProxyRequestPart.write(String). Using relative paths is a valid use-case for developers implementing a servlet-based API. We mitigate the potential partial path traversal by checking the resulting absolute path against the list of allowed paths specified inContainerConfig.getValidFilePaths(). We also block the /var/task directory regardless.- Parameters:
inputPath- The input path- Returns:
- The absolute path to the file
- Throws:
IllegalArgumentException- If the given path is not valid or outside of /tmp
-