Blame SOURCES/tomcat-7.0.76-CVE-2019-17563.patch

90ce6a
diff -up ./java/org/apache/catalina/authenticator/AuthenticatorBase.java.orig ./java/org/apache/catalina/authenticator/AuthenticatorBase.java
90ce6a
--- ./java/org/apache/catalina/authenticator/AuthenticatorBase.java.orig	2020-04-24 11:29:17.047848947 -0400
90ce6a
+++ ./java/org/apache/catalina/authenticator/AuthenticatorBase.java	2020-04-24 11:36:59.943955494 -0400
90ce6a
@@ -854,10 +854,11 @@ public abstract class AuthenticatorBase
90ce6a
         }
90ce6a
 
90ce6a
         // Cache the authentication information in our session, if any
90ce6a
-        if (cache) {
90ce6a
-            if (session != null) {
90ce6a
+        if (session != null) {
90ce6a
+            if (cache) {
90ce6a
                 session.setAuthType(authType);
90ce6a
                 session.setPrincipal(principal);
90ce6a
+            } else {
90ce6a
                 if (username != null)
90ce6a
                     session.setNote(Constants.SESS_USERNAME_NOTE, username);
90ce6a
                 else
90ce6a
diff -up ./java/org/apache/catalina/authenticator/Constants.java.orig ./java/org/apache/catalina/authenticator/Constants.java
90ce6a
--- ./java/org/apache/catalina/authenticator/Constants.java.orig	2020-04-24 11:29:23.513836466 -0400
90ce6a
+++ ./java/org/apache/catalina/authenticator/Constants.java	2020-04-24 11:37:43.381871646 -0400
90ce6a
@@ -119,7 +119,10 @@ public class Constants {
90ce6a
 
90ce6a
     /**
90ce6a
      * The previously authenticated principal (if caching is disabled).
90ce6a
+     *
90ce6a
+     * @deprecated Unused. Will be removed in Tomcat 10.
90ce6a
      */
90ce6a
+    @Deprecated
90ce6a
     public static final String FORM_PRINCIPAL_NOTE =
90ce6a
         "org.apache.catalina.authenticator.PRINCIPAL";
90ce6a
 
90ce6a
diff -up ./java/org/apache/catalina/authenticator/FormAuthenticator.java.orig ./java/org/apache/catalina/authenticator/FormAuthenticator.java
90ce6a
--- ./java/org/apache/catalina/authenticator/FormAuthenticator.java.orig	2020-04-24 11:29:30.865822275 -0400
90ce6a
+++ ./java/org/apache/catalina/authenticator/FormAuthenticator.java	2020-04-24 11:41:51.489392742 -0400
90ce6a
@@ -149,10 +149,6 @@ public class FormAuthenticator
90ce6a
                                 LoginConfig config)
90ce6a
         throws IOException {
90ce6a
 
90ce6a
-        if (checkForCachedAuthentication(request, response, true)) {
90ce6a
-            return (true);
90ce6a
-        }
90ce6a
-
90ce6a
         // References to objects we will need later
90ce6a
         Session session = null;
90ce6a
         Principal principal = null;
90ce6a
@@ -174,11 +170,8 @@ public class FormAuthenticator
90ce6a
                 principal =
90ce6a
                     context.getRealm().authenticate(username, password);
90ce6a
                 if (principal != null) {
90ce6a
-                    session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
90ce6a
+                    register(request, response, principal, HttpServletRequest.FORM_AUTH, username, password);
90ce6a
                     if (!matchRequest(request)) {
90ce6a
-                        register(request, response, principal,
90ce6a
-                                HttpServletRequest.FORM_AUTH,
90ce6a
-                                 username, password);
90ce6a
                         return (true);
90ce6a
                     }
90ce6a
                 }
90ce6a
@@ -197,17 +190,6 @@ public class FormAuthenticator
90ce6a
                           + session.getIdInternal()
90ce6a
                           + "'");
90ce6a
             }
90ce6a
-            principal = (Principal)
90ce6a
-                session.getNote(Constants.FORM_PRINCIPAL_NOTE);
90ce6a
-            register(request, response, principal, HttpServletRequest.FORM_AUTH,
90ce6a
-                     (String) session.getNote(Constants.SESS_USERNAME_NOTE),
90ce6a
-                     (String) session.getNote(Constants.SESS_PASSWORD_NOTE));
90ce6a
-            // If we're caching principals we no longer need the username
90ce6a
-            // and password in the session, so remove them
90ce6a
-            if (cache) {
90ce6a
-                session.removeNote(Constants.SESS_USERNAME_NOTE);
90ce6a
-                session.removeNote(Constants.SESS_PASSWORD_NOTE);
90ce6a
-            }
90ce6a
             if (restoreRequest(request, session)) {
90ce6a
                 if (log.isDebugEnabled()) {
90ce6a
                     log.debug("Proceed to restored request");
90ce6a
@@ -222,6 +204,12 @@ public class FormAuthenticator
90ce6a
             }
90ce6a
         }
90ce6a
 
90ce6a
+        // This check has to be after the previous check for a matching request
90ce6a
+        // because that matching request may also include a cached Principal.
90ce6a
+        if (checkForCachedAuthentication(request, response, true)) {
90ce6a
+            return true;
90ce6a
+        }
90ce6a
+
90ce6a
         // Acquire references to objects we will need to evaluate
90ce6a
         MessageBytes uriMB = MessageBytes.newInstance();
90ce6a
         CharChunk uriCC = uriMB.getCharChunk();
90ce6a
@@ -314,12 +302,7 @@ public class FormAuthenticator
90ce6a
             return (false);
90ce6a
         }
90ce6a
 
90ce6a
-        // Save the authenticated Principal in our session
90ce6a
-        session.setNote(Constants.FORM_PRINCIPAL_NOTE, principal);
90ce6a
-
90ce6a
-        // Save the username and password as well
90ce6a
-        session.setNote(Constants.SESS_USERNAME_NOTE, username);
90ce6a
-        session.setNote(Constants.SESS_PASSWORD_NOTE, password);
90ce6a
+        register(request, response, principal, HttpServletRequest.FORM_AUTH, username, password);
90ce6a
 
90ce6a
         // Redirect the user to the original request URI (which will cause
90ce6a
         // the original request to be restored)
90ce6a
@@ -489,7 +472,7 @@ public class FormAuthenticator
90ce6a
     }
90ce6a
 
90ce6a
       // Is there a saved principal?
90ce6a
-      if (session.getNote(Constants.FORM_PRINCIPAL_NOTE) == null) {
90ce6a
+    if (cache && session.getPrincipal() == null || !cache && request.getPrincipal() == null) {        
90ce6a
         return (false);
90ce6a
     }
90ce6a
 
90ce6a
@@ -518,7 +501,6 @@ public class FormAuthenticator
90ce6a
         SavedRequest saved = (SavedRequest)
90ce6a
             session.getNote(Constants.FORM_REQUEST_NOTE);
90ce6a
         session.removeNote(Constants.FORM_REQUEST_NOTE);
90ce6a
-        session.removeNote(Constants.FORM_PRINCIPAL_NOTE);
90ce6a
         if (saved == null) {
90ce6a
             return (false);
90ce6a
         }