Skip to content

Commit 48d9b40

Browse files
committed
ContentSecurityPolicyHeaderWriter: show workaround for inline CSS only on /series/add or /series/{id} pages.
Addressed to #226
1 parent e0c6750 commit 48d9b40

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 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 ADD_IMAGE_PAGE_PATTERN = "/series/(add|\\d+|\\d/(ask|image))";
36+
3537
private static final String TOGGLZ_PAGES_PATTERN = Url.TOGGLZ_CONSOLE_PAGE + '/';
3638

3739
// default policy prevents loading resources from any source
@@ -51,11 +53,12 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
5153

5254
// - 'self' is required for our own CSS files
5355
// - 'https://cdn.rawgit.com' is required by languages.min.css (TODO: GH #246)
56+
private static final String STYLE_SRC = "style-src 'self' https://cdn.rawgit.com";
57+
5458
// - 'sha256-Dpm...' is required for 'box-shadow: none; border: 0px;' inline CSS
5559
// that are using on /series/add and /series/{id} pages.
56-
private static final String STYLE_SRC =
57-
"style-src 'self' https://cdn.rawgit.com"
58-
+ " 'sha256-DpmxvnMJIlwkpmmAANZYNzmyfnX2PQCBDO4CB2BFjzU='";
60+
private static final String STYLE_SERIES_ADD_IMAGE =
61+
" 'sha256-DpmxvnMJIlwkpmmAANZYNzmyfnX2PQCBDO4CB2BFjzU='";
5962

6063
// - 'https://www.gstatic.com' is required by Google Charts
6164
// - 'sha256-/kX...' is required for 'overflow: hidden;' inline CSS for Google Charts.
@@ -118,6 +121,9 @@ private static String constructDirectives(HttpServletRequest request) {
118121
if (onCollectionInfoPage) {
119122
sb.append(STYLE_COLLECTION_INFO);
120123

124+
} else if (uri.equals(Url.ADD_SERIES_PAGE) || uri.matches(ADD_IMAGE_PAGE_PATTERN)) {
125+
sb.append(STYLE_SERIES_ADD_IMAGE);
126+
121127
} else if (uri.startsWith(TOGGLZ_PAGES_PATTERN)) {
122128
sb.append(STYLE_TOGGLZ);
123129
}

0 commit comments

Comments
 (0)