Skip to content

Commit 983b479

Browse files
committed
ContentSecurityPolicyHeaderWriter: allow AJAX only on /series/add page.
Addressed to #226
1 parent 48d9b40 commit 983b479

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
8484
// - 'https://www.gstatic.com' is required by Google Charts
8585
private static final String SCRIPT_COLLECTION_INFO = " 'unsafe-eval' https://www.gstatic.com";
8686

87-
// - 'self' is required for AJAX requests from our scripts (country suggestions)
87+
// - 'self' is required for AJAX requests from our scripts (country suggestions on /series/add)
8888
private static final String CONNECT_SRC = "connect-src 'self'";
8989

9090
private static final char SEPARATOR = ';';
@@ -96,9 +96,8 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
9696
+ REPORT_URI.length()
9797
+ STYLE_SRC.length()
9898
+ SCRIPT_SRC.length()
99-
+ CONNECT_SRC.length()
10099
// number of separators between directives
101-
+ 6;
100+
+ 5;
102101

103102
@Override
104103
public void writeHeaders(HttpServletRequest request, HttpServletResponse response) {
@@ -135,8 +134,10 @@ private static String constructDirectives(HttpServletRequest request) {
135134
sb.append(SCRIPT_COLLECTION_INFO);
136135
}
137136

138-
sb.append(SEPARATOR)
139-
.append(CONNECT_SRC);
137+
if (uri.equals(Url.ADD_SERIES_PAGE)) {
138+
sb.append(SEPARATOR)
139+
.append(CONNECT_SRC);
140+
}
140141

141142
return sb.toString();
142143
}

0 commit comments

Comments
 (0)