Skip to content

Upgrade passwords stored with an older encoding at login - #301

Merged
mraible merged 2 commits into
apache:masterfrom
mraible:upgrade-password-encoding
Nov 17, 2026
Merged

mraible merged 2 commits into
apache:masterfrom
mraible:upgrade-password-encoding

Conversation

@mraible

@mraible mraible commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

passwds.encryption.lazyUpgradeFrom (SHA by default) lets passwords from older Roller versions verify, but nothing stored them again, so they stayed in the old encoding however often their owners logged in. On a 7.0.0 RC1 site with algorithm=bcrypt and lazyUpgradeFrom=SHA, all nine accounts still had their 40-character unsalted SHA-1 hashes after repeated successful logins.

Spring Security re-encodes a password after a successful login only when the login provider has a UserDetailsPasswordService, and Roller's didn't.

  • RollerUserDetailsService now implements UserDetailsPasswordService and saves the re-encoded password. RollerContext gives it to the database login provider, next to the password encoder.
  • Nothing is stored when the re-encoded password would be plain text ({noop}), which happens while passwds.encryption.enabled is off or passwds.encryption.algorithm is noop. Otherwise a login would turn bcrypt hashes into stored passwords.
  • The password encoder factory moves unchanged from RollerContext to RollerPasswordEncoders, so the test can use the same encoder. Configure Spring Security in Java instead of security.xml #300 makes the same move.
  • New PasswordUpgradeTest logs in through Spring's DaoAuthenticationProvider against the test database, with a user whose password is an unprefixed SHA-1 hash:
    • a successful login stores a {bcrypt} hash, the next login still works, and an up-to-date hash isn't rewritten;
    • a failed login leaves the stored hash alone;
    • with encryption off, or with algorithm=noop, nothing is stored.
      The first test fails without the change.
  • mvn install passes on JDK 21 (735 tests, 1 skipped).
  • CHANGES has a bug-fix entry.

passwds.encryption.lazyUpgradeFrom let passwords from older Roller versions verify, but nothing stored them again, so they stayed in the old encoding however often their owners logged in. RollerUserDetailsService now implements UserDetailsPasswordService, and RollerContext gives it to the database login provider, so Spring Security stores the password with passwds.encryption.algorithm after a successful login. Nothing is stored while passwds.encryption.enabled is off, since the re-encoding would then be plain text.

The password encoder factory moves from RollerContext to RollerPasswordEncoders so the new PasswordUpgradeTest can log in with the encoder Roller uses.

@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: 1 inline comment posted.

The guard only checked passwds.encryption.enabled, but passwds.encryption.algorithm=noop with encryption enabled also re-encodes as {noop}, which would have stored plain text after a login. RollerUserDetailsService now skips any re-encoded password that starts with {noop}, which covers both settings. PasswordUpgradeTest adds a case for algorithm=noop.
@mraible

mraible commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Tested at f69e6f9 on a copy of a real site whose accounts still have 40-character unprefixed SHA-1 hashes: built alone on master, MySQL 8.4, passwds.encryption.enabled=true, algorithm=bcrypt, lazyUpgradeFrom=SHA, logging in through the form behind Apache httpd and a TLS proxy. Stored values were compared by format, length and a fingerprint, never read.

  • Wrong password for two accounts on SHA-1: 302 to login.rol?error=true, and both rows unchanged.
  • First successful login for an account with an unprefixed lowercase SHA-1 hash: the row became a 68-character {bcrypt} hash, and the log shows "Stored the re-encoded password of …" once at INFO.
  • Second login for that account works, and the row isn't rewritten.
  • An account already on {bcrypt} logs in, and its row is unchanged.
  • An account that didn't log in keeps its SHA-1 hash, and the log has no SEVERE or ERROR lines.

Not covered: XML-RPC and AtomPub logins (they verify old hashes but don't re-hash them), and the noop cases, which PasswordUpgradeTest covers. Logins were scripted with curl, and the upgraded account used a test password stored in the old format.

mraible added a commit to mraible/roller that referenced this pull request Nov 17, 2026
Rebased on apache#301, SecurityConfig gives the database login provider the user service as its UserDetailsPasswordService. SecurityConfigTest logs in through the filter chain as a user with an unsalted SHA-1 hash and checks that the stored password becomes {bcrypt}.

@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.

LGTM

@mraible
mraible merged commit 3bceae2 into apache:master Nov 17, 2026
9 checks passed
@mraible
mraible deleted the upgrade-password-encoding branch November 17, 2026 03:45
mraible added a commit to mraible/roller that referenced this pull request Nov 17, 2026
Rebased on apache#301, SecurityConfig gives the database login provider the user service as its UserDetailsPasswordService. SecurityConfigTest logs in through the filter chain as a user with an unsalted SHA-1 hash and checks that the stored password becomes {bcrypt}.
mraible added a commit to mraible/roller that referenced this pull request Nov 17, 2026
Rebased on apache#301, SecurityConfig gives the database login provider the user service as its UserDetailsPasswordService. SecurityConfigTest logs in through the filter chain as a user with an unsalted SHA-1 hash and checks that the stored password becomes {bcrypt}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants