Skip to content

Commit ea38cba

Browse files
committed
task: configure CSP to allow JavaScript from unpkg.com on series info page.
Addressed to #1056 and #1057 No functional changes.
1 parent 8a27e5c commit ea38cba

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
137137
// - 'https://cdnjs.cloudflare.com' is required by selectize.bootstrap3.min.css
138138
private static final String SCRIPTS_SERIES_ADD_PAGE = " https://cdnjs.cloudflare.com";
139139

140+
// - 'https://unpkg.com' is required by react/react-dom
141+
private static final String SCRIPTS_SERIES_INFO_PAGE = " https://unpkg.com";
142+
140143
// - 'unsafe-eval' is required by loader.js from Google Charts
141144
// - 'https://www.gstatic.com' is required by Google Charts
142145
private static final String SCRIPT_COLLECTION_INFO = " 'unsafe-eval' https://www.gstatic.com";
@@ -214,8 +217,9 @@ protected String constructDirectives(String uri) {
214217
sb.append(SEPARATOR)
215218
.append(CHILD_SRC);
216219
} else if (SERIES_INFO_PAGE_PATTERN.matcher(uri).matches()) {
217-
// anonymous and users without a required authority actually don't need this directive
218-
sb.append(SEPARATOR)
220+
// anonymous and users without a required authority actually don't need these directives
221+
sb.append(SCRIPTS_SERIES_INFO_PAGE)
222+
.append(SEPARATOR)
219223
.append(CONNECT_SRC);
220224
}
221225

src/test/java/ru/mystamps/web/support/spring/security/ContentSecurityPolicyHeaderWriterTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ public void onSeriesAddImagePageWithResourcesFromCdn() {
246246
)
247247
);
248248

249+
assertThat(
250+
directives,
251+
hasItemInArray(
252+
"script-src "
253+
+ "'unsafe-inline' "
254+
+ "https://stamps.filezz.ru "
255+
+ "https://maxcdn.bootstrapcdn.com "
256+
+ "https://yandex.st "
257+
+ "https://unpkg.com"
258+
)
259+
);
260+
249261
assertThat(directives, hasItemInArray("connect-src 'self'"));
250262

251263
// hope that all other directives are the same as on the index page

0 commit comments

Comments
 (0)