Copilot commented on code in PR #133:
URL:
https://github.com/apache/fineract-consumer-facing/pull/133#discussion_r3952712825
##########
consumer/src/main/java/org/apache/fineract/consumer/infrastructure/stepup/service/StepUpTokenService.java:
##########
@@ -46,27 +46,34 @@ public class StepUpTokenService {
private final JwtIssuer jwtIssuer;
private final JwtDecoder jwtDecoder;
- public String actionFingerprint(String endpoint, Long fromAccountId, Long
toAccountId, BigDecimal amount) {
- String canonical =
- endpoint + "|" + fromAccountId + "|" + toAccountId + "|" +
amount.stripTrailingZeros().toPlainString();
- return hash(canonical);
- }
-
- public String actionFingerprint(
- String endpoint, Long fromAccountId, Long toAccountId, String
toAccountType, BigDecimal amount) {
- String canonical = endpoint + "|" + fromAccountId + "|" + toAccountId
+ "|" + toAccountType + "|"
- + amount.stripTrailingZeros().toPlainString();
- return hash(canonical);
- }
-
- public String actionFingerprint(String endpoint, Long fromAccountId, Long
toAccountId) {
- String canonical = endpoint + "|" + fromAccountId + "|" + toAccountId;
- return hash(canonical);
+ public String actionFingerprint(String endpoint, Object... parts) {
+ // String.valueOf preserves the prior null-endpoint behavior
("null|...") without NPE.
+ StringBuilder canonical = new
StringBuilder(String.valueOf(endpoint)).append('|');
+ for (int i = 0; i < parts.length; i++) {
+ if (i > 0) {
+ canonical.append('|');
+ }
+ canonical.append(fingerprintPart(parts[i]));
+ }
+ return hash(canonical.toString());
}
Review Comment:
`actionFingerprint(String, Object...)` will throw a NullPointerException if
a caller passes a null varargs array explicitly (e.g.
`actionFingerprint(endpoint, (Object[]) null)`). Varargs methods commonly
receive null arrays from accidental casts; treating null as "no parts" keeps
behavior robust and avoids unexpected 500s.
##########
consumer/src/main/java/org/apache/fineract/consumer/infrastructure/stepup/service/StepUpTokenService.java:
##########
@@ -46,27 +46,34 @@ public class StepUpTokenService {
private final JwtIssuer jwtIssuer;
private final JwtDecoder jwtDecoder;
- public String actionFingerprint(String endpoint, Long fromAccountId, Long
toAccountId, BigDecimal amount) {
- String canonical =
- endpoint + "|" + fromAccountId + "|" + toAccountId + "|" +
amount.stripTrailingZeros().toPlainString();
- return hash(canonical);
- }
-
- public String actionFingerprint(
- String endpoint, Long fromAccountId, Long toAccountId, String
toAccountType, BigDecimal amount) {
- String canonical = endpoint + "|" + fromAccountId + "|" + toAccountId
+ "|" + toAccountType + "|"
- + amount.stripTrailingZeros().toPlainString();
- return hash(canonical);
- }
-
- public String actionFingerprint(String endpoint, Long fromAccountId, Long
toAccountId) {
- String canonical = endpoint + "|" + fromAccountId + "|" + toAccountId;
- return hash(canonical);
+ public String actionFingerprint(String endpoint, Object... parts) {
+ // String.valueOf preserves the prior null-endpoint behavior
("null|...") without NPE.
+ StringBuilder canonical = new
StringBuilder(String.valueOf(endpoint)).append('|');
+ for (int i = 0; i < parts.length; i++) {
+ if (i > 0) {
+ canonical.append('|');
+ }
+ canonical.append(fingerprintPart(parts[i]));
+ }
Review Comment:
The canonicalization uses `|` as an unescaped separator while allowing
arbitrary `String` parts. If any user-controlled field contains `|`, two
different logical tuples can canonicalize to the same string (e.g. parts
`["a|b","c"]` vs `["a","b|c"]`), enabling an action-fingerprint collision for
step-up verification. Consider an unambiguous encoding (length-prefix each
part, or escape `|` and the escape char) so different part boundaries can never
produce the same canonical string.
--
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]