Skip to content

Commit d63e5a1

Browse files
committed
CSP: adjust configuration to use fonts from CDN on prod.
Addressed to #226
1 parent 74db91d commit d63e5a1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
4949
private static final String IMG_SRC = "img-src 'self' https://cdn.rawgit.com https://raw.githubusercontent.com";
5050

5151
// - 'self' is required by glyphicons-halflings-regular.woff2 from bootstrap
52-
private static final String FONT_SRC = "font-src 'self'";
52+
private static final String FONT_SRC_SELF = "font-src 'self'";
53+
54+
// - 'https://maxcdn.bootstrapcdn.com' is required by glyphicons-halflings-regular.woff2
55+
private static final String FONT_SRC_CDN = "font-src https://maxcdn.bootstrapcdn.com";
5356

5457
// CheckStyle: ignore LineLength for next 1 line
5558
private static final String REPORT_URI = "report-uri https://mystamps.report-uri.io/r/default/csp/reportOnly";
@@ -110,7 +113,7 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
110113
private static final int MIN_HEADER_LENGTH =
111114
DEFAULT_SRC.length()
112115
+ IMG_SRC.length()
113-
+ FONT_SRC.length()
116+
+ FONT_SRC_SELF.length()
114117
+ REPORT_URI.length()
115118
+ STYLE_SRC.length()
116119
+ SCRIPT_SRC.length()
@@ -133,7 +136,7 @@ private String constructDirectives(String uri) {
133136

134137
sb.append(DEFAULT_SRC).append(SEPARATOR)
135138
.append(IMG_SRC).append(SEPARATOR)
136-
.append(FONT_SRC).append(SEPARATOR)
139+
.append(useSingleHost ? FONT_SRC_SELF : FONT_SRC_CDN).append(SEPARATOR)
137140
.append(REPORT_URI).append(SEPARATOR)
138141
.append(STYLE_SRC)
139142
.append(useSingleHost ? STYLES_SELF : STYLES_CDN);

0 commit comments

Comments
 (0)