Package org.owasp.esapi.filters
Class SecurityWrapperResponse
- java.lang.Object
-
- javax.servlet.ServletResponseWrapper
-
- javax.servlet.http.HttpServletResponseWrapper
-
- org.owasp.esapi.filters.SecurityWrapperResponse
-
- All Implemented Interfaces:
javax.servlet.http.HttpServletResponse,javax.servlet.ServletResponse
public class SecurityWrapperResponse extends javax.servlet.http.HttpServletResponseWrapper implements javax.servlet.http.HttpServletResponseThis response wrapper simply overrides unsafe methods in the HttpServletResponse API with safe versions.
-
-
Field Summary
-
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
-
-
Constructor Summary
Constructors Constructor Description SecurityWrapperResponse(javax.servlet.http.HttpServletResponse response)Construct a safe response that overrides the default response methods with safer versions.SecurityWrapperResponse(javax.servlet.http.HttpServletResponse response, java.lang.String mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCookie(javax.servlet.http.Cookie cookie)Add a cookie to the response after ensuring that there are no encoded or illegal characters in the name and name and value.voidaddDateHeader(java.lang.String name, long date)Add a cookie to the response after ensuring that there are no encoded or illegal characters in the name.voidaddHeader(java.lang.String name, java.lang.String value)Add a header to the response after ensuring that there are no encoded or illegal characters in the name and name and value.voidaddIntHeader(java.lang.String name, int value)Add an int header to the response after ensuring that there are no encoded or illegal characters in the name and name.booleancontainsHeader(java.lang.String name)Same as HttpServletResponse, no security changes required.java.lang.StringencodeRedirectUrl(java.lang.String url)Deprecated.in servlet spec 2.1.java.lang.StringencodeRedirectURL(java.lang.String url)Return the URL without any changes, to prevent disclosure of the Session ID The default implementation of this method can add the Session ID to the URL if support for cookies is not detected.java.lang.StringencodeUrl(java.lang.String url)Deprecated.in servlet spec 2.1.java.lang.StringencodeURL(java.lang.String url)Return the URL without any changes, to prevent disclosure of the Session ID The default implementation of this method can add the Session ID to the URL if support for cookies is not detected.voidflushBuffer()Same as HttpServletResponse, no security changes required.intgetBufferSize()Same as HttpServletResponse, no security changes required.java.lang.StringgetCharacterEncoding()Same as HttpServletResponse, no security changes required.java.lang.StringgetContentType()Same as HttpServletResponse, no security changes required.java.util.LocalegetLocale()Same as HttpServletResponse, no security changes required.javax.servlet.ServletOutputStreamgetOutputStream()Same as HttpServletResponse, no security changes required.java.io.PrintWritergetWriter()Same as HttpServletResponse, no security changes required.booleanisCommitted()Same as HttpServletResponse, no security changes required.voidreset()Same as HttpServletResponse, no security changes required.voidresetBuffer()Same as HttpServletResponse, no security changes required.voidsendError(int sc)Override the error code with a 200 in order to confound attackers using automated scanners.voidsendError(int sc, java.lang.String msg)Override the error code with a 200 in order to confound attackers using automated scanners.voidsendRedirect(java.lang.String location)This method generates a redirect response that can only be used to redirect the browser to safe locations, as configured in the ESAPI security configuration.voidsetBufferSize(int size)Same as HttpServletResponse, no security changes required.voidsetCharacterEncoding(java.lang.String charset)Sets the character encoding to the ESAPI configured encoding.voidsetContentLength(int len)Same as HttpServletResponse, no security changes required.voidsetContentType(java.lang.String type)Same as HttpServletResponse, no security changes required.voidsetDateHeader(java.lang.String name, long date)Add a date header to the response after ensuring that there are no encoded or illegal characters in the name.voidsetHeader(java.lang.String name, java.lang.String value)Add a header to the response after ensuring that there are no encoded or illegal characters in the name and value.voidsetIntHeader(java.lang.String name, int value)Add an int header to the response after ensuring that there are no encoded or illegal characters in the name.voidsetLocale(java.util.Locale loc)Same as HttpServletResponse, no security changes required.voidsetStatus(int sc)Override the status code with a 200 in order to confound attackers using automated scanners.voidsetStatus(int sc, java.lang.String sm)Deprecated.In Servlet spec 2.1.-
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
getHeader, getHeaderNames, getHeaders, getStatus, getTrailerFields, setTrailerFields
-
Methods inherited from class javax.servlet.ServletResponseWrapper
getResponse, isWrapperFor, isWrapperFor, setContentLengthLong, setResponse
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
SecurityWrapperResponse
public SecurityWrapperResponse(javax.servlet.http.HttpServletResponse response)
Construct a safe response that overrides the default response methods with safer versions.- Parameters:
response-
-
SecurityWrapperResponse
public SecurityWrapperResponse(javax.servlet.http.HttpServletResponse response, java.lang.String mode)- Parameters:
response-mode-
-
-
Method Detail
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the response after ensuring that there are no encoded or illegal characters in the name and name and value. This method also sets the secure and HttpOnly flags on the cookie. This implementation uses a custom "set-cookie" header instead of using Java's cookie interface which doesn't allow the use of HttpOnly.- Specified by:
addCookiein interfacejavax.servlet.http.HttpServletResponse- Overrides:
addCookiein classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
cookie-
-
addDateHeader
public void addDateHeader(java.lang.String name, long date)Add a cookie to the response after ensuring that there are no encoded or illegal characters in the name.- Specified by:
addDateHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
addDateHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-date-
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Add a header to the response after ensuring that there are no encoded or illegal characters in the name and name and value. This implementation follows the following recommendation: "A recipient MAY replace any linear white space with a single SP before interpreting the field value or forwarding the message downstream." http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2- Specified by:
addHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
addHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-value-
-
addIntHeader
public void addIntHeader(java.lang.String name, int value)Add an int header to the response after ensuring that there are no encoded or illegal characters in the name and name.- Specified by:
addIntHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
addIntHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-value-
-
containsHeader
public boolean containsHeader(java.lang.String name)
Same as HttpServletResponse, no security changes required.- Specified by:
containsHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
containsHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-- Returns:
-
encodeRedirectUrl
@Deprecated public java.lang.String encodeRedirectUrl(java.lang.String url)
Deprecated.in servlet spec 2.1. UseencodeRedirectUrl(String)instead.Return the URL without any changes, to prevent disclosure of the Session ID. The default implementation of this method can add the Session ID to the URL if support for cookies is not detected. This exposes the Session ID credential in bookmarks, referer headers, server logs, and more.- Specified by:
encodeRedirectUrlin interfacejavax.servlet.http.HttpServletResponse- Overrides:
encodeRedirectUrlin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
url-- Returns:
- original url
-
encodeRedirectURL
public java.lang.String encodeRedirectURL(java.lang.String url)
Return the URL without any changes, to prevent disclosure of the Session ID The default implementation of this method can add the Session ID to the URL if support for cookies is not detected. This exposes the Session ID credential in bookmarks, referer headers, server logs, and more.- Specified by:
encodeRedirectURLin interfacejavax.servlet.http.HttpServletResponse- Overrides:
encodeRedirectURLin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
url-- Returns:
- original url
-
encodeUrl
@Deprecated public java.lang.String encodeUrl(java.lang.String url)
Deprecated.in servlet spec 2.1. UseencodeURL(String)instead.Return the URL without any changes, to prevent disclosure of the Session ID The default implementation of this method can add the Session ID to the URL if support for cookies is not detected. This exposes the Session ID credential in bookmarks, referer headers, server logs, and more.- Specified by:
encodeUrlin interfacejavax.servlet.http.HttpServletResponse- Overrides:
encodeUrlin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
url-- Returns:
- original url
-
encodeURL
public java.lang.String encodeURL(java.lang.String url)
Return the URL without any changes, to prevent disclosure of the Session ID The default implementation of this method can add the Session ID to the URL if support for cookies is not detected. This exposes the Session ID credential in bookmarks, referer headers, server logs, and more.- Specified by:
encodeURLin interfacejavax.servlet.http.HttpServletResponse- Overrides:
encodeURLin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
url-- Returns:
- original url
-
flushBuffer
public void flushBuffer() throws java.io.IOExceptionSame as HttpServletResponse, no security changes required.- Specified by:
flushBufferin interfacejavax.servlet.ServletResponse- Overrides:
flushBufferin classjavax.servlet.ServletResponseWrapper- Throws:
java.io.IOException
-
getBufferSize
public int getBufferSize()
Same as HttpServletResponse, no security changes required.- Specified by:
getBufferSizein interfacejavax.servlet.ServletResponse- Overrides:
getBufferSizein classjavax.servlet.ServletResponseWrapper- Returns:
-
getCharacterEncoding
public java.lang.String getCharacterEncoding()
Same as HttpServletResponse, no security changes required.- Specified by:
getCharacterEncodingin interfacejavax.servlet.ServletResponse- Overrides:
getCharacterEncodingin classjavax.servlet.ServletResponseWrapper- Returns:
-
getContentType
public java.lang.String getContentType()
Same as HttpServletResponse, no security changes required.- Specified by:
getContentTypein interfacejavax.servlet.ServletResponse- Overrides:
getContentTypein classjavax.servlet.ServletResponseWrapper- Returns:
-
getLocale
public java.util.Locale getLocale()
Same as HttpServletResponse, no security changes required.- Specified by:
getLocalein interfacejavax.servlet.ServletResponse- Overrides:
getLocalein classjavax.servlet.ServletResponseWrapper- Returns:
-
getOutputStream
public javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOExceptionSame as HttpServletResponse, no security changes required.- Specified by:
getOutputStreamin interfacejavax.servlet.ServletResponse- Overrides:
getOutputStreamin classjavax.servlet.ServletResponseWrapper- Returns:
- Throws:
java.io.IOException
-
getWriter
public java.io.PrintWriter getWriter() throws java.io.IOExceptionSame as HttpServletResponse, no security changes required.- Specified by:
getWriterin interfacejavax.servlet.ServletResponse- Overrides:
getWriterin classjavax.servlet.ServletResponseWrapper- Returns:
- Throws:
java.io.IOException
-
isCommitted
public boolean isCommitted()
Same as HttpServletResponse, no security changes required.- Specified by:
isCommittedin interfacejavax.servlet.ServletResponse- Overrides:
isCommittedin classjavax.servlet.ServletResponseWrapper- Returns:
-
reset
public void reset()
Same as HttpServletResponse, no security changes required.- Specified by:
resetin interfacejavax.servlet.ServletResponse- Overrides:
resetin classjavax.servlet.ServletResponseWrapper
-
resetBuffer
public void resetBuffer()
Same as HttpServletResponse, no security changes required.- Specified by:
resetBufferin interfacejavax.servlet.ServletResponse- Overrides:
resetBufferin classjavax.servlet.ServletResponseWrapper
-
sendError
public void sendError(int sc) throws java.io.IOExceptionOverride the error code with a 200 in order to confound attackers using automated scanners.- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse- Overrides:
sendErrorin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
sc-- Throws:
java.io.IOException
-
sendError
public void sendError(int sc, java.lang.String msg) throws java.io.IOExceptionOverride the error code with a 200 in order to confound attackers using automated scanners. The message is canonicalized and filtered for dangerous characters.- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse- Overrides:
sendErrorin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
sc-msg-- Throws:
java.io.IOException
-
sendRedirect
public void sendRedirect(java.lang.String location) throws java.io.IOExceptionThis method generates a redirect response that can only be used to redirect the browser to safe locations, as configured in the ESAPI security configuration. This method does not that redirect requests can be modified by attackers, so do not rely information contained within redirect requests, and do not include sensitive information in a redirect.- Specified by:
sendRedirectin interfacejavax.servlet.http.HttpServletResponse- Overrides:
sendRedirectin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
location-- Throws:
java.io.IOException
-
setBufferSize
public void setBufferSize(int size)
Same as HttpServletResponse, no security changes required.- Specified by:
setBufferSizein interfacejavax.servlet.ServletResponse- Overrides:
setBufferSizein classjavax.servlet.ServletResponseWrapper- Parameters:
size-
-
setCharacterEncoding
public void setCharacterEncoding(java.lang.String charset)
Sets the character encoding to the ESAPI configured encoding.- Specified by:
setCharacterEncodingin interfacejavax.servlet.ServletResponse- Overrides:
setCharacterEncodingin classjavax.servlet.ServletResponseWrapper- Parameters:
charset-
-
setContentLength
public void setContentLength(int len)
Same as HttpServletResponse, no security changes required.- Specified by:
setContentLengthin interfacejavax.servlet.ServletResponse- Overrides:
setContentLengthin classjavax.servlet.ServletResponseWrapper- Parameters:
len-
-
setContentType
public void setContentType(java.lang.String type)
Same as HttpServletResponse, no security changes required.- Specified by:
setContentTypein interfacejavax.servlet.ServletResponse- Overrides:
setContentTypein classjavax.servlet.ServletResponseWrapper- Parameters:
type-
-
setDateHeader
public void setDateHeader(java.lang.String name, long date)Add a date header to the response after ensuring that there are no encoded or illegal characters in the name.- Specified by:
setDateHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
setDateHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-date-
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Add a header to the response after ensuring that there are no encoded or illegal characters in the name and value. "A recipient MAY replace any linear white space with a single SP before interpreting the field value or forwarding the message downstream." http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2- Specified by:
setHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
setHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-value-
-
setIntHeader
public void setIntHeader(java.lang.String name, int value)Add an int header to the response after ensuring that there are no encoded or illegal characters in the name.- Specified by:
setIntHeaderin interfacejavax.servlet.http.HttpServletResponse- Overrides:
setIntHeaderin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
name-value-
-
setLocale
public void setLocale(java.util.Locale loc)
Same as HttpServletResponse, no security changes required.- Specified by:
setLocalein interfacejavax.servlet.ServletResponse- Overrides:
setLocalein classjavax.servlet.ServletResponseWrapper- Parameters:
loc-
-
setStatus
public void setStatus(int sc)
Override the status code with a 200 in order to confound attackers using automated scanners.- Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse- Overrides:
setStatusin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
sc-
-
setStatus
@Deprecated public void setStatus(int sc, java.lang.String sm)Deprecated.In Servlet spec 2.1.Override the status code with a 200 in order to confound attackers using automated scanners. The message is canonicalized and filtered for dangerous characters.- Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse- Overrides:
setStatusin classjavax.servlet.http.HttpServletResponseWrapper- Parameters:
sc-sm-
-
-