|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
The HTTPUtilities interface is a collection of methods that provide additional security related to HTTP requests, responses, sessions, cookies, headers, and logging.
| Field Summary | |
static java.lang.String |
REMEMBER_TOKEN_COOKIE_NAME
Key for remember token cookie |
| Method Summary | |
java.lang.String |
addCSRFToken(java.lang.String href)
Adds the current user's CSRF token (see User.getCSRFToken()) to the URL for purposes of preventing CSRF attacks. |
void |
assertSecureRequest()
Ensures that the current request uses SSL and POST to protect any sensitive parameters in the querystring from being sniffed or logged. |
javax.servlet.http.HttpSession |
changeSessionIdentifier()
Invalidate the old session after copying all of its contents to a newly created session with a new session id. |
java.lang.String |
decryptHiddenField(java.lang.String encrypted)
Decrypts an encrypted hidden field value and returns the cleartext. |
java.util.Map |
decryptQueryString(java.lang.String encrypted)
Takes an encrypted querystring and returns a Map containing the original parameters. |
java.util.Map |
decryptStateFromCookie()
Retrieves a map of data from a cookie encrypted with encryptStateInCookie(). |
java.lang.String |
encryptHiddenField(java.lang.String value)
Encrypts a hidden field value for use in HTML. |
java.lang.String |
encryptQueryString(java.lang.String query)
Takes a querystring (i.e. |
void |
encryptStateInCookie(java.util.Map cleartext)
Stores a Map of data in an encrypted cookie. |
java.lang.String |
getCookie(java.lang.String name)
Returns the first cookie matching the given name. |
java.lang.String |
getCSRFToken()
Returns the current user's CSRF token. |
javax.servlet.http.HttpServletRequest |
getCurrentRequest()
Retrieves the current HttpServletRequest |
javax.servlet.http.HttpServletResponse |
getCurrentResponse()
Retrieves the current HttpServletResponse |
java.util.List |
getSafeFileUploads(java.io.File tempDir,
java.io.File finalDir)
Extract uploaded files from a multipart HTTP requests. |
void |
killAllCookies()
Kill all cookies received in the last request from the browser. |
void |
killCookie(java.lang.String name)
Kills the specified cookie by setting a new cookie that expires immediately. |
void |
logHTTPRequest(Logger logger)
Format the Source IP address, URL, URL parameters, and all form parameters into a string suitable for the log file. |
void |
logHTTPRequest(Logger logger,
java.util.List parameterNamesToObfuscate)
Format the Source IP address, URL, URL parameters, and all form parameters into a string suitable for the log file. |
void |
safeAddCookie(java.lang.String name,
java.lang.String value,
int maxAge,
java.lang.String domain,
java.lang.String path)
Adds a cookie to the specified HttpServletResponse and adds the Http-Only flag. |
void |
safeAddHeader(java.lang.String name,
java.lang.String value)
Adds a header to an HttpServletResponse after checking for special characters (such as CRLF injection) that could enable attacks like response splitting and other header-based attacks that nobody has thought of yet. |
void |
safeSendForward(java.lang.String context,
java.lang.String location)
This method perform a forward to any resource located inside the WEB-INF directory. |
void |
safeSendRedirect(java.lang.String context,
java.lang.String location)
This method generates a redirect response that can only be used to redirect the browser to safe locations. |
void |
safeSetContentType()
Sets the content type on each HTTP response, to help protect against cross-site scripting attacks and other types of injection into HTML documents. |
void |
safeSetHeader(java.lang.String name,
java.lang.String value)
Sets a header in an HttpServletResponse after checking for special characters (such as CRLF injection) that could enable attacks like response splitting and other header-based attacks that nobody has thought of yet. |
void |
setCurrentHTTP(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Stores the current HttpRequest and HttpResponse so that they may be readily accessed throughout ESAPI (and elsewhere) |
void |
setNoCacheHeaders()
Set headers to protect sensitive information against being cached in the browser. |
java.lang.String |
setRememberToken(java.lang.String password,
int maxAge,
java.lang.String domain,
java.lang.String path)
Set a cookie containing the current User's remember me token for automatic authentication. |
void |
verifyCSRFToken()
Checks the CSRF token in the URL (see User.getCSRFToken()) against the user's CSRF token and throws an IntrusionException if it is missing. |
| Field Detail |
public static final java.lang.String REMEMBER_TOKEN_COOKIE_NAME
| Method Detail |
public void assertSecureRequest()
throws AccessControlException
getCurrentRequest() to obtain the current HttpServletRequest object
AccessControlExceptionpublic java.lang.String addCSRFToken(java.lang.String href)
href -
public java.lang.String getCSRFToken()
public void safeAddCookie(java.lang.String name,
java.lang.String value,
int maxAge,
java.lang.String domain,
java.lang.String path)
getCurrentResponse() to obtain the current HttpServletResponse object
name - the cookie namevalue - the cookie valuedomain - the domain to restrict the cookie to, or nullpath - the path to restrict the cookie to, or nullmaxAge - the max age in relative seconds that the cookie should be valid for
public void safeAddHeader(java.lang.String name,
java.lang.String value)
throws ValidationException
getCurrentResponse() to obtain the current HttpServletResponse object
name - the namevalue - the value
ValidationException
public void safeSetHeader(java.lang.String name,
java.lang.String value)
throws ValidationException
getCurrentResponse() to obtain the current HttpServletResponse object
name - the namevalue - the value
ValidationException
public javax.servlet.http.HttpSession changeSessionIdentifier()
throws AuthenticationException
getCurrentRequest() to obtain the current HttpSession object
EnterpriseSecurityException - the enterprise security exception
AuthenticationException
public void verifyCSRFToken()
throws IntrusionException
getCurrentRequest() to obtain the current url
IntrusionExceptionpublic java.lang.String decryptHiddenField(java.lang.String encrypted)
Encryptor.decrypt(String) ?
public java.lang.String setRememberToken(java.lang.String password,
int maxAge,
java.lang.String domain,
java.lang.String path)
password - the user's passwordmaxAge - the length of time that the token should be valid for in relative secondsdomain - the domain to restrict the token to or nullpath - the path to restrict the token to or null
public java.lang.String encryptHiddenField(java.lang.String value)
throws EncryptionException
value - the cleartext value
EncryptionException - FIXME RD: What value does this offer over Encryptor.encrypt(String) ?
public java.lang.String encryptQueryString(java.lang.String query)
throws EncryptionException
Encryptor.encrypt(String) ?
EncryptionException
public java.util.Map decryptQueryString(java.lang.String encrypted)
throws EncryptionException
encrypted -
Encryptor.decrypt(String) ?
FIXME RD: Is it really valid to return a Map, if the parameter names can be duplicated? e.g. ?a=1&a=2
EncryptionExceptionpublic java.lang.String getCookie(java.lang.String name)
getCurrentRequest() to obtain the HttpServletRequest object
public java.util.List getSafeFileUploads(java.io.File tempDir,
java.io.File finalDir)
throws ValidationException
getCurrentRequest() to obtain the HttpServletRequest object
tempDir - the temp dirfinalDir - the final dir
ValidationException - the validation exception
public java.util.Map decryptStateFromCookie()
throws EncryptionException
HTTPUtilities#getCurrentResquest() to obtain the HttpServletRequest object
FIXME RD: More information needed about why this may be useful
EncryptionExceptionpublic void killAllCookies()
getCurrentRequest() to obtain the HttpServletRequest object
This method uses getCurrentResponse() to obtain the HttpServletRequest object
public void killCookie(java.lang.String name)
getCurrentResponse() to obtain the HttpServletResponse object
name - the cookie name
public void encryptStateInCookie(java.util.Map cleartext)
throws EncryptionException
getCurrentResponse() to obtain the HttpServletResponse object
EncryptionException
public void safeSendRedirect(java.lang.String context,
java.lang.String location)
throws java.io.IOException
getCurrentResponse() to obtain the HttpServletResponse object
context - location - the URL to redirect to
java.io.IOException - Signals that an I/O exception has occurred.
public void safeSendForward(java.lang.String context,
java.lang.String location)
throws AccessControlException,
javax.servlet.ServletException,
java.io.IOException
getCurrentResponse() to obtain the HttpServletResponse object
context - location -
AccessControlException
javax.servlet.ServletException
java.io.IOExceptionpublic void safeSetContentType()
getCurrentResponse() to obtain the HttpServletResponse object
public void setNoCacheHeaders()
Cache-Control: no-storeNote that the header "pragma: no-cache" is only useful in HTTP requests, not HTTP responses. So even though there are many articles recommending the use of this header, it is not helpful for preventing browser caching. For more information, please refer to the relevant standards:
Cache-Control: no-cache
Cache-Control: must-revalidate
Expires: -1
getCurrentResponse() to obtain the HttpServletResponse object
public void setCurrentHTTP(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
request - the current requestresponse - the current responsepublic javax.servlet.http.HttpServletRequest getCurrentRequest()
public javax.servlet.http.HttpServletResponse getCurrentResponse()
public void logHTTPRequest(Logger logger)
getCurrentRequest() to obtain the HttpServletRequest object
logger - the logger to write the request to
public void logHTTPRequest(Logger logger,
java.util.List parameterNamesToObfuscate)
getCurrentResponse() to obtain the HttpServletResponse object
logger - the logger to write the request toparameterNamesToObfuscate - the sensitive params
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||