Skip to content

Commit 49e1760

Browse files
committed
Sanitize siteKey input to prevent log injection
1 parent 3d17e4c commit 49e1760

File tree

1 file changed

+10
-1
lines changed
  • captchaservice-backend/src/main/java/de/muenchen/captchaservice/service/captcha

1 file changed

+10
-1
lines changed

captchaservice-backend/src/main/java/de/muenchen/captchaservice/service/captcha/MetricsService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void recordVerifySuccess(String siteKey, SourceAddress sourceAddress) {
5151

5252
public void recordClientSolveTime(String siteKey, SourceAddress sourceAddress, long solveTime) {
5353
if (solveTime <= 0) {
54-
log.warn("Invalid solve time value: {} for site: {}", solveTime, siteKey);
54+
log.warn("Invalid solve time value: {} for site: {}", solveTime, sanitizeForLog(siteKey));
5555
return;
5656
}
5757

@@ -71,4 +71,13 @@ public void initializeInvalidatedPayloadsGauge() {
7171
.description("Gauge for the number of currently invalidated payloads")
7272
.register(meterRegistry);
7373
}
74+
75+
/**
76+
* Sanitizes user input for logging to prevent log injection.
77+
* Removes newlines and carriage returns.
78+
*/
79+
private static String sanitizeForLog(String input) {
80+
if (input == null) return null;
81+
return input.replaceAll("[\\r\\n]", "");
82+
}
7483
}

0 commit comments

Comments
 (0)