Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
32d476c
End a user's other sessions when their password changes or their acco…
mraible Nov 17, 2026
8fd7bae
Keep the stored password when an OIDC account's profile is saved with…
mraible Nov 18, 2026
babfe8f
End a session after a password change even when its Roller session wa…
mraible Nov 18, 2026
49f9108
Say when a typed password is too long, and keep the generated one out…
mraible Nov 18, 2026
99d7be7
Check the password length on profiles that also have an OpenID URL
mraible Nov 18, 2026
0166a18
Merge branch 'password-length-checks' into end-sessions-on-password-c…
mraible Nov 18, 2026
fd18da4
Merge branch 'external-login-placeholder' into password-length-checks
mraible Nov 18, 2026
44ae043
Merge branch 'password-length-checks' into end-sessions-on-password-c…
mraible Nov 18, 2026
6763bd6
Merge branch 'external-login-placeholder' into password-length-checks
mraible Nov 19, 2026
082ad37
Let long legacy passwords log in, and tighten registration password c…
mraible Nov 19, 2026
feb3c2e
Record the login password at authentication time
mraible Nov 19, 2026
bf2ad64
Test that security.xml records the password digest on every login
mraible Nov 19, 2026
1398bbe
End a login whose account was disabled, and keep sessions across a pa…
mraible Nov 20, 2026
0c1c751
Merge remote-tracking branch 'origin/master' into end-sessions-on-pas…
mraible Nov 20, 2026
f7ee5a2
Clear the login from the session's shared security context before end…
mraible Nov 20, 2026
9c5c1c9
Send a request whose session was just ended back to its page or to th…
mraible Nov 20, 2026
c6eca3f
Keep a session's own requests logged in while it saves a new password
mraible Nov 20, 2026
c03ea3e
Answer comment data requests without a user with 403 instead of a ser…
mraible Nov 20, 2026
bd35911
Name the user and the reason when a session is ended
mraible Nov 20, 2026
ca20d5b
Restore the password encoder in PasswordChangeSessionTest even when c…
mraible Nov 20, 2026
00a95c2
Drop a test helper whose reason no longer holds
mraible Nov 20, 2026
1d02bae
Keep checking a registration after its password is too long
mraible Nov 20, 2026
c4a4e25
Say why the password length limit applies to every algorithm
mraible Nov 20, 2026
6ebe3d1
Merge branch 'password-length-checks' into end-sessions-on-password-c…
mraible Nov 20, 2026
f2aa9e0
Send an ended session to the site root when its path would name anoth…
mraible Nov 21, 2026
1b9a71b
Build an ended session's redirect from the /roller-ui/ path
mraible Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 304 additions & 13 deletions app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSession.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.security.SecureRandom;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.apache.roller.weblogger.ui.rendering.util.cache.SaltCache;
Expand All @@ -35,6 +36,8 @@ public class LoadSaltFilter implements Filter {

static final String RENDERING_PATH = "/roller-ui/rendering/";

private static final String ROLLER_UI_PATH = "/roller-ui/";

/** Roller UI static files, which never hold a form. */
static final String[] STATIC_PATHS = {"/roller-ui/styles/", "/roller-ui/scripts/", "/roller-ui/images/",
"/roller-ui/theme/"};
Expand All @@ -50,6 +53,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}
httpReq.getSession(true);
RollerSession rollerSession = RollerSession.getRollerSession(httpReq);
if (redirectEndedSession(httpReq, (HttpServletResponse) response)) {
return;
}
if (rollerSession != null) {
String userId = rollerSession.getAuthenticatedUser() != null ? rollerSession.getAuthenticatedUser().getId() : "";
SaltCache saltCache = SaltCache.getInstance();
Expand Down Expand Up @@ -89,6 +95,36 @@ static boolean isStaticFile(HttpServletRequest request) {
return false;
}

/**
* Sends a request whose session Roller has just ended, because its user's
* password or account changed, back to the page it asked for, or to the
* login page if it posted a form. Spring Security then asks for a login
* where one is needed, as it does for any visitor who is not logged in.
* Only the request the browser sent is redirected, not a forward.
*
* @return true when the request was redirected
*/
static boolean redirectEndedSession(HttpServletRequest request, HttpServletResponse response)
throws IOException {
if (!RollerSession.isSessionEnded(request)
|| request.getDispatcherType() != DispatcherType.REQUEST) {
return false;
}
String path = request.getServletPath()
+ (request.getPathInfo() != null ? request.getPathInfo() : "");
String target;
if (("GET".equalsIgnoreCase(request.getMethod()) || "HEAD".equalsIgnoreCase(request.getMethod()))
&& path.startsWith(ROLLER_UI_PATH)) {
// Starting the redirect with /roller-ui/ keeps it on this site.
target = request.getContextPath() + ROLLER_UI_PATH + path.substring(ROLLER_UI_PATH.length())
+ (request.getQueryString() != null ? "?" + request.getQueryString() : "");
} else {
target = request.getContextPath() + "/roller-ui/login.rol";
}
response.sendRedirect(target);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
return true;
}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void doFilter(ServletRequest request, ServletResponse response,
try {
SaltValidator.requireSubmittedSalt(httpReq);
} catch (ServletException e) {
// the salt was issued to a login whose session just ended
if (LoadSaltFilter.redirectEndedSession(httpReq, (HttpServletResponse) response)) {
return;
}
if (isPostTooLarge(httpReq)) {
// The container dropped the form, salt included, because it
// is over its maximum POST size. Pasted images make this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.roller.weblogger.ui.core.security;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
* Records a successful login in its session, then lets another handler send
* the user on. Roller ends a session when its user's password is no longer
* the one recorded here.
*/
public class RollerLoginSuccessHandler implements AuthenticationSuccessHandler {

private final AuthenticationSuccessHandler next;

public RollerLoginSuccessHandler(AuthenticationSuccessHandler next) {
this.next = next;
}

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
RollerSession.loggedIn(request, authentication);
next.onAuthenticationSuccess(request, response, authentication);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.roller.weblogger.ui.core.security;


import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -130,9 +130,22 @@ public static PasswordEncoder create() {
*/
private record ExternalLoginAware(PasswordEncoder delegate) implements PasswordEncoder {

/**
* Returns null for a password that BCrypt refuses as too long. A
* login re-encodes the password it has just checked against an older
* encoding, and for such a password that login has to succeed and
* leave the stored password as it is.
*/
@Override
public String encode(CharSequence rawPassword) {
return delegate.encode(rawPassword);
try {
return delegate.encode(rawPassword);
} catch (IllegalArgumentException e) {
if (rawPassword != null && isTooLong(rawPassword.toString())) {
return null;
}
throw e;
}
}

@Override
Expand Down Expand Up @@ -161,4 +174,21 @@ public boolean upgradeEncoding(String encodedPassword) {
public static String randomUnusedPassword() {
return RandomStringUtils.secure().nextAlphanumeric(64);
}

/**
* The longest password, in UTF-8 bytes, that BCrypt accepts. PBKDF2,
* SCrypt and Argon2 take longer ones, but the limit applies whatever the
* algorithm, so that a site can switch to BCrypt, the default, without
* leaving passwords it can't re-encode.
*/
public static final int MAX_PASSWORD_BYTES = 72;

/**
* Returns true when a typed password is longer than an encoder accepts, so
* that a form can say so instead of failing when the password is encoded.
*/
public static boolean isTooLong(String password) {
return password != null
&& password.getBytes(StandardCharsets.UTF_8).length > MAX_PASSWORD_BYTES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.config.AuthMethod;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.codec.Hex;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;

import jakarta.servlet.http.HttpServletRequest;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

Expand All @@ -50,6 +54,17 @@ public RollerRememberMeServices(UserDetailsService userDetailsService) {
log.debug("initialized: RollerRememberMeServices with key");
}

/**
* Records the login a remember-me cookie stands for in its session, as a
* login form does.
*/
@Override
protected Authentication createSuccessfulAuthentication(HttpServletRequest request, UserDetails user) {
Authentication login = super.createSuccessfulAuthentication(request, user);
RollerSession.loggedIn(request, login);
return login;
}

/**
* Calculates the digital signature to be put in the cookie. Default value is
* SHA-512 ("username:tokenExpiryTime:password:key")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.User;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.dao.DataRetrievalFailureException;

Expand Down Expand Up @@ -113,6 +114,8 @@ public UserDetails updatePassword(UserDetails user, String newPassword) {
+ ", which changed while they logged in");
return user;
}
// the password did not change, so the user's sessions stay
RollerSession.passwordReencoded(userData.getUserName(), userData.getPassword(), newPassword);
userData.setPassword(newPassword);
umgr.saveUser(userData);
roller.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.roller.weblogger.pojos.User;
import org.apache.roller.weblogger.pojos.WeblogPermission;
import org.apache.roller.weblogger.ui.core.RollerLoginSessionManager;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.apache.roller.weblogger.ui.struts2.core.Register;
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
import org.apache.struts2.interceptor.parameter.StrutsParameter;
Expand Down Expand Up @@ -143,6 +144,7 @@ public String save() {
myValidate();

if (!hasActionErrors()) {
String previousOpenIdUrl = user.getOpenIdUrl();
getBean().copyTo(user);

if (authMethod == AuthMethod.DB_OIDC) {
Expand All @@ -158,9 +160,14 @@ public String save() {
}
}

// User.password does not allow null, so generate one
if (authMethod.equals(AuthMethod.OIDC) ||
(authMethod.equals(AuthMethod.DB_OIDC) && !StringUtils.isEmpty(bean.getOpenIdUrl()))) {
// User.password does not allow null, so generate one when the user
// starts signing in with an OpenID URL. Keep the stored one when the
// OpenID URL is unchanged, so an edit doesn't end the user's sessions.
if ((authMethod.equals(AuthMethod.OIDC) ||
(authMethod.equals(AuthMethod.DB_OIDC) && !StringUtils.isEmpty(bean.getOpenIdUrl())))
&& (StringUtils.isEmpty(user.getPassword())
|| !StringUtils.equals(StringUtils.removeEnd(previousOpenIdUrl, "/"),
StringUtils.removeEnd(user.getOpenIdUrl(), "/")))) {
String randomString = RollerPasswordEncoders.randomUnusedPassword();
user.resetPassword(randomString);
}
Expand Down Expand Up @@ -191,6 +198,9 @@ public String save() {
// save new user
mgr.addUser(user);
} else {
if (isUserEditingSelf()) {
RollerSession.savingPassword(getServletRequest(), user);
}
mgr.saveUser(user);
}

Expand All @@ -214,6 +224,12 @@ public String save() {
}
WebloggerFactory.getWeblogger().flush();

// a password change ends the user's sessions, except this one
// when the administrator edits their own account
if (!isAdd() && isUserEditingSelf()) {
RollerSession.refreshPassword(getServletRequest(), user);
}

// successful add or edit: send user back to user admin page
bean = new CreateUserBean();
addMessage("userAdmin.userSaved");
Expand All @@ -231,7 +247,10 @@ private boolean isAdd() {
return actionName.equals("createUser");
}

private void myValidate() {
void myValidate() {
if (RollerPasswordEncoders.isTooLong(getBean().getPassword())) {
addError("userRegister.error.passwordTooLong");
}
// the external-login marker never matches at login
if (RollerPasswordEncoders.isExternalLoginMarker(getBean().getPassword())) {
addError("error.add.user.reservedPassword");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void doGet(HttpServletRequest request,
// need post permission to view comments
RollerSession rses = RollerSession.getRollerSession(request);
Weblog weblog = c.getWeblogEntry().getWebsite();
if (weblog.hasUserPermission(rses.getAuthenticatedUser(), WeblogPermission.POST)) {
if (hasPostPermission(rses, weblog)) {
// HTML-escaped, since the page shows it as HTML
String content = Utilities.escapeHTML(c.getContent());
String json = "{\"id\":\"" + StringEscapeUtils.escapeJson(c.getId())
Expand Down Expand Up @@ -106,7 +106,7 @@ public void doPut(HttpServletRequest request,
// need post permission to edit comments
RollerSession rses = RollerSession.getRollerSession(request);
Weblog weblog = c.getWeblogEntry().getWebsite();
if (weblog.hasUserPermission(rses.getAuthenticatedUser(), WeblogPermission.POST)) {
if (hasPostPermission(rses, weblog)) {
String content = Utilities.streamToString(request.getInputStream());
c.setContent(content);
// don't update the posttime when updating the comment
Expand Down Expand Up @@ -138,6 +138,15 @@ public void doPost(HttpServletRequest request,
doPut(request, response);
}

/**
* Whether the session's user may post to the weblog. A request with no
* user, such as one whose session was just ended, may not.
*/
private static boolean hasPostPermission(RollerSession rses, Weblog weblog) {
return rses != null && rses.getAuthenticatedUser() != null
&& weblog.hasUserPermission(rses.getAuthenticatedUser(), WeblogPermission.POST);
}

private void writeSaveResponse(HttpServletRequest request,
HttpServletResponse response, int status, String id, String content)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.roller.weblogger.config.AuthMethod;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.User;
import org.apache.roller.weblogger.ui.core.RollerSession;
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
import org.apache.struts2.interceptor.parameter.StrutsParameter;
import org.apache.struts2.interceptor.validation.SkipValidation;
Expand Down Expand Up @@ -75,6 +76,7 @@ public String save() {

// We ONLY modify the user currently logged in
User existingUser = getAuthenticatedUser();
String previousOpenIdUrl = existingUser.getOpenIdUrl();

// copy updated attributes
getBean().copyTo(existingUser);
Expand Down Expand Up @@ -106,9 +108,15 @@ public String save() {
}
}

// User.password does not allow null, so generate one
if (authMethod.equals(AuthMethod.OIDC) ||
(authMethod.equals(AuthMethod.DB_OIDC) && !StringUtils.isEmpty(bean.getOpenIdUrl()))) {
// User.password does not allow null, so generate one when the user
// starts signing in with an OpenID URL. Keep the stored one when the
// OpenID URL is unchanged, so a profile edit doesn't end the user's
// other sessions.
if ((authMethod.equals(AuthMethod.OIDC) ||
(authMethod.equals(AuthMethod.DB_OIDC) && !StringUtils.isEmpty(bean.getOpenIdUrl())))
&& (StringUtils.isEmpty(existingUser.getPassword())
|| !StringUtils.equals(StringUtils.removeEnd(previousOpenIdUrl, "/"),
StringUtils.removeEnd(existingUser.getOpenIdUrl(), "/")))) {
String randomString = RollerPasswordEncoders.randomUnusedPassword();
existingUser.resetPassword(randomString);
}
Expand All @@ -121,9 +129,12 @@ public String save() {

try {
// save the updated profile
// a password change ends the user's other sessions, not this one
RollerSession.savingPassword(getServletRequest(), existingUser);
UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
mgr.saveUser(existingUser);
WebloggerFactory.getWeblogger().flush();
RollerSession.refreshPassword(getServletRequest(), existingUser);
Comment thread
mraible marked this conversation as resolved.
Resolved
addMessage("generic.changes.saved");
return SUCCESS;
} catch (WebloggerException ex) {
Expand All @@ -135,6 +146,9 @@ public String save() {
}

public void myValidate() {
if (RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) {
addError("userRegister.error.passwordTooLong");
}
// the external-login marker never matches at login
if (RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) {
addError("error.add.user.reservedPassword");
Expand Down
Loading
Loading