Class XSSFilter
- java.lang.Object
-
- de.hybris.platform.servicelayer.web.XSSFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class XSSFilter extends java.lang.Object implements javax.servlet.FilterFilter that wraps requests to XSSRequestWrapper to sanitize inputs for XSS.Utilizes
HttpServletRequestWrapperthat sanitize requests inputs to mitigate risks of XSS scripts being passed over. This code is based on free and non-restricted code found at: http://ricardozuasti.com/2012/stronger-anti-cross-site-scripting-xss-filter-for-java-web-apps/
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceXSSFilter.XSSFilterConfigInterface to inject configuration parameters intoXSSFilterwithout exposing the actual implementation of how these parameters are obtained.static interfaceXSSFilter.XSSValueTranslatorInterface to encapsulate the actual processing of parameter and header values.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONFIG_ACTIONstatic java.lang.StringCONFIG_ENABLEDprotected static java.lang.StringCONFIG_HEADER_PREFIXstatic java.lang.StringCONFIG_HEADER_PREFIX_REGEXPstatic java.lang.StringCONFIG_PARAM_PREFIXstatic java.lang.StringCONFIG_RULE_PREFIX_REGEXPstatic java.lang.StringCONFIG_SORTstatic java.lang.StringHOST_HEADER_WHITE_LIST_PREFIXprotected static org.apache.log4j.LoggerLOGprotected static java.lang.StringREJECTED_REQUEST_RESP_CONTENT
-
Constructor Summary
Constructors Constructor Description XSSFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<java.util.regex.Pattern>compilePatterns(java.util.Map<java.lang.String,java.lang.String> rules)voiddestroy()voiddoFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)protected java.lang.StringgetSetupInfo()voidinit(javax.servlet.FilterConfig filterConfig)protected voidinitFromConfig(XSSFilter.XSSFilterConfig config)protected voidinitPatternsAndHeaders(boolean enabled, java.util.Map<java.lang.String,java.lang.String> patternDefinitions, java.util.Map<java.lang.String,java.lang.String> headers)protected voidprocessPatternsAndDoFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)voidreloadOnConfigChange()protected voidsetRejectResponseCodes(javax.servlet.http.HttpServletResponse httpResponse)
-
-
-
Field Detail
-
LOG
protected static org.apache.log4j.Logger LOG
-
CONFIG_PARAM_PREFIX
public static final java.lang.String CONFIG_PARAM_PREFIX
- See Also:
- Constant Field Values
-
CONFIG_RULE_PREFIX_REGEXP
public static final java.lang.String CONFIG_RULE_PREFIX_REGEXP
- See Also:
- Constant Field Values
-
CONFIG_HEADER_PREFIX_REGEXP
public static final java.lang.String CONFIG_HEADER_PREFIX_REGEXP
- See Also:
- Constant Field Values
-
CONFIG_HEADER_PREFIX
protected static final java.lang.String CONFIG_HEADER_PREFIX
- See Also:
- Constant Field Values
-
CONFIG_ENABLED
public static final java.lang.String CONFIG_ENABLED
- See Also:
- Constant Field Values
-
CONFIG_SORT
public static final java.lang.String CONFIG_SORT
- See Also:
- Constant Field Values
-
CONFIG_ACTION
public static final java.lang.String CONFIG_ACTION
- See Also:
- Constant Field Values
-
HOST_HEADER_WHITE_LIST_PREFIX
public static final java.lang.String HOST_HEADER_WHITE_LIST_PREFIX
- See Also:
- Constant Field Values
-
REJECTED_REQUEST_RESP_CONTENT
protected static final java.lang.String REJECTED_REQUEST_RESP_CONTENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
initFromConfig
protected void initFromConfig(XSSFilter.XSSFilterConfig config)
-
initPatternsAndHeaders
protected void initPatternsAndHeaders(boolean enabled, java.util.Map<java.lang.String,java.lang.String> patternDefinitions, java.util.Map<java.lang.String,java.lang.String> headers)
-
reloadOnConfigChange
public void reloadOnConfigChange()
-
compilePatterns
protected java.util.List<java.util.regex.Pattern> compilePatterns(java.util.Map<java.lang.String,java.lang.String> rules)
-
getSetupInfo
protected java.lang.String getSetupInfo()
-
doFilter
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
processPatternsAndDoFilter
protected void processPatternsAndDoFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws java.io.IOException, javax.servlet.ServletException- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
setRejectResponseCodes
protected void setRejectResponseCodes(javax.servlet.http.HttpServletResponse httpResponse) throws java.io.IOException- Throws:
java.io.IOException
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
-