Class ForwardPathValidator
- java.lang.Object
-
- com.sun.identity.federation.common.ForwardPathValidator
-
public final class ForwardPathValidator extends Object
Sanity checks for request-derived values before they are handed to aRequestDispatcher. A forward is served from inside the web application: it can reach/WEB-INFand/META-INF, and it does not run the filters declared inweb.xml, so a path an end user controls must never be allowed to climb out of the location the code intends to dispatch to.The container processes a dispatcher path in a fixed order before it maps it (Tomcat
ApplicationContext.getRequestDispatcher, withdispatchersUseEncodedPathson by default): the query string is cut,;paramsare stripped from the raw string (each;up to the next raw/), the rest is percent-decoded once, and//and/./are collapsed. The checks here follow that order: traversal is refused in the raw form and again in the decoded form, and the reserved-directory check reads the stripped, decoded, collapsed path. An escape that decodes to a URL delimiter (%25,%3F,%23,%3B) or to something that is not UTF-8 is refused outright: no in-app path of the product carries one.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringforwardTarget(String path)The path to hand to aRequestDispatcherforpath, ornullwhenpathmust not be dispatched to.static booleanisSafeForwardPath(String path)Whetherpathmay be forwarded to as-is: absolute, without..segments in its raw or decoded form (path parameters stripped, as the container does), without backslashes, control characters, malformed or delimiter escapes, and not under a reserved directory once collapsed.static booleanisSafeMetaAlias(String metaAlias)WhethermetaAliascan be appended to a fixed handler path without changing which resource is dispatched to.
-
-
-
Method Detail
-
isSafeForwardPath
public static boolean isSafeForwardPath(String path)
Whetherpathmay be forwarded to as-is: absolute, without..segments in its raw or decoded form (path parameters stripped, as the container does), without backslashes, control characters, malformed or delimiter escapes, and not under a reserved directory once collapsed.- Parameters:
path- a context-relative path, optionally with a query string- Returns:
trueif the path is safe to pass to a request dispatcher
-
forwardTarget
public static String forwardTarget(String path)
The path to hand to aRequestDispatcherforpath, ornullwhenpathmust not be dispatched to. The result is the form the container maps - path parameters stripped and percent-escapes decoded once,+kept literal - with the query string as it was given.Beyond
isSafeForwardPath(java.lang.String)the dispatcher form is refused when it carries aWEB-INFsegment anywhere, not only at the root: no in-app path of the product does. The decoded form is derived and re-checked here in the shape static analysis recognises as a sanitised forward target, so the checks read as a repetition of whatisSafeForwardPathestablished.- Parameters:
path- a context-relative path, optionally with a query string- Returns:
- the path to dispatch to, or
nullif it is not a plain in-app path
-
isSafeMetaAlias
public static boolean isSafeMetaAlias(String metaAlias)
WhethermetaAliascan be appended to a fixed handler path without changing which resource is dispatched to.- Parameters:
metaAlias- the provider meta alias taken from the request- Returns:
trueif the alias contains no traversal
-
-