Skip to content

Commit df4a4bb

Browse files
author
planetlevel
committed
Add assertSecureRequest() call which checks for POST and SSL at once, since they should always be used together.
1 parent d7030f1 commit df4a4bb

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

src/org/owasp/esapi/Authenticator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.servlet.http.HttpServletResponse;
3535
import javax.servlet.http.HttpSession;
3636

37+
import org.owasp.esapi.errors.AccessControlException;
3738
import org.owasp.esapi.errors.AuthenticationAccountsException;
3839
import org.owasp.esapi.errors.AuthenticationCredentialsException;
3940
import org.owasp.esapi.errors.AuthenticationException;
@@ -631,9 +632,11 @@ public IUser login(HttpServletRequest request, HttpServletResponse response) thr
631632
// set last host address
632633
user.setLastHostAddress( request.getRemoteHost() );
633634

634-
// warn if this authentication request came over a non-SSL connection, exposing credentials or session id
635-
if ( !ESAPI.httpUtilities().isSecureChannel() ) {
636-
new AuthenticationCredentialsException( "Session or credentials exposed", "Authentication attempt made over non-SSL connection. Check web.xml and server configuration. User: " + user.getAccountName() );
635+
// warn if this authentication request was not POST or non-SSL connection, exposing credentials or session id
636+
try {
637+
ESAPI.httpUtilities().assertSecureRequest();
638+
} catch( AccessControlException e ) {
639+
throw new AuthenticationException( "Attempt to login with an insecure request", e.getLogMessage(), e );
637640
}
638641

639642
// don't let anonymous user log in

src/org/owasp/esapi/interfaces/IHTTPUtilities.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
*/
4545
public interface IHTTPUtilities {
4646

47+
48+
/**
49+
* Ensures that the current request uses SSL and POST to protect any sensitive parameters
50+
* in the querystring from being sniffed or logged. For example, this method should
51+
* be called from any method that uses sensitive data from a web form.
52+
* @param requiredMethod
53+
* @throws AccessControlException
54+
*/
55+
void assertSecureRequest() throws AccessControlException;
56+
57+
4758
/**
4859
* Adds the current user's CSRF token (see User.getCSRFToken()) to the URL for purposes of preventing CSRF attacks.
4960
* This method should be used on all URLs to be put into all links and forms the application generates.
@@ -174,18 +185,6 @@ public interface IHTTPUtilities {
174185
*/
175186
Map decryptStateFromCookie() throws EncryptionException ;
176187

177-
/**
178-
* Returns true if the request and response are using an SSL-enabled connection. This check should be made on
179-
* every request from the login page through the logout confirmation page. Essentially, any page that uses the
180-
* Authenticator.login() call should call this. Implementers should consider calling this method directly in
181-
* their Authenticator.login() method. If this method returns true for a page that requires SSL, there must be a
182-
* misconfiguration, an AuthenticationException is warranted.
183-
*
184-
* @param request
185-
* @return
186-
*/
187-
boolean isSecureChannel();
188-
189188
/**
190189
* Kill all cookies received in the last request from the browser. Note that new cookies set by the application in
191190
* this response may not be killed by this method.

test/testresources/multipart.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)