Package org.apache.shiro.web.filter
Class InvalidRequestFilter
java.lang.Object
- All Implemented Interfaces:
javax.servlet.Filter,org.apache.shiro.lang.util.Nameable,PathConfigProcessor
A request filter that blocks malicious requests. Invalid request will respond with a 400 response code.
This filter checks and blocks the request if the following characters are found in the request URI:
- Semicolon - can be disabled by setting
blockSemicolon = false - Backslash - can be disabled by setting
blockBackslash = false - Non-ASCII characters - can be disabled by setting
blockNonAscii = false, the ability to disable this check will be removed in future version.
- Since:
- 1.6
- See Also:
-
Field Summary
Fields inherited from class org.apache.shiro.web.filter.AccessControlFilter
DEFAULT_LOGIN_URL, GET_METHOD, POST_METHODFields inherited from class org.apache.shiro.web.filter.PathMatchingFilter
appliedPaths, pathMatcherFields inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.apache.shiro.web.servlet.AbstractFilter
filterConfig -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanisAccessAllowed(javax.servlet.ServletRequest req, javax.servlet.ServletResponse response, Object mappedValue) Returnstrueif the request is allowed to proceed through the filter normally, orfalseif the request should be handled by theonAccessDenied(request,response,mappedValue)method instead.booleanbooleanbooleanprotected booleanonAccessDenied(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) Processes requests where the subject was denied access as determined by theisAccessAllowedmethod.voidsetBlockBackslash(boolean blockBackslash) voidsetBlockNonAscii(boolean blockNonAscii) voidsetBlockSemicolon(boolean blockSemicolon) Methods inherited from class org.apache.shiro.web.filter.AccessControlFilter
getLoginUrl, getSubject, isLoginRequest, onAccessDenied, onPreHandle, redirectToLogin, saveRequest, saveRequestAndRedirectToLogin, setLoginUrlMethods inherited from class org.apache.shiro.web.filter.PathMatchingFilter
getPathWithinApplication, isEnabled, pathsMatch, pathsMatch, preHandle, processPathConfigMethods inherited from class org.apache.shiro.web.servlet.AdviceFilter
afterCompletion, cleanup, doFilterInternal, executeChain, postHandleMethods inherited from class org.apache.shiro.web.servlet.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isEnabled, isEnabled, isFilterOncePerRequest, setEnabled, setFilterOncePerRequest, shouldNotFilterMethods inherited from class org.apache.shiro.web.servlet.NameableFilter
getName, setName, toStringBuilderMethods inherited from class org.apache.shiro.web.servlet.AbstractFilter
destroy, getFilterConfig, getInitParam, init, onFilterConfigSet, setFilterConfigMethods inherited from class org.apache.shiro.web.servlet.ServletContextSupport
getContextAttribute, getContextInitParam, getServletContext, removeContextAttribute, setContextAttribute, setServletContext, toString
-
Constructor Details
-
InvalidRequestFilter
public InvalidRequestFilter()
-
-
Method Details
-
isAccessAllowed
protected boolean isAccessAllowed(javax.servlet.ServletRequest req, javax.servlet.ServletResponse response, Object mappedValue) throws Exception Description copied from class:AccessControlFilterReturnstrueif the request is allowed to proceed through the filter normally, orfalseif the request should be handled by theonAccessDenied(request,response,mappedValue)method instead.- Specified by:
isAccessAllowedin classAccessControlFilter- Parameters:
req- the incomingServletRequestresponse- the outgoingServletResponsemappedValue- the filter-specific config value mapped to this filter in the URL rules mappings.- Returns:
trueif the request should proceed through the filter normally,falseif the request should be processed by this filter'sAccessControlFilter.onAccessDenied(ServletRequest,ServletResponse,Object)method instead.- Throws:
Exception- if an error occurs during processing.
-
onAccessDenied
protected boolean onAccessDenied(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws Exception Description copied from class:AccessControlFilterProcesses requests where the subject was denied access as determined by theisAccessAllowedmethod.- Specified by:
onAccessDeniedin classAccessControlFilter- Parameters:
request- the incomingServletRequestresponse- the outgoingServletResponse- Returns:
trueif the request should continue to be processed; false if the subclass will handle/render the response directly.- Throws:
Exception- if there is an error processing the request.
-
isBlockSemicolon
public boolean isBlockSemicolon() -
setBlockSemicolon
public void setBlockSemicolon(boolean blockSemicolon) -
isBlockBackslash
public boolean isBlockBackslash() -
setBlockBackslash
public void setBlockBackslash(boolean blockBackslash) -
isBlockNonAscii
public boolean isBlockNonAscii() -
setBlockNonAscii
public void setBlockNonAscii(boolean blockNonAscii)
-