From 2dc0ef023769415a88736a814519aebdd93b89b4 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Thu, 19 Nov 2026 17:38:24 -0700 Subject: [PATCH 1/6] Recognize previously configured external-login markers Accounts created before users.passwords.externalAuthValue changed still have the old marker stored, encoded or not, and the encoder only recognized the current marker and the default, so the old marker matched at login. The new users.passwords.externalAuthValue.previous setting lists earlier markers, which are refused at login and can't be chosen as passwords, the same as the current one. Empty entries are ignored so an empty password never counts as a marker. --- .../core/security/RollerPasswordEncoders.java | 29 +++++++++---- .../roller/weblogger/config/roller.properties | 5 +++ .../ExternalLoginPlaceholderTest.java | 42 +++++++++++++++++++ 3 files changed, 69 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 3e1886af3..691212ba4 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 @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.roller.weblogger.config.WebloggerConfig; @@ -57,14 +58,28 @@ public static String externalLoginMarker() { } /** - * 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. + * Whether a password is the configured external-login marker, the default + * one, or one listed in users.passwords.externalAuthValue.previous, which + * accounts may still have stored from before the setting changed. None of + * them matches at login, so none 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)); + if (password == null) { + return false; + } + if (externalLoginMarker().contentEquals(password) + || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password)) { + return true; + } + String previous = WebloggerConfig.getProperty("users.passwords.externalAuthValue.previous"); + for (String marker : StringUtils.split(StringUtils.defaultString(previous), ',')) { + // an empty entry is never a marker, so an empty password isn't one + String trimmed = marker.trim(); + if (!trimmed.isEmpty() && trimmed.contentEquals(password)) { + return true; + } + } + return false; } @SuppressWarnings("deprecation") @@ -126,7 +141,7 @@ 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, and neither do - * the default placeholder and an empty password. + * the default or a previous placeholder and an empty password. */ private record ExternalLoginAware(PasswordEncoder delegate) implements PasswordEncoder { diff --git a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties index 970dac6f4..000a7411e 100644 --- a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties +++ b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties @@ -360,6 +360,11 @@ weblog.inlineImages.maxFieldBytes=60000 # Empty value used for passphrase in roller_user table when LDAP, CMA, or OIDC used. users.passwords.externalAuthValue= +# Comma-separated values that users.passwords.externalAuthValue had before. +# Accounts created then still have them stored, so list them here when changing +# that setting; none of them is accepted as a password. +users.passwords.externalAuthValue.previous= + # OIDC provider configuration. To configure a provider, set all three required # properties using the pattern oidc.{registrationId}.{property}. # Multiple providers can be configured with different registration IDs. 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 8f83b8857..50ca127e5 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 @@ -139,6 +139,48 @@ void theDefaultPlaceholderIsNotAPasswordUnderAnotherConfiguredValue() throws Exc assertFalse(RollerPasswordEncoders.create().matches("", "")); } + @Test + void aPreviousEncodedPlaceholderIsNotAPasswordAfterTheSettingChanges() throws Exception { + setProperty("authentication.method", "cma"); + // as Register stored it for container-managed sign-ups + User user = TestUtils.setupUser("oldcmauser"); + userName = user.getUserName(); + user.setPassword(RollerPasswordEncoders.create().encode("")); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + setProperty("users.passwords.externalAuthValue", ""); + setProperty("users.passwords.externalAuthValue.previous", ","); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + } + + @Test + void aPreviousUnencodedPlaceholderIsNotAPasswordAfterTheSettingChanges() throws Exception { + setProperty("authentication.method", "ldap"); + setProperty("users.passwords.externalAuthValue", ""); + setProperty("users.passwords.externalAuthValue.previous", "{noop}secret"); + // as CustomUserRegistry stored it before the setting changed + User user = TestUtils.setupUser("oldldapuser"); + userName = user.getUserName(); + user.setPassword("{noop}secret"); + WebloggerFactory.getWeblogger().getUserManager().saveUser(user); + TestUtils.endSession(true); + + assertThrows(AuthenticationException.class, () -> provider().authenticate( + UsernamePasswordAuthenticationToken.unauthenticated(userName, "secret"))); + } + + @Test + void emptyEntriesInThePreviousPlaceholdersAreIgnored() throws Exception { + setProperty("users.passwords.externalAuthValue.previous", ",, ,"); + + assertTrue(RollerPasswordEncoders.isExternalLoginMarker("")); + assertFalse(RollerPasswordEncoders.isExternalLoginMarker("")); + assertFalse(RollerPasswordEncoders.isExternalLoginMarker(" ")); + } + @Test void anEmptyConfiguredPlaceholderIsNotAPassword() throws Exception { setProperty("authentication.method", "db"); From e2aca52d388c90251535e424316787fa187a9e71 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 13:56:42 -0700 Subject: [PATCH 2/6] Refuse a password that BCrypt treats as equal to an external-login marker BCrypt gives some passwords other than a marker the same hash as the marker, so an exact comparison with the marker isn't enough to keep it from matching. After the delegate matches, the encoder now also checks whether the current, default or a previous marker matches the stored value, and refuses the password if one does. The marker list is read once per check. --- .../core/security/RollerPasswordEncoders.java | 50 +++++++++++++------ .../ExternalLoginPlaceholderTest.java | 18 +++++++ 2 files changed, 54 insertions(+), 14 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 691212ba4..6674798b5 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 @@ -19,7 +19,9 @@ import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; @@ -64,22 +66,27 @@ public static String externalLoginMarker() { * them matches at login, so none can be chosen as a Roller password. */ public static boolean isExternalLoginMarker(CharSequence password) { - if (password == null) { - return false; - } - if (externalLoginMarker().contentEquals(password) - || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password)) { - return true; - } + return password != null && externalLoginMarkers().contains(password.toString()); + } + + /** + * The configured marker, the default one and the previous ones. The + * previous ones are a comma-separated list, so a marker that contains a + * comma can't be listed there. + */ + private static Set externalLoginMarkers() { + Set markers = new LinkedHashSet<>(); + markers.add(externalLoginMarker()); + markers.add(DEFAULT_EXTERNAL_LOGIN_MARKER); String previous = WebloggerConfig.getProperty("users.passwords.externalAuthValue.previous"); for (String marker : StringUtils.split(StringUtils.defaultString(previous), ',')) { // an empty entry is never a marker, so an empty password isn't one String trimmed = marker.trim(); - if (!trimmed.isEmpty() && trimmed.contentEquals(password)) { - return true; + if (!trimmed.isEmpty()) { + markers.add(trimmed); } } - return false; + return markers; } @SuppressWarnings("deprecation") @@ -141,7 +148,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, and neither do - * the default or a previous placeholder and an empty password. + * the default or a previous placeholder, a password the delegate treats as + * equal to one of them, and an empty password. */ private record ExternalLoginAware(PasswordEncoder delegate) implements PasswordEncoder { @@ -152,13 +160,27 @@ public String encode(CharSequence rawPassword) { @Override public boolean matches(CharSequence rawPassword, String encodedPassword) { + if (rawPassword == null || rawPassword.length() == 0) { + return false; + } + Set markers = externalLoginMarkers(); // 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)) { + if (markers.contains(encodedPassword) || markers.contains(rawPassword.toString())) { + return false; + } + if (!delegate.matches(rawPassword, encodedPassword)) { return false; } - return delegate.matches(rawPassword, encodedPassword); + // BCrypt, for one, treats some other passwords as equal to a + // marker, so refuse any password whose stored value a marker + // matches too + for (String marker : markers) { + if (delegate.matches(marker, encodedPassword)) { + return false; + } + } + return true; } @Override 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 50ca127e5..89824c8fa 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 @@ -33,6 +33,7 @@ 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.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -252,6 +253,23 @@ void theEncoderDoesNotMatchThePlaceholder() { assertTrue(encoder.matches("secret", encoder.encode("secret"))); } + @Test + void aPasswordThatBcryptTreatsAsEqualToThePlaceholderNeverMatches() throws Exception { + setProperty("users.passwords.externalAuthValue", ""); + setProperty("users.passwords.externalAuthValue.previous", ""); + PasswordEncoder encoder = RollerPasswordEncoders.create(); + for (String marker : new String[] {"", "", ""}) { + String stored = encoder.encode(marker); + // BCrypt repeats its key, a NUL byte after each copy, so this + // password gives the same hash as the placeholder + String sameKey = marker + '\0' + marker; + assertTrue(new BCryptPasswordEncoder().matches(sameKey, stored.substring("{bcrypt}".length()))); + assertFalse(encoder.matches(sameKey, stored), marker); + } + // a password that only starts like a placeholder still matches + assertTrue(encoder.matches("x", encoder.encode("x"))); + } + private static DaoAuthenticationProvider provider() { DaoAuthenticationProvider provider = new DaoAuthenticationProvider(new RollerUserDetailsService()); provider.setPasswordEncoder(RollerPasswordEncoders.create()); From 5f2b28116c786ef37397e15d15f2d9f7db84b234 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 13:57:01 -0700 Subject: [PATCH 3/6] Log when a password is refused as an external-login marker An account whose real password equals the current, default or a previous marker can't log in, and until now the log didn't say why. The encoder now logs an info line for that refusal, without the password, so an administrator can tell it from a wrong password and set a new one. --- .../ui/core/security/RollerPasswordEncoders.java | 14 +++++++++++++- 1 file changed, 13 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 6674798b5..c029dc42f 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 @@ -166,7 +166,11 @@ public boolean matches(CharSequence rawPassword, String encodedPassword) { Set markers = externalLoginMarkers(); // a stored marker is checked before the delegate sees it, since a // marker such as {noop}secret would otherwise match its own suffix - if (markers.contains(encodedPassword) || markers.contains(rawPassword.toString())) { + if (markers.contains(encodedPassword)) { + return false; + } + if (markers.contains(rawPassword.toString())) { + logRefusal(); return false; } if (!delegate.matches(rawPassword, encodedPassword)) { @@ -177,12 +181,20 @@ public boolean matches(CharSequence rawPassword, String encodedPassword) { // matches too for (String marker : markers) { if (delegate.matches(marker, encodedPassword)) { + logRefusal(); return false; } } return true; } + private static void logRefusal() { + // the password itself is never logged + log.info("Refused a password that Roller treats as an external-login marker" + + " (users.passwords.externalAuthValue or its .previous list). An" + + " administrator can set a new password for an account that uses one."); + } + @Override public boolean upgradeEncoding(String encodedPassword) { return delegate.upgradeEncoding(encodedPassword); From 0009ac812d1e93832769771c1a6b2a369264bf2d Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 13:57:09 -0700 Subject: [PATCH 4/6] Document the limits of users.passwords.externalAuthValue.previous The list is comma-separated, so a marker that contains a comma can't be listed there. roller.properties now says so, along with listing earlier values in the same restart that changes the setting and the accounts that need an administrator to set a new password. Roller also logs a warning at startup when the configured marker contains a comma. --- .../weblogger/ui/core/security/RollerPasswordEncoders.java | 5 +++++ .../org/apache/roller/weblogger/config/roller.properties | 5 ++++- 2 files changed, 9 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 c029dc42f..94e07cf97 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 @@ -141,6 +141,11 @@ public static PasswordEncoder create() { log.info("Password Encryption Algorithm set to '" + algorithm + "'"); + if (externalLoginMarker().contains(",")) { + log.warn("users.passwords.externalAuthValue contains a comma, so it can't be listed in" + + " users.passwords.externalAuthValue.previous if the setting changes later."); + } + return new ExternalLoginAware(new DelegatingPasswordEncoder(algorithm, encoders)); } diff --git a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties index 000a7411e..c72d50fc6 100644 --- a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties +++ b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties @@ -362,7 +362,10 @@ users.passwords.externalAuthValue= # Comma-separated values that users.passwords.externalAuthValue had before. # Accounts created then still have them stored, so list them here when changing -# that setting; none of them is accepted as a password. +# that setting, in the same restart; none of them is accepted as a password. +# A value that contains a comma can't be listed, and an account that has logged +# in with an earlier value, or whose own password is one of them, needs an +# administrator to set a new password. users.passwords.externalAuthValue.previous= # OIDC provider configuration. To configure a provider, set all three required From 71e2ac71cd94c49a8992e902fc099e39b0884266 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 13:59:13 -0700 Subject: [PATCH 5/6] Test previous external-login markers in the password forms and the encoder ExternalLoginMarkerPasswordTest now checks that registration, the profile page and user administration refuse a marker listed in users.passwords.externalAuthValue.previous, and its tearDown restores the configuration in a finally block. The provider tests for previous markers also check the encoder directly, and the list test covers spaces around an entry. --- .../ExternalLoginPlaceholderTest.java | 5 +- .../core/ExternalLoginMarkerPasswordTest.java | 57 ++++++++++++++++--- 2 files changed, 53 insertions(+), 9 deletions(-) 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 89824c8fa..a4d0249de 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 @@ -155,6 +155,7 @@ void aPreviousEncodedPlaceholderIsNotAPasswordAfterTheSettingChanges() throws Ex assertThrows(AuthenticationException.class, () -> provider().authenticate( UsernamePasswordAuthenticationToken.unauthenticated(userName, ""))); + assertFalse(RollerPasswordEncoders.create().matches("", user.getPassword())); } @Test @@ -171,12 +172,14 @@ void aPreviousUnencodedPlaceholderIsNotAPasswordAfterTheSettingChanges() throws assertThrows(AuthenticationException.class, () -> provider().authenticate( UsernamePasswordAuthenticationToken.unauthenticated(userName, "secret"))); + assertFalse(RollerPasswordEncoders.create().matches("secret", "{noop}secret")); } @Test void emptyEntriesInThePreviousPlaceholdersAreIgnored() throws Exception { - setProperty("users.passwords.externalAuthValue.previous", ",, ,"); + setProperty("users.passwords.externalAuthValue.previous", ", ,, ,"); + assertTrue(RollerPasswordEncoders.isExternalLoginMarker("")); assertTrue(RollerPasswordEncoders.isExternalLoginMarker("")); assertFalse(RollerPasswordEncoders.isExternalLoginMarker("")); assertFalse(RollerPasswordEncoders.isExternalLoginMarker(" ")); 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..ec4220276 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 @@ -75,15 +75,20 @@ void setUp() throws Exception { @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); + try { + if (factory != null) { + factory.close(); } - }); + } finally { + Properties config = config(); + savedProperties.forEach((k, v) -> { + if (v == null) { + config.remove(k); + } else { + config.setProperty(k, v); + } + }); + } } @Test @@ -192,6 +197,42 @@ void anAdministratorCannotCreateAUserWithTheMarker() throws Exception { verify(users, never()).addUser(any()); } + @Test + void theFormsRejectAPreviousMarker() throws Exception { + setProperty("users.passwords.externalAuthValue.previous", ", "); + + Register register = withText(new Register()); + register.getBean().setUserName("newuser"); + register.getBean().setPasswordText(""); + register.getBean().setPasswordConfirm(""); + register.myValidate(); + assertTrue(register.getActionErrors().contains(RESERVED)); + + User user = new User(); + user.setUserName("dbuser"); + user.setPassword("{bcrypt}existing"); + Profile profile = withText(new Profile()); + profile.setAuthenticatedUser(user); + profile.getBean().setPasswordText(""); + profile.getBean().setPasswordConfirm(""); + assertEquals(UIAction.INPUT, profile.save()); + assertTrue(profile.getActionErrors().contains(RESERVED)); + + User admin = new User(); + admin.setUserName("admin"); + UserEdit userEdit = withText(new UserEdit()); + userEdit.setActionName("createUser"); + userEdit.setAuthenticatedUser(admin); + userEdit.myPrepare(); + userEdit.getBean().setUserName("newuser"); + userEdit.getBean().setPassword(""); + assertEquals(UIAction.INPUT, userEdit.save()); + assertTrue(userEdit.getActionErrors().contains(RESERVED)); + + verify(users, never()).saveUser(any()); + verify(users, never()).addUser(any()); + } + private static T withText(T action) { T spied = spy(action); doAnswer(call -> call.getArgument(0)).when(spied).getText(anyString()); From 9aa936fe12767a4a9da8e4780db1a679fb04e919 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Fri, 20 Nov 2026 13:59:22 -0700 Subject: [PATCH 6/6] Mention users.passwords.externalAuthValue.previous in CHANGES --- CHANGES.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b2240dc96..0f0307fae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -57,8 +57,11 @@ - **New passwords can't be the external-login placeholder.** Registration, the profile page and user administration refuse `users.passwords.externalAuthValue` (by default ``) as a - password, and it never works as one. An administrator can set a new password - for an account that used it (#304). + password, and it never works as one. When you change that setting, list its + earlier values in the new `users.passwords.externalAuthValue.previous` + (comma-separated) so they're treated the same. A login refused for this + reason is logged, and an administrator can set a new password for an + account that used one (#304, #364). - **Roller UI stylesheets, scripts and images don't start a session** (#310). - **The LDAP comment authenticator escapes the commenter's user name** when it builds the bind name (#322).