@@ -42,11 +42,16 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
42
42
// default policy prevents loading resources from any source
43
43
private static final String DEFAULT_SRC = "default-src 'none'" ;
44
44
45
- // - 'self' is required for uploaded images and its previews
46
45
// - 'https://cdn.rawgit.com' is required by languages.png (TODO: GH #246)
47
46
// - 'https://raw.githubusercontent.com' is required by languages.png
48
47
// CheckStyle: ignore LineLength for next 1 line
49
- private static final String IMG_SRC = "img-src 'self' https://cdn.rawgit.com https://raw.githubusercontent.com" ;
48
+ private static final String IMG_SRC = "img-src https://cdn.rawgit.com https://raw.githubusercontent.com" ;
49
+
50
+ // - 'self' is required for uploaded images and its previews
51
+ private static final String IMG_SRC_SELF = " 'self'" ;
52
+
53
+ // - 'https://stamps.filezz.ru' is required for uploaded images and its previews
54
+ private static final String IMG_SRC_CDN = " https://stamps.filezz.ru" ;
50
55
51
56
// - 'self' is required by glyphicons-halflings-regular.woff2 from bootstrap
52
57
private static final String FONT_SRC_SELF = "font-src 'self'" ;
@@ -128,14 +133,14 @@ public void writeHeaders(HttpServletRequest request, HttpServletResponse respons
128
133
response .setHeader ("Content-Security-Policy-Report-Only" , constructDirectives (uri ));
129
134
}
130
135
131
- @ SuppressWarnings ("PMD.NPathComplexity" )
136
+ @ SuppressWarnings ({ "PMD.NPathComplexity" , "PMD.ModifiedCyclomaticComplexity" } )
132
137
private String constructDirectives (String uri ) {
133
138
boolean onCollectionInfoPage = uri .startsWith (COLLECTION_INFO_PAGE_PATTERN );
134
139
135
140
StringBuilder sb = new StringBuilder (MIN_HEADER_LENGTH );
136
141
137
142
sb .append (DEFAULT_SRC ).append (SEPARATOR )
138
- .append (IMG_SRC ).append (SEPARATOR )
143
+ .append (IMG_SRC ).append (useSingleHost ? IMG_SRC_SELF : IMG_SRC_CDN ). append ( SEPARATOR )
139
144
.append (useSingleHost ? FONT_SRC_SELF : FONT_SRC_CDN ).append (SEPARATOR )
140
145
.append (REPORT_URI ).append (SEPARATOR )
141
146
.append (STYLE_SRC )
0 commit comments