Skip to content

Commit

Permalink
Fixed strange security hole - a logged in user could go to login page…
Browse files Browse the repository at this point in the history
… and login as some other user no matter what password is entered. Somehow authenticator just returns success.
  • Loading branch information
NikitaZ committed May 8, 2022
1 parent e124b30 commit d334c40
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/su/ioffe/crescente/web/LoginPageBean.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package su.ioffe.crescente.web;


import jakarta.servlet.ServletException;
import su.ioffe.crescente.data.info.UserAccountSummary;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
Expand All @@ -17,6 +18,7 @@
import jakarta.servlet.http.HttpServletResponse;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

import static jakarta.security.enterprise.AuthenticationStatus.NOT_DONE;
Expand Down Expand Up @@ -96,13 +98,22 @@ public boolean getReadOnly() {
}

public String login() {
if (securityContext.getCallerPrincipal() != null &&
!securityContext.getCallerPrincipal().getName().equals(getUserName())) {
externalContext.invalidateSession();
try {
((HttpServletRequest) externalContext.getRequest()).logout();
} catch (ServletException e) {
LOGGER.log(Level.SEVERE, "Not cool...", e);
}
return null;
}
Credential credential = new UsernamePasswordCredential(getUserName(), new Password(getPassword()));
AuthenticationStatus status = securityContext.authenticate(
(HttpServletRequest) externalContext.getRequest(),
(HttpServletResponse) externalContext.getResponse(),
withParams().credential(credential));
// withParams().credential(credential).newAuthentication(true));

if (status.equals(NOT_DONE)) {
facesContext.addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Something is wrong with authentication configuration or password is not set, please contact system administrator.", null));
Expand Down

0 comments on commit d334c40

Please sign in to comment.