Package org.apache.tomcat.util.http
Class RequestUtil
- java.lang.Object
-
- org.apache.tomcat.util.http.RequestUtil
-
public class RequestUtil extends java.lang.ObjectUtility methods for HTTP request processing.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisSameOrigin(HttpServletRequest request, java.lang.String origin)Check if the given origin matches the origin of the request.static booleanisValidOrigin(java.lang.String origin)Checks if a given origin is valid or not.static java.lang.Stringnormalize(java.lang.String path)Normalize a relative URI path.static java.lang.Stringnormalize(java.lang.String path, boolean replaceBackSlash)Normalize a relative URI path.
-
-
-
Method Detail
-
normalize
public static java.lang.String normalize(java.lang.String path)
Normalize a relative URI path. This method normalizes "/./", "/../", "//" and "\". If the input path is an attempt to 'escape the root' (e.g. /../input.txt) thennullis returned to prevent attempts to 'escape the root'. URI paths containing null bytes will be rejected.- Parameters:
path- Relative path to be normalized- Returns:
- The normalized path or
nullif the input path attempts to 'escape the root'.
-
normalize
public static java.lang.String normalize(java.lang.String path, boolean replaceBackSlash)Normalize a relative URI path. This method normalizes "/./", "/../" and "//". This method optionally normalizes "\". If the input path is an attempt to 'escape the root' (e.g. /../input.txt) thennullis returned to prevent attempts to 'escape the root'. URI paths containing null bytes will be rejected.- Parameters:
path- Relative path to be normalizedreplaceBackSlash- Should '\\' be normalized to '/'- Returns:
- The normalized path or
nullif the input path attempts to 'escape the root'.
-
isSameOrigin
public static boolean isSameOrigin(HttpServletRequest request, java.lang.String origin)
Check if the given origin matches the origin of the request.- Parameters:
request- The HTTP servlet requestorigin- The origin to check- Returns:
- True if the origin matches the request's origin
-
isValidOrigin
public static boolean isValidOrigin(java.lang.String origin)
Checks if a given origin is valid or not. Criteria:- If an encoded character is present in origin, it's not valid.
- If origin is "null", it's valid.
- Origin should be a valid
URI
- Parameters:
origin- The origin URI- Returns:
trueif the origin was valid- See Also:
- RFC952
-
-