java.lang.Object
javax.servlet.ServletRequestWrapper
javax.servlet.http.HttpServletRequestWrapper
net.i2p.servlet.filters.XSSRequestWrapper
- All Implemented Interfaces:
HttpServletRequest, ServletRequest
Request wrapper to prevent XSS attacks.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternWhitelist for header values, ASCII letters and common punctuation.private static final StringParameter prefix marking a value to pass through unfiltered.private static final StringWhitelist of characters allowed in a parameter value, adapted from the OWASP ESAPI validation patterns.private static final PatternCompiled whitelist for parameter values.private static final StringAs above, with backslash added for Windows paths.Fields inherited from interface HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTHConstructor Summary
ConstructorsConstructorDescriptionXSSRequestWrapper(HttpServletRequest servletRequest) Wraps a request so its parameters and headers are filtered of XSS payloads.Method Summary
Modifier and TypeMethodDescriptionHeader with XSS patterns stripped.getParameter(String parameter) Parameter names starting with "nofilter_" will not be filtered.Parameter names starting with "nofilter_" will not be filtered.String[]getParameterValues(String parameter) Parameter names starting with "nofilter_" will not be filtered.private static StringRemoves cross-site scripting constructs from a value.Methods inherited from class HttpServletRequestWrapper
authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgradeMethods inherited from class ServletRequestWrapper
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameterNames, getProtocol, getReader, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync
Field Details
NON_WIN_PATTERN
Whitelist of characters allowed in a parameter value, adapted from the OWASP ESAPI validation patterns. See also: ESAPI.properties- See Also:
WIN_PATTERN
As above, with backslash added for Windows paths.- See Also:
parameterValuePattern
Compiled whitelist for parameter values.headerValuePattern
Whitelist for header values, ASCII letters and common punctuation.NOFILTER
Parameter prefix marking a value to pass through unfiltered.- See Also:
Constructor Details
XSSRequestWrapper
Wraps a request so its parameters and headers are filtered of XSS payloads.- Parameters:
servletRequest- the request being wrapped, whose parameters and headers are filtered
Method Details
getParameterValues
Parameter names starting with "nofilter_" will not be filtered.- Specified by:
getParameterValuesin interfaceServletRequest- Overrides:
getParameterValuesin classServletRequestWrapper- Returns:
- the parameter values
getParameter
Parameter names starting with "nofilter_" will not be filtered.- Specified by:
getParameterin interfaceServletRequest- Overrides:
getParameterin classServletRequestWrapper- Returns:
- the value submitted for this parameter once it has been checked against the whitelist, or null if the parameter is absent or its value did not match and was dropped
getParameterMap
Parameter names starting with "nofilter_" will not be filtered.- Specified by:
getParameterMapin interfaceServletRequest- Overrides:
getParameterMapin classServletRequestWrapper- Returns:
- the parameter map
getHeader
Header with XSS patterns stripped.- Specified by:
getHeaderin interfaceHttpServletRequest- Overrides:
getHeaderin classHttpServletRequestWrapper- Returns:
- the value of the named header once it has been checked against the whitelist, or null if the header is absent or its value did not match and was dropped
stripXSS