Skip to content

Commit d9b322e

Browse files
committed
CSP: adjust configuration to fix errors on /togglz page.
Addressed to #226
1 parent f270eb3 commit d9b322e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
3232
private static final String COLLECTION_INFO_PAGE_PATTERN =
3333
Url.INFO_COLLECTION_PAGE.replace("{slug}", "");
3434

35+
private static final String TOGGLZ_PAGES_PATTERN = Url.TOGGLZ_CONSOLE_PAGE + '/';
36+
3537
// default policy prevents loading resources from any source
3638
private static final String DEFAULT_SRC = "default-src 'none'";
3739

@@ -56,11 +58,16 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
5658
+ " 'sha256-DpmxvnMJIlwkpmmAANZYNzmyfnX2PQCBDO4CB2BFjzU='";
5759

5860
// - 'https://www.gstatic.com' is required by Google Charts
59-
// - 'sha256-/kX...' is required for 'overflow: hidden;' inline CSS that is using
60-
// by Google Charts.
61+
// - 'sha256-/kX...' is required for 'overflow: hidden;' inline CSS for Google Charts.
6162
private static final String STYLE_COLLECTION_INFO =
6263
" https://www.gstatic.com 'sha256-/kXZODfqoc2myS1eI6wr0HH8lUt+vRhW8H/oL+YJcMg='";
6364

65+
// - 'sha256-biL...' is required for 'display: none;' inline CSS for Togglz
66+
// - 'sha256-zQD...' is required for 'width: 100%; text-align: center;' inline CSS for Togglz
67+
private static final String STYLE_TOGGLZ =
68+
" 'sha256-biLFinpqYMtWHmXfkA1BPeCY0/fNt46SAZ+BBk5YUog='"
69+
+ " 'sha256-zQDRfdePzsm4666fPPtpna61v74bryIt2Xu5qx2rn4A='";
70+
6471
// - 'self' is required for our own JS files
6572
// - 'unsafe-inline' is required by jquery.min.js (that is using code inside of
6673
// event handlers. We can't use hashing algorithms because they aren't supported
@@ -109,7 +116,11 @@ private static String constructDirectives(HttpServletRequest request) {
109116

110117
if (onCollectionInfoPage) {
111118
sb.append(STYLE_COLLECTION_INFO);
119+
120+
} else if (request.getRequestURI().startsWith(TOGGLZ_PAGES_PATTERN)) {
121+
sb.append(STYLE_TOGGLZ);
112122
}
123+
113124
sb.append(SEPARATOR)
114125
.append(SCRIPT_SRC);
115126

0 commit comments

Comments
 (0)