Skip to content

Commit 6dcb3f4

Browse files
annazarubinaphp-coder
authored andcommitted
task(/site/csp/reports): introduce the endpoint for gathering CSP violation reports.
Fix #1058
1 parent abd0ba7 commit 6dcb3f4

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2009-2019 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.feature.site;
19+
20+
import lombok.extern.slf4j.Slf4j;
21+
import org.springframework.http.HttpStatus;
22+
import org.springframework.web.bind.annotation.PostMapping;
23+
import org.springframework.web.bind.annotation.RequestBody;
24+
import org.springframework.web.bind.annotation.ResponseStatus;
25+
import org.springframework.web.bind.annotation.RestController;
26+
27+
@RestController
28+
@Slf4j
29+
public class CspController {
30+
31+
@PostMapping(SiteUrl.CSP_REPORTS_HANDLER)
32+
@ResponseStatus(HttpStatus.NO_CONTENT)
33+
public void handleReport(@RequestBody String body) {
34+
log.warn(body);
35+
}
36+
37+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public SitemapController sitemapController() {
8585
return new SitemapController(seriesService);
8686
}
8787

88+
@Bean
89+
public CspController cspController() {
90+
return new CspController();
91+
}
92+
8893
}
8994

9095
@RequiredArgsConstructor

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public final class SiteUrl {
3939
public static final String SITEMAP_XML = "/sitemap.xml";
4040

4141
public static final String SITE_EVENTS_PAGE = "/site/events";
42+
public static final String CSP_REPORTS_HANDLER = "/site/csp/reports";
4243

4344
public static final String FORBIDDEN_PAGE = "/error/403";
4445
public static final String NOT_FOUND_PAGE = "/error/404";

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected void configure(HttpSecurity http) throws Exception {
135135
// Allow unsecured requests to H2 consoles.
136136
// See also spring.h2.console.path in application-test.properties and
137137
// ContentSecurityPolicyHeaderWriter.H2_CONSOLE_PATTERN
138-
.ignoringAntMatchers("/console/**")
138+
.ignoringAntMatchers("/console/**", SiteUrl.CSP_REPORTS_HANDLER)
139139
.and()
140140
.rememberMe()
141141
// FIXME: GH #27

0 commit comments

Comments
 (0)