|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.HTTPUtilities
Reference implementation of the IHTTPUtilities interface. This implementation uses the Apache Commons FileUploader library, which in turn uses the Apache Commons IO library.
To simplify the interface, this class uses the current request and response that are tracked by ThreadLocal variables in the Authenticator. This means that you must have called ESAPI.authenticator().setCurrentHTTP(null, response) before calling these methods. This is done automatically by the Authenticator.login() method.
IHTTPUtilities| Constructor Summary | |
HTTPUtilities()
|
|
| 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. |
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 cleartest. |
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 the encrypted cookie. |
void |
enableRememberToken(int maxAge,
java.lang.String domain,
java.lang.String path)
Save the user's remember me token in a cookie. |
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)
Utility method to get a cookie from the current request. |
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)
Uses the Apache Commons FileUploader to parse the multipart HTTP request and extract any files therein. |
boolean |
isSecureChannel()
Returns true if the request was transmitted over an SSL enabled connection. |
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(ILogger logger)
Format the Source IP address, URL, URL parameters, and all form parameters into a string suitable for the log file. |
void |
logHTTPRequest(ILogger logger,
java.util.List parameterNamesToObfuscate)
Formats an HTTP request into a log suitable string. |
void |
safeAddCookie(javax.servlet.http.Cookie cookie)
|
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 HttpServletResponse that uses Secure and HttpOnly flags. |
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. |
java.lang.String |
safeEncodeRedirectUrl(java.lang.String url)
Deprecated. |
java.lang.String |
safeEncodeRedirectURL(java.lang.String url)
Return exactly what was sent to prevent URL rewriting. |
java.lang.String |
safeEncodeUrl(java.lang.String url)
Deprecated. |
java.lang.String |
safeEncodeURL(java.lang.String url)
Return exactly what was sent to prevent URL rewriting. |
void |
safeSendError(int sc)
|
void |
safeSendError(int sc,
java.lang.String msg)
|
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 |
safeSetCharacterEncodingInRequest(java.lang.String env)
|
void |
safeSetCharacterEncodingInResponse(java.lang.String charset)
|
void |
safeSetContentType()
Set the character encoding on every HttpServletResponse in order to limit the ways in which the input data can be represented. |
void |
safeSetDateHeader(java.lang.String name,
long date)
|
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 |
safeSetIntHeader(java.lang.String name,
int value)
|
void |
safeSetLocale(java.util.Locale loc)
|
void |
safeSetStatus(int sc)
|
void |
safeSetStatus(int sc,
java.lang.String sm)
|
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. |
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. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public HTTPUtilities()
| Method Detail |
public java.lang.String addCSRFToken(java.lang.String href)
IHTTPUtilities
addCSRFToken in interface IHTTPUtilitiesIHTTPUtilities.addCSRFToken(java.lang.String)
public void enableRememberToken(int maxAge,
java.lang.String domain,
java.lang.String path)
enableRememberToken in interface IHTTPUtilitiesmaxAge - domain - path -
public void safeAddCookie(java.lang.String name,
java.lang.String value,
int maxAge,
java.lang.String domain,
java.lang.String path)
safeAddCookie in interface IHTTPUtilitiesmaxAge - number of seconds until cookie expiresname - the namevalue - the valuedomain - the domainpath - the pathorg.owasp.esapi.interfaces.IHTTPUtilities#safeAddCookie(java.lang.String,
java.lang.String, java.util.Date, java.lang.String,
java.lang.String, javax.servlet.http.HttpServletResponse)
public void safeAddHeader(java.lang.String name,
java.lang.String value)
IHTTPUtilities
safeAddHeader in interface IHTTPUtilitiesname - the namevalue - the value
public void safeSendError(int sc)
throws java.io.IOException
java.io.IOException
public void safeSendError(int sc,
java.lang.String msg)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getCookie(java.lang.String name)
getCookie in interface IHTTPUtilities
public void safeSetDateHeader(java.lang.String name,
long date)
public void safeSetIntHeader(java.lang.String name,
int value)
public void safeSetCharacterEncodingInResponse(java.lang.String charset)
public void safeAddCookie(javax.servlet.http.Cookie cookie)
public void safeSetLocale(java.util.Locale loc)
public void safeSetStatus(int sc)
public void safeSetStatus(int sc,
java.lang.String sm)
public void safeSetCharacterEncodingInRequest(java.lang.String env)
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public void safeSetHeader(java.lang.String name,
java.lang.String value)
throws ValidationException
IHTTPUtilities
safeSetHeader in interface IHTTPUtilitiesname - the namevalue - the value
ValidationExceptionpublic java.lang.String safeEncodeURL(java.lang.String url)
url -
public java.lang.String safeEncodeUrl(java.lang.String url)
public java.lang.String safeEncodeRedirectURL(java.lang.String url)
url -
public java.lang.String safeEncodeRedirectUrl(java.lang.String url)
public javax.servlet.http.HttpSession changeSessionIdentifier()
throws AuthenticationException
IHTTPUtilities
changeSessionIdentifier in interface IHTTPUtilitiesAuthenticationException
public void verifyCSRFToken()
throws IntrusionException
IHTTPUtilities
verifyCSRFToken in interface IHTTPUtilitiesIntrusionExceptionpublic java.lang.String decryptHiddenField(java.lang.String encrypted)
IHTTPUtilities
decryptHiddenField in interface IHTTPUtilitiesencrypted -
public java.util.Map decryptQueryString(java.lang.String encrypted)
throws EncryptionException
IHTTPUtilities
decryptQueryString in interface IHTTPUtilitiesencrypted -
EncryptionException
public java.util.Map decryptStateFromCookie()
throws EncryptionException
IHTTPUtilities
decryptStateFromCookie in interface IHTTPUtilitiesEncryptionExceptionIHTTPUtilities.decryptStateFromCookie()
public java.lang.String encryptHiddenField(java.lang.String value)
throws EncryptionException
IHTTPUtilities
encryptHiddenField in interface IHTTPUtilitiesvalue -
EncryptionException
public java.lang.String encryptQueryString(java.lang.String query)
throws EncryptionException
IHTTPUtilities
encryptQueryString in interface IHTTPUtilitiesEncryptionException
public void encryptStateInCookie(java.util.Map cleartext)
throws EncryptionException
IHTTPUtilities
encryptStateInCookie in interface IHTTPUtilitiesEncryptionExceptionIHTTPUtilities.encryptStateInCookie(java.util.Map)
public java.util.List getSafeFileUploads(java.io.File tempDir,
java.io.File finalDir)
throws ValidationException
getSafeFileUploads in interface IHTTPUtilitiestempDir - the temp dirfinalDir - the final dir
ValidationException - the validation exceptionorg.owasp.esapi.interfaces.IHTTPUtilities#safeGetFileUploads(javax.servlet.http.HttpServletRequest,
java.io.File, java.io.File, int)public boolean isSecureChannel()
isSecureChannel in interface IHTTPUtilitiespublic void killAllCookies()
IHTTPUtilities
killAllCookies in interface IHTTPUtilitiespublic void killCookie(java.lang.String name)
IHTTPUtilities
killCookie in interface IHTTPUtilitiesname - the cookie name
public void safeSendForward(java.lang.String context,
java.lang.String location)
throws AccessControlException,
javax.servlet.ServletException,
java.io.IOException
IHTTPUtilities
safeSendForward in interface IHTTPUtilitiescontext - location -
AccessControlException
java.io.IOException
javax.servlet.ServletException
public void safeSendRedirect(java.lang.String context,
java.lang.String location)
throws java.io.IOException
IHTTPUtilities
safeSendRedirect in interface IHTTPUtilitieslocation - the URL to redirect to
java.io.IOException - Signals that an I/O exception has occurred.public void safeSetContentType()
safeSetContentType in interface IHTTPUtilitiesorg.owasp.esapi.interfaces.IHTTPUtilities#safeSetContentType(java.lang.String)public void setNoCacheHeaders()
setNoCacheHeaders in interface IHTTPUtilitiesorg.owasp.esapi.interfaces.IHTTPUtilities#setNoCacheHeaders(javax.servlet.http.HttpServletResponse)public javax.servlet.http.HttpServletRequest getCurrentRequest()
IHTTPUtilities
getCurrentRequest in interface IHTTPUtilitiespublic javax.servlet.http.HttpServletResponse getCurrentResponse()
IHTTPUtilities
getCurrentResponse in interface IHTTPUtilities
public void setCurrentHTTP(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
IHTTPUtilities
setCurrentHTTP in interface IHTTPUtilitiesrequest - the current requestresponse - the current responsepublic void logHTTPRequest(ILogger logger)
IHTTPUtilities
logHTTPRequest in interface IHTTPUtilities
public void logHTTPRequest(ILogger logger,
java.util.List parameterNamesToObfuscate)
logHTTPRequest in interface IHTTPUtilitiesparameterNamesToObfuscate - the sensitive paramsorg.owasp.esapi.interfaces.ILogger#formatHttpRequestForLog(javax.servlet.http.HttpServletRequest)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||