|
18 | 18 | package ru.mystamps.web.feature.site;
|
19 | 19 |
|
20 | 20 | import lombok.extern.slf4j.Slf4j;
|
| 21 | +import org.apache.commons.lang3.StringUtils; |
21 | 22 | import org.springframework.http.HttpStatus;
|
22 | 23 | import org.springframework.web.bind.annotation.PostMapping;
|
23 | 24 | import org.springframework.web.bind.annotation.RequestBody;
|
| 25 | +import org.springframework.web.bind.annotation.RequestHeader; |
24 | 26 | import org.springframework.web.bind.annotation.ResponseStatus;
|
25 | 27 | import org.springframework.web.bind.annotation.RestController;
|
26 | 28 |
|
| 29 | +import javax.servlet.http.HttpServletRequest; |
| 30 | + |
27 | 31 | @RestController
|
28 | 32 | @Slf4j
|
29 | 33 | public class CspController {
|
| 34 | + private static final String UNKNOWN = "<unknown>"; |
30 | 35 |
|
31 | 36 | // @todo #1058 /site/csp/reports: add integration tests
|
32 | 37 | @PostMapping(SiteUrl.CSP_REPORTS_HANDLER)
|
33 | 38 | @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); |
35 | 47 | log.warn(body);
|
36 | 48 | }
|
37 | 49 |
|
|
0 commit comments