|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.reference.DefaultHTTPUtilities
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.
HTTPUtilities| Field Summary |
| Fields inherited from interface org.owasp.esapi.HTTPUtilities |
REMEMBER_TOKEN_COOKIE_NAME |
| Constructor Summary | |
DefaultHTTPUtilities()
|
|
| 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()
Checks the method of the current request. |
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)
Utility method to get a cookie from the current request. |
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)
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(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)
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. |
java.lang.String |
setRememberToken(java.lang.String password,
int maxAge,
java.lang.String domain,
java.lang.String path)
Save the user's remember me token in a cookie. |
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 DefaultHTTPUtilities()
| Method Detail |
public java.lang.String addCSRFToken(java.lang.String href)
HTTPUtilities
addCSRFToken in interface HTTPUtilitieshref -
HTTPUtilities.addCSRFToken(java.lang.String)public java.lang.String getCSRFToken()
HTTPUtilities
getCSRFToken in interface HTTPUtilitiesHTTPUtilities.getCSRFToken()
public java.lang.String setRememberToken(java.lang.String password,
int maxAge,
java.lang.String domain,
java.lang.String path)
setRememberToken in interface HTTPUtilitiespassword - 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 void assertSecureRequest()
throws AccessControlException
assertSecureRequest in interface HTTPUtilitiesAccessControlException
public void safeAddCookie(java.lang.String name,
java.lang.String value,
int maxAge,
java.lang.String domain,
java.lang.String path)
safeAddCookie in interface HTTPUtilitiesmaxAge - number of seconds until cookie expiresname - the cookie namevalue - the cookie valuedomain - the domain to restrict the cookie to, or nullpath - the path to restrict the cookie to, or nullorg.owasp.esapi.HTTPUtilities#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)
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the current HttpServletResponse object
safeAddHeader in interface HTTPUtilitiesname - 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 HTTPUtilities
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
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the current HttpServletResponse object
safeSetHeader in interface HTTPUtilitiesname - 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
HTTPUtilitiesHTTPUtilities.getCurrentRequest() to obtain the current HttpSession object
changeSessionIdentifier in interface HTTPUtilitiesAuthenticationException
public void verifyCSRFToken()
throws IntrusionException
HTTPUtilitiesHTTPUtilities.getCurrentRequest() to obtain the current url
verifyCSRFToken in interface HTTPUtilitiesIntrusionExceptionpublic java.lang.String decryptHiddenField(java.lang.String encrypted)
HTTPUtilitiesEncryptor.decrypt(String) ?
decryptHiddenField in interface HTTPUtilities
public java.util.Map decryptQueryString(java.lang.String encrypted)
throws EncryptionException
HTTPUtilities
decryptQueryString in interface HTTPUtilitiesencrypted -
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
EncryptionException
public java.util.Map decryptStateFromCookie()
throws EncryptionException
HTTPUtilitiesHTTPUtilities#getCurrentResquest() to obtain the HttpServletRequest object
FIXME RD: More information needed about why this may be useful
decryptStateFromCookie in interface HTTPUtilitiesEncryptionExceptionHTTPUtilities.decryptStateFromCookie()
public java.lang.String encryptHiddenField(java.lang.String value)
throws EncryptionException
HTTPUtilities
encryptHiddenField in interface HTTPUtilitiesvalue - 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
HTTPUtilities
encryptQueryString in interface HTTPUtilitiesEncryptor.encrypt(String) ?
EncryptionException
public void encryptStateInCookie(java.util.Map cleartext)
throws EncryptionException
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the HttpServletResponse object
encryptStateInCookie in interface HTTPUtilitiesEncryptionExceptionHTTPUtilities.encryptStateInCookie(java.util.Map)
public java.util.List getSafeFileUploads(java.io.File tempDir,
java.io.File finalDir)
throws ValidationException
getSafeFileUploads in interface HTTPUtilitiestempDir - the temp dirfinalDir - the final dir
ValidationException - the validation exceptionorg.owasp.esapi.HTTPUtilities#safeGetFileUploads(javax.servlet.http.HttpServletRequest,
java.io.File, java.io.File, int)public boolean isSecureChannel()
public void killAllCookies()
HTTPUtilitiesHTTPUtilities.getCurrentRequest() to obtain the HttpServletRequest object
This method uses HTTPUtilities.getCurrentResponse() to obtain the HttpServletRequest object
killAllCookies in interface HTTPUtilitiespublic void killCookie(java.lang.String name)
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the HttpServletResponse object
killCookie in interface HTTPUtilitiesname - the cookie name
public void safeSendForward(java.lang.String context,
java.lang.String location)
throws AccessControlException,
javax.servlet.ServletException,
java.io.IOException
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the HttpServletResponse object
safeSendForward in interface HTTPUtilitiescontext - location -
javax.servlet.ServletException
java.io.IOException
AccessControlException
public void safeSendRedirect(java.lang.String context,
java.lang.String location)
throws java.io.IOException
HTTPUtilitiesHTTPUtilities.getCurrentResponse() to obtain the HttpServletResponse object
safeSendRedirect in interface HTTPUtilitiescontext - location - the URL to redirect to
java.io.IOException - Signals that an I/O exception has occurred.public void safeSetContentType()
safeSetContentType in interface HTTPUtilitiesorg.owasp.esapi.HTTPUtilities#safeSetContentType(java.lang.String)public void setNoCacheHeaders()
setNoCacheHeaders in interface HTTPUtilitiesorg.owasp.esapi.HTTPUtilities#setNoCacheHeaders(javax.servlet.http.HttpServletResponse)public javax.servlet.http.HttpServletRequest getCurrentRequest()
HTTPUtilities
getCurrentRequest in interface HTTPUtilitiespublic javax.servlet.http.HttpServletResponse getCurrentResponse()
HTTPUtilities
getCurrentResponse in interface HTTPUtilities
public void setCurrentHTTP(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
HTTPUtilities
setCurrentHTTP in interface HTTPUtilitiesrequest - the current requestresponse - the current responsepublic void logHTTPRequest(Logger logger)
HTTPUtilitiesHTTPUtilities.getCurrentRequest() to obtain the HttpServletRequest object
logHTTPRequest in interface HTTPUtilitieslogger - the logger to write the request to
public void logHTTPRequest(Logger logger,
java.util.List parameterNamesToObfuscate)
logHTTPRequest in interface HTTPUtilitieslogger - the logger to write the request toparameterNamesToObfuscate - the sensitive paramsorg.owasp.esapi.Logger#formatHttpRequestForLog(javax.servlet.http.HttpServletRequest)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||