Skip to content

Recognize previously configured external-login markers - #364

Open
mraible wants to merge 6 commits into
masterfrom
previous-external-login-markers
Open

mraible wants to merge 6 commits into
masterfrom
previous-external-login-markers

Conversation

@mraible

@mraible mraible commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

A follow-up to #304, from Dave's review of its 6.1.x twin #306.

When an admin changes users.passwords.externalAuthValue, accounts created earlier still store the old marker, encoded or not, and Roller only recognized the current marker and the default <externalAuth>.

  • The new users.passwords.externalAuthValue.previous setting takes a comma-separated list of earlier markers. They're refused at login and can't be chosen as passwords, the same as the current one. Empty entries are ignored, so an empty password field never counts as a marker.
  • BCrypt treats some other passwords as equal to a marker, so after the delegate encoder matches, the encoder also checks the current, default and previous markers against the stored value and refuses the password if one matches.
  • A login refused because the password is a marker is logged at info level, without the password, so an admin can tell it from a wrong password.
  • roller.properties documents the setting with an empty default, and says that a marker containing a comma can't be listed, that earlier values should be listed in the same restart that changes the setting, and which accounts need an administrator to set a new password. Roller logs a warning at startup when the configured marker contains a comma.
  • CHANGES.md mentions the new setting in the existing placeholder entry.

ExternalLoginPlaceholderTest covers an earlier marker stored encoded and unencoded, empty and spaced entries in the list, and a password that BCrypt treats as equal to the current, default or a previous marker. ExternalLoginMarkerPasswordTest checks that registration, the profile page and user administration refuse a previous marker. #306 has the same change for 6.1.x.

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.
…rker

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.
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.
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.
…coder

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.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR-Review: 2 inline comments posted. The two focused test classes pass locally on JDK 25 (21 tests). Otherwise this matches #306 and looks good to merge.

// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞Claude Issue: Important: Each successful login now runs one more delegate match for every marker. With BCrypt, that is one more full hash for each marker: 2 in total with the default setting, 3 or more with a custom marker or a .previous list. A BCrypt collision with a marker shorter than 71 bytes needs a password that contains NUL. Otherwise the password must be at least 72 UTF-8 bytes long (truncation). So the loop can run only in those cases, for example:

String raw = rawPassword.toString();
if (raw.indexOf('\0') >= 0 || raw.getBytes(StandardCharsets.UTF_8).length >= 72) {
    for (String marker : markers) { ... }
}

The tests still cover this, because sameKey contains NUL. The same change applies to ExternalLoginAwarePasswordEncoder on 6.1.x.


@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
if (rawPassword == null || rawPassword.length() == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞Claude Issue: Important: The 6.1.x twin (#306) also returns false for a null or empty encodedPassword before the delegate sees it ("the delegate can throw for a missing or empty stored value"). Here, without lazyUpgradeFrom, DelegatingPasswordEncoder throws IllegalArgumentException for a stored value with no {id}. That makes the login fail with an error instead of a bad-credentials result. Add the same guard so both branches behave the same:

if (rawPassword == null || rawPassword.length() == 0
        || encodedPassword == null || encodedPassword.isEmpty()) {
    return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants