Skip to content

Commit b36ebc3

Browse files
committed
refactor(CspController): don't include "original-policy" field into logs.
Fix #1242
1 parent 3f0d4c4 commit b36ebc3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
import org.springframework.web.bind.annotation.RestController;
2828

2929
import javax.servlet.http.HttpServletRequest;
30+
import java.util.regex.Pattern;
3031

3132
@RestController
3233
@Slf4j
3334
public class CspController {
3435
private static final String UNKNOWN = "<unknown>";
3536

37+
private static final Pattern ORIGINAL_POLICY_PATTERN = Pattern.compile(
38+
"\"original-policy\":\"[^\"]+\","
39+
);
40+
3641
@PostMapping(SiteUrl.CSP_REPORTS_HANDLER)
3742
@ResponseStatus(HttpStatus.NO_CONTENT)
3843
public void handleReport(
@@ -41,9 +46,11 @@ public void handleReport(
4146
@RequestHeader(name = "user-agent", defaultValue = UNKNOWN) String userAgent) {
4247

4348
String ip = StringUtils.defaultString(request.getRemoteAddr(), UNKNOWN);
44-
4549
log.warn("CSP report from IP: {}, user agent: {}", ip, userAgent);
46-
log.warn(body);
50+
51+
// Omit "original-policy" as it quite long and useless most of the time
52+
String report = ORIGINAL_POLICY_PATTERN.matcher(body).replaceFirst(StringUtils.EMPTY);
53+
log.warn(report);
4754
}
4855

4956
}

0 commit comments

Comments
 (0)