snoopdave commented on code in PR #364:
URL: https://github.com/apache/roller/pull/364#discussion_r4660151484
##########
app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java:
##########
@@ -137,13 +165,39 @@ public String encode(CharSequence rawPassword) {
@Override
public boolean matches(CharSequence rawPassword, String
encodedPassword) {
+ if (rawPassword == null || rawPassword.length() == 0) {
Review Comment:
🐞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:
```java
if (rawPassword == null || rawPassword.length() == 0
|| encodedPassword == null || encodedPassword.isEmpty()) {
return false;
}
```
##########
app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java:
##########
@@ -137,13 +165,39 @@ public String encode(CharSequence rawPassword) {
@Override
public boolean matches(CharSequence rawPassword, String
encodedPassword) {
+ if (rawPassword == null || rawPassword.length() == 0) {
+ return false;
+ }
+ Set<String> 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)) {
+ return false;
+ }
+ if (markers.contains(rawPassword.toString())) {
+ logRefusal();
+ 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) {
Review Comment:
🐞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:
```java
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]