From cfb28cc499f79a4a733c61257950995260e1fa3e Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Mon, 16 Nov 2026 22:02:18 -0700 Subject: [PATCH 1/9] Don't match the external-login placeholder as a password Users who log in through LDAP or the servlet container have users.passwords.externalAuthValue stored in place of a Roller password. Roller's password encoder no longer matches that placeholder, so it isn't treated as a password anywhere the encoder checks one. --- .../core/security/RollerPasswordEncoders.java | 31 ++++- .../ExternalLoginPlaceholderTest.java | 129 ++++++++++++++++++ 2 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index f3fb2753e..2804913d4 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -42,7 +42,7 @@ private RollerPasswordEncoders() { } @SuppressWarnings("deprecation") - public static DelegatingPasswordEncoder create() { + public static PasswordEncoder create() { Map encoders = new HashMap<>(); @@ -93,6 +93,33 @@ public static DelegatingPasswordEncoder create() { log.info("Password Encryption Algorithm set to '" + algorithm + "'"); - return new DelegatingPasswordEncoder(algorithm, encoders); + return new ExternalLoginAware(new DelegatingPasswordEncoder(algorithm, encoders)); + } + + /** + * Users who log in through LDAP or the servlet container have no Roller + * password; Roller stores users.passwords.externalAuthValue in its place. + * That placeholder is not a password, so it never matches. + */ + private record ExternalLoginAware(PasswordEncoder delegate) implements PasswordEncoder { + + @Override + public String encode(CharSequence rawPassword) { + return delegate.encode(rawPassword); + } + + @Override + public boolean matches(CharSequence rawPassword, String encodedPassword) { + String marker = WebloggerConfig.getProperty("users.passwords.externalAuthValue", ""); + if (rawPassword != null && marker != null && !marker.isEmpty() && marker.contentEquals(rawPassword)) { + return false; + } + return delegate.matches(rawPassword, encodedPassword); + } + + @Override + public boolean upgradeEncoding(String encodedPassword) { + return delegate.upgradeEncoding(encodedPassword); + } } } diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java new file mode 100644 index 000000000..d5819d202 --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java @@ -0,0 +1,129 @@ +/* + * 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.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.apache.roller.weblogger.TestUtils; +import org.apache.roller.weblogger.business.WebloggerFactory; +import org.apache.roller.weblogger.config.WebloggerConfig; +import org.apache.roller.weblogger.pojos.User; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.crypto.password.PasswordEncoder; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Users who log in through LDAP or the servlet container have a placeholder + * stored instead of a Roller password. The placeholder is not a password. + */ +class ExternalLoginPlaceholderTest { + + private final Map savedProperties = new HashMap<>(); + private String userName; + + @BeforeEach + void setUp() throws Exception { + TestUtils.setupWeblogger(); + setProperty("passwds.encryption.enabled", "true"); + setProperty("passwds.encryption.algorithm", "bcrypt"); + } + + @AfterEach + void tearDown() throws Exception { + if (userName != null) { + TestUtils.teardownUser(userName); + TestUtils.endSession(true); + } + Properties config = config(); + savedProperties.forEach((k, v) -> { + if (v == null) { + config.remove(k); + } else { + config.setProperty(k, v); + } + }); + } + + @Test + void anEncodedPlaceholderIsNotAPassword() throws Exception { + setProperty("authentication.method", "cma"); + // as Register stores it for container-managed sign-ups + User user = TestUtils.setupUser("cmauser"); + userName = user.getUserName(); + // (User.resetPassword encodes with the login's password encoder) + user.setPassword(RollerPasswordEncoders.create().encode( + WebloggerConfig.getProperty("users.passwords.externalAuthValue", ""))); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + } + + @Test + void anUnencodedPlaceholderIsNotAPassword() throws Exception { + setProperty("authentication.method", "db"); + setProperty("passwds.encryption.lazyUpgradeFrom", "plaintext"); + // as CustomUserRegistry stores it for directory users + User user = TestUtils.setupUser("ldapuser"); + userName = user.getUserName(); + user.setPassword(""); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + } + + @Test + void theEncoderDoesNotMatchThePlaceholder() { + // the encoder also checks AtomPub and XML-RPC passwords + PasswordEncoder encoder = RollerPasswordEncoders.create(); + assertFalse(encoder.matches("", encoder.encode(""))); + assertTrue(encoder.matches("secret", encoder.encode("secret"))); + } + + private static DaoAuthenticationProvider provider() { + DaoAuthenticationProvider provider = new DaoAuthenticationProvider(new RollerUserDetailsService()); + provider.setPasswordEncoder(RollerPasswordEncoders.create()); + return provider; + } + + private void setProperty(String key, String value) throws ReflectiveOperationException { + Properties config = config(); + savedProperties.putIfAbsent(key, config.getProperty(key)); + config.setProperty(key, value); + } + + private static Properties config() throws ReflectiveOperationException { + Field field = WebloggerConfig.class.getDeclaredField("config"); + field.setAccessible(true); + return (Properties) field.get(null); + } +} From fa368f39b9fa8df8bdb6c75f4b806333daf634fc Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Tue, 17 Nov 2026 19:52:19 -0700 Subject: [PATCH 2/9] Reject the external-login placeholder as a chosen password and never match an empty one Registration, the profile page and the admin user editor now reject users.passwords.externalAuthValue, and the default , as a new password with a validation message, since that value never matches at login. An account that already has it can be given a new password by an administrator. An empty configured value now falls back to for what Roller stores, and the password encoder never matches an empty password or the default placeholder. --- .../ui/core/security/CustomUserRegistry.java | 2 +- .../core/security/RollerPasswordEncoders.java | 30 ++- .../weblogger/ui/struts2/admin/UserEdit.java | 5 + .../weblogger/ui/struts2/core/Profile.java | 5 + .../weblogger/ui/struts2/core/Register.java | 9 +- .../resources/ApplicationResources.properties | 1 + .../ExternalLoginPlaceholderTest.java | 68 ++++++ .../core/ExternalLoginMarkerPasswordTest.java | 203 ++++++++++++++++++ 8 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/CustomUserRegistry.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/CustomUserRegistry.java index e618468b1..14cbe2898 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/CustomUserRegistry.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/CustomUserRegistry.java @@ -154,7 +154,7 @@ else if(userDetails instanceof LdapUserDetails) { // for LDAP we don't store its password in the roller_users table, // just an string indicating external auth method being used. - unusedPassword = WebloggerConfig.getProperty("users.passwords.externalAuthValue",""); + unusedPassword = RollerPasswordEncoders.externalLoginMarker(); ud.setPassword(unusedPassword); ud.setEnabled(enabled ? Boolean.TRUE : Boolean.FALSE); diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index 2804913d4..5bc019802 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -38,9 +38,33 @@ public final class RollerPasswordEncoders { private static final Log log = LogFactory.getLog(RollerPasswordEncoders.class); + /** Stored in place of a password when none is configured. */ + public static final String DEFAULT_EXTERNAL_LOGIN_MARKER = ""; + private RollerPasswordEncoders() { } + /** + * The value stored in place of a Roller password for users who log in + * through LDAP or the servlet container: users.passwords.externalAuthValue, + * or the default when that setting is empty. + */ + public static String externalLoginMarker() { + String marker = WebloggerConfig.getProperty("users.passwords.externalAuthValue"); + return marker == null || marker.isEmpty() ? DEFAULT_EXTERNAL_LOGIN_MARKER : marker; + } + + /** + * Whether a password is the configured external-login marker or the + * default one, which accounts may still have stored from before the + * setting changed. Neither matches at login, so neither can be chosen as a + * Roller password. + */ + public static boolean isExternalLoginMarker(CharSequence password) { + return password != null && (externalLoginMarker().contentEquals(password) + || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password)); + } + @SuppressWarnings("deprecation") public static PasswordEncoder create() { @@ -99,7 +123,8 @@ public static PasswordEncoder create() { /** * Users who log in through LDAP or the servlet container have no Roller * password; Roller stores users.passwords.externalAuthValue in its place. - * That placeholder is not a password, so it never matches. + * That placeholder is not a password, so it never matches, and neither do + * the default placeholder and an empty password. */ private record ExternalLoginAware(PasswordEncoder delegate) implements PasswordEncoder { @@ -110,8 +135,7 @@ public String encode(CharSequence rawPassword) { @Override public boolean matches(CharSequence rawPassword, String encodedPassword) { - String marker = WebloggerConfig.getProperty("users.passwords.externalAuthValue", ""); - if (rawPassword != null && marker != null && !marker.isEmpty() && marker.contentEquals(rawPassword)) { + if (rawPassword == null || rawPassword.length() == 0 || isExternalLoginMarker(rawPassword)) { return false; } return delegate.matches(rawPassword, encodedPassword); diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java index cb77e1750..ff3e73362 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java @@ -41,6 +41,7 @@ import org.apache.roller.weblogger.ui.core.RollerLoginSessionManager; import org.apache.roller.weblogger.ui.struts2.core.Register; import org.apache.roller.weblogger.ui.struts2.util.UIAction; +import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; @@ -232,6 +233,10 @@ private boolean isAdd() { } private void myValidate() { + // the external-login marker never matches at login + if (RollerPasswordEncoders.isExternalLoginMarker(getBean().getPassword())) { + addError("error.add.user.reservedPassword"); + } if (isAdd()) { String allowed = WebloggerConfig.getProperty("username.allowedChars"); if(allowed == null || allowed.isBlank()) { diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java index 9671fb0d3..d0134a3be 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java @@ -29,6 +29,7 @@ import org.apache.roller.weblogger.config.WebloggerConfig; import org.apache.roller.weblogger.pojos.User; import org.apache.roller.weblogger.ui.struts2.util.UIAction; +import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; @@ -135,6 +136,10 @@ public String save() { } public void myValidate() { + // the external-login marker never matches at login + if (RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) { + addError("error.add.user.reservedPassword"); + } if (StringUtils.isEmpty(getBean().getOpenIdUrl())) { // check that passwords match if they were specified (w/StringUtils.equals, null == null) if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) { diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index cf8fc87e0..69b0f7abe 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -40,6 +40,7 @@ import org.apache.roller.weblogger.ui.core.security.BootstrapSecurity; import org.apache.roller.weblogger.ui.struts2.util.UIAction; import org.apache.roller.weblogger.util.MailUtil; +import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; @@ -357,7 +358,7 @@ public void myValidate() { if (usingSSO) { // store an unused marker in the Roller DB for the passphrase in // the LDAP or CMA cases, as actual passwords are stored externally - String unusedPassword = WebloggerConfig.getProperty("users.passwords.externalAuthValue", ""); + String unusedPassword = RollerPasswordEncoders.externalLoginMarker(); // Preserve username and password, Spring Security case preserveUsernameAndPassword(unusedPassword); @@ -389,6 +390,12 @@ public void myValidate() { getBean().setPasswordConfirm(randomString); } + // the external-login marker is stored for users who log in elsewhere + // and never matches at login + if (!usingSSO && RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) { + addError("error.add.user.reservedPassword"); + } + // check that passwords match if (!getBean().getPasswordText().equals(getBean().getPasswordConfirm())) { addError("userRegister.error.mismatchedPasswords"); diff --git a/app/src/main/resources/ApplicationResources.properties b/app/src/main/resources/ApplicationResources.properties index b55815559..387e4a0ad 100644 --- a/app/src/main/resources/ApplicationResources.properties +++ b/app/src/main/resources/ApplicationResources.properties @@ -486,6 +486,7 @@ error.add.user.openIdInUse=Open ID already in use with another account. error.add.user.missingUserName=You must specify a username. error.add.user.badUserName=Invalid user name (must be alpha-numerics only). error.add.user.missingPassword=You must specify a password. +error.add.user.reservedPassword=That password is reserved for accounts that log in elsewhere. Please choose a different password. error.add.user.invalid.timezone=Invalid timezone. error.add.user.invalid.locale=Invalid locale. error.upload.dirmax=You cannot exceed the maximum directory size of {0} MB. diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java index d5819d202..12234d3d9 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java @@ -32,8 +32,10 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.password.PasswordEncoder; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -101,6 +103,72 @@ void anUnencodedPlaceholderIsNotAPassword() throws Exception { UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); } + @Test + void anOrdinaryPlaintextPasswordStillMatches() throws Exception { + setProperty("authentication.method", "db"); + setProperty("passwds.encryption.lazyUpgradeFrom", "plaintext"); + // as older Roller versions stored passwords + User user = TestUtils.setupUser("plainuser"); + userName = user.getUserName(); + user.setPassword("an ordinary password"); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertTrue(provider().authenticate(UsernamePasswordAuthenticationToken.unauthenticated( + userName, "an ordinary password")).isAuthenticated()); + assertTrue(RollerPasswordEncoders.create().matches("an ordinary password", "an ordinary password")); + } + + @Test + void theDefaultPlaceholderIsNotAPasswordUnderAnotherConfiguredValue() throws Exception { + setProperty("authentication.method", "db"); + setProperty("passwds.encryption.lazyUpgradeFrom", "plaintext"); + setProperty("users.passwords.externalAuthValue", ""); + // stored before the setting was changed + User user = TestUtils.setupUser("olduser"); + userName = user.getUserName(); + user.setPassword(""); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + assertFalse(RollerPasswordEncoders.create().matches("", "")); + } + + @Test + void anEmptyConfiguredPlaceholderIsNotAPassword() throws Exception { + setProperty("authentication.method", "db"); + setProperty("passwds.encryption.lazyUpgradeFrom", "plaintext"); + setProperty("users.passwords.externalAuthValue", ""); + // as CustomUserRegistry stored an empty placeholder before + User user = TestUtils.setupUser("emptyuser"); + userName = user.getUserName(); + user.setPassword(""); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + assertFalse(RollerPasswordEncoders.create().matches("", "")); + } + + @Test + void anEmptyConfiguredPlaceholderIsStoredAsTheDefault() throws Exception { + setProperty("authentication.method", "ldap"); + setProperty("users.passwords.externalAuthValue", ""); + SecurityContextHolder.getContext().setAuthentication(UsernamePasswordAuthenticationToken.authenticated( + org.springframework.security.core.userdetails.User.withUsername("ldapuser") + .password("unused").authorities("editor").build(), + null, java.util.List.of())); + try { + User user = CustomUserRegistry.getUserDetailsFromAuthentication(null); + assertEquals("", user.getPassword()); + } finally { + SecurityContextHolder.clearContext(); + } + } + @Test void theEncoderDoesNotMatchThePlaceholder() { // the encoder also checks AtomPub and XML-RPC passwords diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java new file mode 100644 index 000000000..3ef37becb --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java @@ -0,0 +1,203 @@ +/* + * 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.struts2.core; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.apache.roller.weblogger.business.UserManager; +import org.apache.roller.weblogger.business.Weblogger; +import org.apache.roller.weblogger.business.WebloggerFactory; +import org.apache.roller.weblogger.config.WebloggerConfig; +import org.apache.roller.weblogger.pojos.User; +import org.apache.roller.weblogger.ui.struts2.admin.UserEdit; +import org.apache.roller.weblogger.ui.struts2.util.UIAction; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Accounts that log in through LDAP or the servlet container store + * users.passwords.externalAuthValue instead of a password, and that value never + * matches at login. So nobody can choose it as a Roller password. + */ +class ExternalLoginMarkerPasswordTest { + + private static final String RESERVED = "error.add.user.reservedPassword"; + + private final Map savedProperties = new HashMap<>(); + private MockedStatic factory; + private UserManager users; + + @BeforeEach + void setUp() throws Exception { + setProperty("authentication.method", "db"); + setProperty("users.passwords.externalAuthValue", ""); + factory = mockStatic(WebloggerFactory.class); + users = mock(UserManager.class); + Weblogger weblogger = mock(Weblogger.class); + when(weblogger.getUserManager()).thenReturn(users); + factory.when(WebloggerFactory::getWeblogger).thenReturn(weblogger); + } + + @AfterEach + void tearDown() throws Exception { + factory.close(); + Properties config = config(); + savedProperties.forEach((k, v) -> { + if (v == null) { + config.remove(k); + } else { + config.setProperty(k, v); + } + }); + } + + @Test + void registrationRejectsTheMarker() { + Register action = withText(new Register()); + action.getBean().setUserName("newuser"); + action.getBean().setPasswordText(""); + action.getBean().setPasswordConfirm(""); + + action.myValidate(); + + assertTrue(action.getActionErrors().contains(RESERVED)); + } + + @Test + void registrationRejectsTheDefaultMarkerUnderAnotherConfiguredValue() throws Exception { + setProperty("users.passwords.externalAuthValue", ""); + for (String reserved : new String[] {"", ""}) { + Register action = withText(new Register()); + action.getBean().setUserName("newuser"); + action.getBean().setPasswordText(reserved); + action.getBean().setPasswordConfirm(reserved); + + action.myValidate(); + + assertTrue(action.getActionErrors().contains(RESERVED), reserved); + } + } + + @Test + void registrationAcceptsAnOrdinaryPassword() { + Register action = withText(new Register()); + action.getBean().setUserName("newuser"); + action.getBean().setPasswordText("an ordinary password"); + action.getBean().setPasswordConfirm("an ordinary password"); + + action.myValidate(); + + assertFalse(action.hasActionErrors()); + } + + @Test + void theProfileRejectsTheMarker() throws Exception { + User user = new User(); + user.setUserName("dbuser"); + user.setPassword("{bcrypt}existing"); + Profile action = withText(new Profile()); + action.setAuthenticatedUser(user); + action.getBean().setPasswordText(""); + action.getBean().setPasswordConfirm(""); + + assertEquals(UIAction.INPUT, action.save()); + + assertTrue(action.getActionErrors().contains(RESERVED)); + assertEquals("{bcrypt}existing", user.getPassword()); + verify(users, never()).saveUser(any()); + } + + @Test + void anAdministratorCannotGiveAUserTheMarker() throws Exception { + User admin = new User(); + admin.setUserName("admin"); + User user = new User(); + user.setId("user-1"); + user.setUserName("dbuser"); + user.setPassword("{bcrypt}existing"); + when(users.getUser("user-1")).thenReturn(user); + UserEdit action = withText(new UserEdit()); + action.setActionName("modifyUser"); + action.setAuthenticatedUser(admin); + action.getBean().setId("user-1"); + action.myPrepare(); + action.getBean().setPassword(""); + + assertEquals(UIAction.INPUT, action.save()); + + assertTrue(action.getActionErrors().contains(RESERVED)); + assertEquals("{bcrypt}existing", user.getPassword()); + verify(users, never()).saveUser(any()); + } + + @Test + void anAdministratorCannotCreateAUserWithTheMarker() throws Exception { + UserEdit action = withText(new UserEdit()); + User admin = new User(); + admin.setUserName("admin"); + action.setActionName("createUser"); + action.setAuthenticatedUser(admin); + action.myPrepare(); + action.getBean().setUserName("newuser"); + action.getBean().setPassword(""); + + assertEquals(UIAction.INPUT, action.save()); + + assertTrue(action.getActionErrors().contains(RESERVED)); + verify(users, never()).addUser(any()); + } + + private static T withText(T action) { + T spied = spy(action); + doAnswer(call -> call.getArgument(0)).when(spied).getText(anyString()); + doAnswer(call -> call.getArgument(0)).when(spied).getText(anyString(), anyList()); + doAnswer(call -> call.getArgument(0)).when(spied).getText(anyString(), anyString(), anyString()); + return spied; + } + + private void setProperty(String key, String value) throws ReflectiveOperationException { + Properties config = config(); + savedProperties.putIfAbsent(key, config.getProperty(key)); + config.setProperty(key, value); + } + + private static Properties config() throws ReflectiveOperationException { + Field field = WebloggerConfig.class.getDeclaredField("config"); + field.setAccessible(true); + return (Properties) field.get(null); + } +} From 49f9108bd97bfaff2d7cb303995cf5aa82f2393f Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Tue, 17 Nov 2026 19:56:22 -0700 Subject: [PATCH 3/9] Say when a typed password is too long, and keep the generated one out of the form A password over 72 bytes in UTF-8, for example 20 emoji, made BCrypt throw when Register, Profile or UserEdit saved it, so the user got an error page. The forms now check the length first and say the password is too long. Register also put the random password it generates for OIDC users in the form's hidden password fields, so a registration that failed validation, for example on a taken user name, sent it back to the browser. It now keeps that password in the action and only uses it when saving the user. --- .../core/security/RollerPasswordEncoders.java | 17 ++- .../weblogger/ui/struts2/admin/UserEdit.java | 5 +- .../weblogger/ui/struts2/core/Profile.java | 3 + .../weblogger/ui/struts2/core/Register.java | 38 ++++-- .../resources/ApplicationResources.properties | 1 + .../admin/UserEditPasswordLengthTest.java | 43 ++++++ .../core/PasswordFormValidationTest.java | 125 ++++++++++++++++++ 7 files changed, 216 insertions(+), 16 deletions(-) create mode 100644 app/src/test/java/org/apache/roller/weblogger/ui/struts2/admin/UserEditPasswordLengthTest.java create mode 100644 app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index 263102981..9a8208587 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -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; @@ -158,4 +158,19 @@ public boolean upgradeEncoding(String encodedPassword) { public static String randomUnusedPassword() { return RandomStringUtils.secure().nextAlphanumeric(64); } + + /** + * The longest password, in UTF-8 bytes, that every encoder accepts. BCrypt + * refuses longer ones. + */ + 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; + } } diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java index a0aaaf353..63b1c7637 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java @@ -232,7 +232,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"); diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java index 9be587542..aaaf66f9d 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java @@ -145,6 +145,9 @@ public void myValidate() { if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) { addError("userRegister.error.mismatchedPasswords"); } + if (RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { + addError("userRegister.error.passwordTooLong"); + } if (authMethod == AuthMethod.OIDC) { addError("userRegister.error.missingOpenID"); } diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index 48f0a3ce7..16a2e7249 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -70,6 +70,10 @@ public class Register extends UIAction { private String activationCode = null; private ProfileBean bean = new ProfileBean(); + // generated for OIDC users, kept out of the bean so that the form never + // renders it + private String unusedPassword = null; + public Register() { this.pageTitle = "newUser.addNewUser"; } @@ -211,7 +215,9 @@ public String save() { ud.setEnabled(Boolean.TRUE); // If user set both password and passwordConfirm then reset password - if (!StringUtils.isEmpty(getBean().getPasswordText()) && + if (unusedPassword != null) { + ud.resetPassword(unusedPassword); + } else if (!StringUtils.isEmpty(getBean().getPasswordText()) && !StringUtils.isEmpty(getBean().getPasswordConfirm())) { ud.resetPassword(getBean().getPasswordText()); } @@ -383,22 +389,26 @@ public void myValidate() { } // User.password does not allow null, so generate one for OIDC users + unusedPassword = null; if (getAuthMethod().equals(AuthMethod.OIDC.name()) || (getAuthMethod().equals(AuthMethod.DB_OIDC.name()) && !StringUtils.isEmpty(getBean().getOpenIdUrl()))) { - String randomString = RollerPasswordEncoders.randomUnusedPassword(); - getBean().setPasswordText(randomString); - getBean().setPasswordConfirm(randomString); - } - - // the external-login marker is stored for users who log in elsewhere - // and never matches at login - if (!usingSSO && RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) { - addError("error.add.user.reservedPassword"); - } + unusedPassword = RollerPasswordEncoders.randomUnusedPassword(); + } else { + if (RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { + addError("userRegister.error.passwordTooLong"); + return; + } + + // the external-login marker is stored for users who log in + // elsewhere and never matches at login + if (!usingSSO && RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) { + addError("error.add.user.reservedPassword"); + } - // check that passwords match - if (!getBean().getPasswordText().equals(getBean().getPasswordConfirm())) { - addError("userRegister.error.mismatchedPasswords"); + // check that passwords match + if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) { + addError("userRegister.error.mismatchedPasswords"); + } } // check that username is not taken diff --git a/app/src/main/resources/ApplicationResources.properties b/app/src/main/resources/ApplicationResources.properties index 387e4a0ad..a6f61b45f 100644 --- a/app/src/main/resources/ApplicationResources.properties +++ b/app/src/main/resources/ApplicationResources.properties @@ -1522,6 +1522,7 @@ userRegister.button.save=Sign Up userRegister.success.ready=Yes, form appears to be complete. Click the button below. userRegister.error.mismatchedPasswords=Your passwords do not match! +userRegister.error.passwordTooLong=Your password is too long. Use at most 72 characters, or fewer if it has accented letters, symbols or emoji. userRegister.error.missingOpenID=Open ID URL must be provided. userRegister.error.missingOpenIDOrPassword=Either an Open ID URL or a password must be provided. userRegister.error.bothOpenIDAndPassword=Please supply just a password or an OpenID (not both). diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/admin/UserEditPasswordLengthTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/admin/UserEditPasswordLengthTest.java new file mode 100644 index 000000000..56e1c8a7b --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/admin/UserEditPasswordLengthTest.java @@ -0,0 +1,43 @@ +/* + * 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.struts2.admin; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UserEditPasswordLengthTest { + + @Test + void rejectsPasswordTooLongToEncode() { + UserEdit action = new UserEdit() { + @Override + public String getText(String key) { + return key; + } + }; + action.setActionName("createUser"); + action.getBean().setUserName("emoji"); + // 20 emoji, 80 bytes in UTF-8 + action.getBean().setPassword("😀".repeat(20)); + action.myValidate(); + assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + assertEquals(1, action.getActionErrors().size(), action.getActionErrors().toString()); + } +} diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java new file mode 100644 index 000000000..2d822af41 --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java @@ -0,0 +1,125 @@ +/* + * 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.struts2.core; + +import java.lang.reflect.Field; + +import org.apache.roller.weblogger.business.UserManager; +import org.apache.roller.weblogger.business.Weblogger; +import org.apache.roller.weblogger.business.WebloggerFactory; +import org.apache.roller.weblogger.config.AuthMethod; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; + +/** + * Passwords that the encoder can't take get a form error, and a password + * generated for an OIDC user is never put in the form. + */ +class PasswordFormValidationTest { + + // 20 emoji, 80 bytes in UTF-8 + private static final String TOO_LONG = "😀".repeat(20); + // 72 bytes in UTF-8 + private static final String LONGEST = "a".repeat(72); + + @Test + void profileRejectsPasswordTooLongToEncode() { + Profile action = new Profile() { + @Override + public String getText(String key) { + return key; + } + }; + action.getBean().setPasswordText(TOO_LONG); + action.getBean().setPasswordConfirm(TOO_LONG); + action.myValidate(); + assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + } + + @Test + void profileAcceptsLongestPassword() { + Profile action = new Profile() { + @Override + public String getText(String key) { + return key; + } + }; + action.getBean().setPasswordText(LONGEST); + action.getBean().setPasswordConfirm(LONGEST); + action.myValidate(); + assertFalse(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + } + + @Test + void registerRejectsPasswordTooLongToEncode() throws Exception { + Register action = register(AuthMethod.ROLLERDB); + action.getBean().setUserName("emoji"); + action.getBean().setPasswordText(TOO_LONG); + action.getBean().setPasswordConfirm(TOO_LONG); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } + assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + } + + @Test + void registerKeepsGeneratedPasswordOutOfTheForm() throws Exception { + Register action = register(AuthMethod.DB_OIDC); + action.getBean().setUserName("taken"); + action.getBean().setOpenIdUrl("https://idp.example.com#taken"); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } + // the form is shown again with an error, and must not carry the password + assertTrue(action.getActionErrors().contains("error.add.user.userNameInUse")); + assertNull(action.getBean().getPasswordText()); + assertNull(action.getBean().getPasswordConfirm()); + assertNull(action.getBean().getPassword()); + } + + private static Register register(AuthMethod authMethod) throws Exception { + Register action = new Register() { + @Override + public String getText(String key) { + return key; + } + }; + Field field = Register.class.getDeclaredField("authMethod"); + field.setAccessible(true); + field.set(action, authMethod); + return action; + } + + private static MockedStatic mockUserManager() throws Exception { + UserManager userManager = mock(UserManager.class); + when(userManager.getUserByUserName("taken", null)) + .thenReturn(new org.apache.roller.weblogger.pojos.User()); + Weblogger weblogger = mock(Weblogger.class); + when(weblogger.getUserManager()).thenReturn(userManager); + MockedStatic factory = mockStatic(WebloggerFactory.class); + factory.when(WebloggerFactory::getWeblogger).thenReturn(weblogger); + return factory; + } +} From 99d7be7da731df1f6be8a6781b55571c220e2e5e Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Tue, 17 Nov 2026 20:20:09 -0700 Subject: [PATCH 4/9] Check the password length on profiles that also have an OpenID URL Profile only checked a typed password's length when no OpenID URL was given, but it saves a typed password either way, so a long one with an OpenID URL still failed in BCrypt. --- .../weblogger/ui/struts2/core/Profile.java | 6 +++--- .../core/PasswordFormValidationTest.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java index aaaf66f9d..3afc607fd 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java @@ -136,6 +136,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"); @@ -145,9 +148,6 @@ public void myValidate() { if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) { addError("userRegister.error.mismatchedPasswords"); } - if (RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { - addError("userRegister.error.passwordTooLong"); - } if (authMethod == AuthMethod.OIDC) { addError("userRegister.error.missingOpenID"); } diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java index 2d822af41..a3535a2ab 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java @@ -58,6 +58,25 @@ public String getText(String key) { assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); } + @Test + void profileRejectsPasswordTooLongToEncodeWithOpenIdUrl() { + Profile action = new Profile() { + @Override + public String getText(String key) { + return key; + } + }; + action.getBean().setOpenIdUrl("https://idp.example.com#emoji"); + action.getBean().setPasswordText(TOO_LONG); + action.getBean().setPasswordConfirm(TOO_LONG); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } catch (Exception e) { + throw new AssertionError(e); + } + assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + } + @Test void profileAcceptsLongestPassword() { Profile action = new Profile() { From 959a351447facd497f1c6eabc021a8703aec341d Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Tue, 17 Nov 2026 21:46:38 -0700 Subject: [PATCH 5/9] Don't let a stored external-login marker reach the delegate encoder --- .../ui/core/security/RollerPasswordEncoders.java | 5 ++++- .../security/ExternalLoginPlaceholderTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index 263102981..3e1886af3 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -137,7 +137,10 @@ public String encode(CharSequence rawPassword) { @Override public boolean matches(CharSequence rawPassword, String encodedPassword) { - if (rawPassword == null || rawPassword.length() == 0 || isExternalLoginMarker(rawPassword)) { + // a stored marker is checked before the delegate sees it, since a + // marker such as {noop}secret would otherwise match its own suffix + if (rawPassword == null || rawPassword.length() == 0 || isExternalLoginMarker(rawPassword) + || isExternalLoginMarker(encodedPassword)) { return false; } return delegate.matches(rawPassword, encodedPassword); diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java index 12234d3d9..67e35146f 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java @@ -153,6 +153,22 @@ void anEmptyConfiguredPlaceholderIsNotAPassword() throws Exception { assertFalse(RollerPasswordEncoders.create().matches("", "")); } + @Test + void aStoredPlaceholderWithAnEncoderPrefixIsNotAPassword() throws Exception { + setProperty("authentication.method", "ldap"); + setProperty("users.passwords.externalAuthValue", "{noop}secret"); + // as CustomUserRegistry stores the configured placeholder + User user = TestUtils.setupUser("prefixuser"); + userName = user.getUserName(); + user.setPassword("{noop}secret"); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, "secret"))); + assertFalse(RollerPasswordEncoders.create().matches("secret", "{noop}secret")); + } + @Test void anEmptyConfiguredPlaceholderIsStoredAsTheDefault() throws Exception { setProperty("authentication.method", "ldap"); From 2e66914e529d005b7f8ac0f1ea3da64f5d3fa1f2 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Wed, 18 Nov 2026 21:15:34 -0700 Subject: [PATCH 6/9] Make registration null-safe and use one external-login marker for remember-me Registering without a password outside db mode no longer throws a NullPointerException when the passwords are compared. The remember-me signature for LDAP users now takes its placeholder from RollerPasswordEncoders.externalLoginMarker(), so an empty users.passwords.externalAuthValue means the default there as it does everywhere else. With the default configuration the value is unchanged, so existing remember-me cookies stay valid. Also removes the duplicate RollerPasswordEncoders imports, and makes the tests restore WebloggerConfig properties even when user teardown fails or the original value was not set. --- .../security/RollerRememberMeServices.java | 2 +- .../weblogger/ui/struts2/admin/UserEdit.java | 1 - .../weblogger/ui/struts2/core/Profile.java | 1 - .../weblogger/ui/struts2/core/Register.java | 3 +- .../ExternalLoginPlaceholderTest.java | 44 ++++++++++++++----- .../core/ExternalLoginMarkerPasswordTest.java | 16 ++++++- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java index 9e5742bb8..ea8d4d28b 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java @@ -65,7 +65,7 @@ protected String makeTokenSignature(long tokenExpiryTime, String username, Strin // for LDAP we don't store its password in the roller_users table, // just an string indicating external auth method being used. - password = WebloggerConfig.getProperty("users.passwords.externalAuthValue",""); + password = RollerPasswordEncoders.externalLoginMarker(); } String data = username + ":" + tokenExpiryTime + ":" + password + ":" + getKey(); diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java index a0aaaf353..7e66fb995 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/UserEdit.java @@ -41,7 +41,6 @@ import org.apache.roller.weblogger.ui.core.RollerLoginSessionManager; import org.apache.roller.weblogger.ui.struts2.core.Register; import org.apache.roller.weblogger.ui.struts2.util.UIAction; -import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java index 9be587542..49bccca2a 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Profile.java @@ -29,7 +29,6 @@ import org.apache.roller.weblogger.config.WebloggerConfig; import org.apache.roller.weblogger.pojos.User; import org.apache.roller.weblogger.ui.struts2.util.UIAction; -import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index 48f0a3ce7..d80922d7e 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -40,7 +40,6 @@ import org.apache.roller.weblogger.ui.core.security.BootstrapSecurity; import org.apache.roller.weblogger.ui.struts2.util.UIAction; import org.apache.roller.weblogger.util.MailUtil; -import org.apache.roller.weblogger.ui.core.security.RollerPasswordEncoders; import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.interceptor.parameter.StrutsParameter; import org.apache.struts2.interceptor.validation.SkipValidation; @@ -397,7 +396,7 @@ public void myValidate() { } // check that passwords match - if (!getBean().getPasswordText().equals(getBean().getPasswordConfirm())) { + if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) { addError("userRegister.error.mismatchedPasswords"); } diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java index 67e35146f..8f83b8857 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java @@ -58,18 +58,21 @@ void setUp() throws Exception { @AfterEach void tearDown() throws Exception { - if (userName != null) { - TestUtils.teardownUser(userName); - TestUtils.endSession(true); - } - Properties config = config(); - savedProperties.forEach((k, v) -> { - if (v == null) { - config.remove(k); - } else { - config.setProperty(k, v); + try { + if (userName != null) { + TestUtils.teardownUser(userName); + TestUtils.endSession(true); } - }); + } finally { + Properties config = config(); + savedProperties.forEach((k, v) -> { + if (v == null) { + config.remove(k); + } else { + config.setProperty(k, v); + } + }); + } } @Test @@ -185,6 +188,20 @@ void anEmptyConfiguredPlaceholderIsStoredAsTheDefault() throws Exception { } } + @Test + void theRememberMeSignatureUsesTheDefaultForAnEmptyConfiguredPlaceholder() throws Exception { + setProperty("authentication.method", "ldap"); + setProperty("rememberme.enabled", "false"); + RollerRememberMeServices services = new RollerRememberMeServices(new RollerUserDetailsService()); + setProperty("users.passwords.externalAuthValue", ""); + String signedWithTheDefault = services.makeTokenSignature(1L, "ldapuser", "unused"); + + // CustomUserRegistry stores the default for an empty setting + setProperty("users.passwords.externalAuthValue", ""); + + assertEquals(signedWithTheDefault, services.makeTokenSignature(1L, "ldapuser", "unused")); + } + @Test void theEncoderDoesNotMatchThePlaceholder() { // the encoder also checks AtomPub and XML-RPC passwords @@ -201,7 +218,10 @@ private static DaoAuthenticationProvider provider() { private void setProperty(String key, String value) throws ReflectiveOperationException { Properties config = config(); - savedProperties.putIfAbsent(key, config.getProperty(key)); + // keep the first value seen, even when it is null (not set) + if (!savedProperties.containsKey(key)) { + savedProperties.put(key, config.getProperty(key)); + } config.setProperty(key, value); } diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java index 3ef37becb..a76f131f5 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -124,6 +125,16 @@ void registrationAcceptsAnOrdinaryPassword() { assertFalse(action.hasActionErrors()); } + @Test + void registrationWithoutAPasswordDoesNotFail() throws Exception { + // db-oidc does not require a password when the form is validated + setProperty("authentication.method", "db-oidc"); + Register action = withText(new Register()); + action.getBean().setUserName("newuser"); + + assertDoesNotThrow(action::myValidate); + } + @Test void theProfileRejectsTheMarker() throws Exception { User user = new User(); @@ -191,7 +202,10 @@ private static T withText(T action) { private void setProperty(String key, String value) throws ReflectiveOperationException { Properties config = config(); - savedProperties.putIfAbsent(key, config.getProperty(key)); + // keep the first value seen, even when it is null (not set) + if (!savedProperties.containsKey(key)) { + savedProperties.put(key, config.getProperty(key)); + } config.setProperty(key, value); } From 082ad37012906b2a1e6a5da4862e2d62f1cdfacc Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Wed, 18 Nov 2026 21:20:48 -0700 Subject: [PATCH 7/9] Let long legacy passwords log in, and tighten registration password checks A user whose password is stored with an older encoding and is longer than BCrypt's 72 bytes can log in again. The encoder returns no re-encoding for such a password instead of throwing, so the login succeeds and the stored password is left as it is. Registration under db-oidc now asks for a password when neither a password nor an OpenID URL is given, instead of failing when the user is saved. The missing-password error uses error.add.user.missingPassword, which exists in the message bundle. The length check no longer runs for LDAP and container-managed sign-ups, where the form holds the configured placeholder rather than a typed password. The too-long message no longer promises 72 characters, since the limit is in bytes and the form fields are shorter than that. --- .../core/security/RollerPasswordEncoders.java | 15 +++- .../weblogger/ui/struts2/core/Register.java | 9 +- .../resources/ApplicationResources.properties | 2 +- .../ui/core/security/PasswordUpgradeTest.java | 19 +++++ .../core/ExternalLoginMarkerPasswordTest.java | 2 +- .../core/PasswordFormValidationTest.java | 84 ++++++++++++++++++- 6 files changed, 124 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index eeac520bb..9332cfaec 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -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 diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index 4f428e41a..2c59269a4 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -381,9 +381,11 @@ public void myValidate() { } // check password, it is required if OpenID and SSO are disabled - if (AuthMethod.ROLLERDB.name().equals(getAuthMethod()) + if ((AuthMethod.ROLLERDB.name().equals(getAuthMethod()) + || (AuthMethod.DB_OIDC.name().equals(getAuthMethod()) + && StringUtils.isEmpty(getBean().getOpenIdUrl()))) && StringUtils.isEmpty(getBean().getPasswordText())) { - addError("error.add.user.passwordEmpty"); + addError("error.add.user.missingPassword"); return; } @@ -393,7 +395,8 @@ public void myValidate() { (getAuthMethod().equals(AuthMethod.DB_OIDC.name()) && !StringUtils.isEmpty(getBean().getOpenIdUrl()))) { unusedPassword = RollerPasswordEncoders.randomUnusedPassword(); } else { - if (RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { + // (with LDAP or CMA the bean holds the marker, not a typed password) + if (!usingSSO && RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { addError("userRegister.error.passwordTooLong"); return; } diff --git a/app/src/main/resources/ApplicationResources.properties b/app/src/main/resources/ApplicationResources.properties index a6f61b45f..a900c86e6 100644 --- a/app/src/main/resources/ApplicationResources.properties +++ b/app/src/main/resources/ApplicationResources.properties @@ -1522,7 +1522,7 @@ userRegister.button.save=Sign Up userRegister.success.ready=Yes, form appears to be complete. Click the button below. userRegister.error.mismatchedPasswords=Your passwords do not match! -userRegister.error.passwordTooLong=Your password is too long. Use at most 72 characters, or fewer if it has accented letters, symbols or emoji. +userRegister.error.passwordTooLong=Your password is too long. Accented letters, non-Latin characters and emoji take up more room than other characters, so use fewer of them or a shorter password. userRegister.error.missingOpenID=Open ID URL must be provided. userRegister.error.missingOpenIDOrPassword=Either an Open ID URL or a password must be provided. userRegister.error.bothOpenIDAndPassword=Please supply just a password or an OpenID (not both). diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/PasswordUpgradeTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/PasswordUpgradeTest.java index f38522b30..06a18cfca 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/PasswordUpgradeTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/PasswordUpgradeTest.java @@ -100,6 +100,25 @@ void successfulLoginStoresTheConfiguredEncoding() throws Exception { assertEquals(stored, storedPassword(), "an up-to-date hash is left alone"); } + @Test + void aPasswordTooLongToReEncodeStillLogsIn() throws Exception { + // 73 bytes, one more than BCrypt encodes + String longPassword = "a".repeat(73); + String longHash = HexFormat.of().formatHex(MessageDigest.getInstance("SHA-1") + .digest(longPassword.getBytes(StandardCharsets.UTF_8))); + UserManager mgr = WebloggerFactory.getWeblogger().getUserManager(); + User user = mgr.getUserByUserName(userName); + user.setPassword(longHash); + mgr.saveUser(user); + TestUtils.endSession(true); + + assertTrue(provider().authenticate(UsernamePasswordAuthenticationToken.unauthenticated( + userName, longPassword)).isAuthenticated()); + TestUtils.endSession(true); + + assertEquals(longHash, storedPassword()); + } + @Test void failedLoginLeavesThePasswordAlone() throws Exception { assertThrows(BadCredentialsException.class, () -> provider().authenticate( diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java index a76f131f5..3e68e8aec 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/ExternalLoginMarkerPasswordTest.java @@ -127,7 +127,7 @@ void registrationAcceptsAnOrdinaryPassword() { @Test void registrationWithoutAPasswordDoesNotFail() throws Exception { - // db-oidc does not require a password when the form is validated + // neither a password nor an OpenID URL is typed setProperty("authentication.method", "db-oidc"); Register action = withText(new Register()); action.getBean().setUserName("newuser"); diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java index a3535a2ab..c0cbb9eda 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java @@ -17,15 +17,22 @@ package org.apache.roller.weblogger.ui.struts2.core; +import java.io.InputStream; import java.lang.reflect.Field; +import java.util.List; +import java.util.Properties; + +import jakarta.servlet.http.HttpServletRequest; import org.apache.roller.weblogger.business.UserManager; import org.apache.roller.weblogger.business.Weblogger; import org.apache.roller.weblogger.business.WebloggerFactory; import org.apache.roller.weblogger.config.AuthMethod; +import org.apache.roller.weblogger.config.WebloggerConfig; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -43,6 +50,7 @@ class PasswordFormValidationTest { private static final String TOO_LONG = "😀".repeat(20); // 72 bytes in UTF-8 private static final String LONGEST = "a".repeat(72); + private static final String MARKER = "users.passwords.externalAuthValue"; @Test void profileRejectsPasswordTooLongToEncode() { @@ -103,6 +111,62 @@ void registerRejectsPasswordTooLongToEncode() throws Exception { assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); } + @Test + void registerRequiresAPasswordInDatabaseMode() throws Exception { + Register action = register(AuthMethod.ROLLERDB); + action.getBean().setUserName("nopassword"); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } + assertEquals(List.of("error.add.user.missingPassword"), List.copyOf(action.getActionErrors())); + assertTrue(messages().containsKey("error.add.user.missingPassword")); + } + + @Test + void registerRequiresAPasswordWithoutAnOpenIdUrl() throws Exception { + Register action = register(AuthMethod.DB_OIDC); + action.getBean().setUserName("nopassword"); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } + assertEquals(List.of("error.add.user.missingPassword"), List.copyOf(action.getActionErrors())); + } + + @Test + void registerDoesNotMeasureThePlaceholderOfAnExternalLogin() throws Exception { + Properties config = config(); + String saved = config.getProperty(MARKER); + // longer than a typed password may be + config.setProperty(MARKER, "x".repeat(80)); + try (MockedStatic factory = mockUserManager()) { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getUserPrincipal()).thenReturn(() -> "cmauser"); + Register action = new Register() { + @Override + public String getText(String key) { + return key; + } + + @Override + protected HttpServletRequest getServletRequest() { + return request; + } + }; + setAuthMethod(action, AuthMethod.CMA); + + action.myValidate(); + + assertEquals("cmauser", action.getBean().getUserName()); + assertFalse(action.hasActionErrors(), action.getActionErrors().toString()); + } finally { + if (saved == null) { + config.remove(MARKER); + } else { + config.setProperty(MARKER, saved); + } + } + } + @Test void registerKeepsGeneratedPasswordOutOfTheForm() throws Exception { Register action = register(AuthMethod.DB_OIDC); @@ -125,10 +189,28 @@ public String getText(String key) { return key; } }; + setAuthMethod(action, authMethod); + return action; + } + + private static void setAuthMethod(Register action, AuthMethod authMethod) throws Exception { Field field = Register.class.getDeclaredField("authMethod"); field.setAccessible(true); field.set(action, authMethod); - return action; + } + + private static Properties config() throws ReflectiveOperationException { + Field field = WebloggerConfig.class.getDeclaredField("config"); + field.setAccessible(true); + return (Properties) field.get(null); + } + + private static Properties messages() throws Exception { + Properties messages = new Properties(); + try (InputStream in = Register.class.getResourceAsStream("/ApplicationResources.properties")) { + messages.load(in); + } + return messages; } private static MockedStatic mockUserManager() throws Exception { From 1d02baeccedd8b88e35cd4d215211e3d01001387 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 14:34:57 -0700 Subject: [PATCH 8/9] Keep checking a registration after its password is too long A too-long password no longer stops the other checks, so the form also says when the user name is taken or the passwords don't match. --- .../roller/weblogger/ui/struts2/core/Register.java | 1 - .../struts2/core/PasswordFormValidationTest.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java index 2c59269a4..9b48914d7 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/core/Register.java @@ -398,7 +398,6 @@ public void myValidate() { // (with LDAP or CMA the bean holds the marker, not a typed password) if (!usingSSO && RollerPasswordEncoders.isTooLong(getBean().getPasswordText())) { addError("userRegister.error.passwordTooLong"); - return; } // the external-login marker is stored for users who log in diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java index c0cbb9eda..bd8dac1f0 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/core/PasswordFormValidationTest.java @@ -111,6 +111,20 @@ void registerRejectsPasswordTooLongToEncode() throws Exception { assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); } + @Test + void registerReportsATakenUserNameWithATooLongPassword() throws Exception { + Register action = register(AuthMethod.ROLLERDB); + action.getBean().setUserName("taken"); + action.getBean().setPasswordText(TOO_LONG); + action.getBean().setPasswordConfirm(TOO_LONG + "x"); + try (MockedStatic factory = mockUserManager()) { + action.myValidate(); + } + assertTrue(action.getActionErrors().contains("userRegister.error.passwordTooLong")); + assertTrue(action.getActionErrors().contains("userRegister.error.mismatchedPasswords")); + assertTrue(action.getActionErrors().contains("error.add.user.userNameInUse")); + } + @Test void registerRequiresAPasswordInDatabaseMode() throws Exception { Register action = register(AuthMethod.ROLLERDB); From c4a4e257ab04c8e42952dd1b4a7b623ee156cb2b Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 14:34:57 -0700 Subject: [PATCH 9/9] Say why the password length limit applies to every algorithm --- .../weblogger/ui/core/security/RollerPasswordEncoders.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java index 9332cfaec..883f9872e 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java @@ -176,8 +176,10 @@ public static String randomUnusedPassword() { } /** - * The longest password, in UTF-8 bytes, that every encoder accepts. BCrypt - * refuses longer ones. + * 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;