Skip to content

Commit d0e9268

Browse files
committed
chore(/site/csp/reports): include user's IP and agent into log message.
Fix #1112
1 parent 52c290a commit d0e9268

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/ru/mystamps/web/feature/site/CspController.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,32 @@
1818
package ru.mystamps.web.feature.site;
1919

2020
import lombok.extern.slf4j.Slf4j;
21+
import org.apache.commons.lang3.StringUtils;
2122
import org.springframework.http.HttpStatus;
2223
import org.springframework.web.bind.annotation.PostMapping;
2324
import org.springframework.web.bind.annotation.RequestBody;
25+
import org.springframework.web.bind.annotation.RequestHeader;
2426
import org.springframework.web.bind.annotation.ResponseStatus;
2527
import org.springframework.web.bind.annotation.RestController;
2628

29+
import javax.servlet.http.HttpServletRequest;
30+
2731
@RestController
2832
@Slf4j
2933
public class CspController {
34+
private static final String UNKNOWN = "<unknown>";
3035

3136
// @todo #1058 /site/csp/reports: add integration tests
3237
@PostMapping(SiteUrl.CSP_REPORTS_HANDLER)
3338
@ResponseStatus(HttpStatus.NO_CONTENT)
34-
public void handleReport(@RequestBody String body) {
39+
public void handleReport(
40+
@RequestBody String body,
41+
HttpServletRequest request,
42+
@RequestHeader(name = "user-agent", defaultValue = UNKNOWN) String userAgent) {
43+
44+
String ip = StringUtils.defaultString(request.getRemoteAddr(), UNKNOWN);
45+
46+
log.warn("CSP report from IP: {}, user agent: {}", ip, userAgent);
3547
log.warn(body);
3648
}
3749

0 commit comments

Comments
 (0)