@@ -42,11 +42,16 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
4242 // default policy prevents loading resources from any source
4343 private static final String DEFAULT_SRC = "default-src 'none'" ;
4444
45- // - 'self' is required for uploaded images and its previews
4645 // - 'https://cdn.rawgit.com' is required by languages.png (TODO: GH #246)
4746 // - 'https://raw.githubusercontent.com' is required by languages.png
4847 // 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" ;
5055
5156 // - 'self' is required by glyphicons-halflings-regular.woff2 from bootstrap
5257 private static final String FONT_SRC_SELF = "font-src 'self'" ;
@@ -128,14 +133,14 @@ public void writeHeaders(HttpServletRequest request, HttpServletResponse respons
128133 response .setHeader ("Content-Security-Policy-Report-Only" , constructDirectives (uri ));
129134 }
130135
131- @ SuppressWarnings ("PMD.NPathComplexity" )
136+ @ SuppressWarnings ({ "PMD.NPathComplexity" , "PMD.ModifiedCyclomaticComplexity" } )
132137 private String constructDirectives (String uri ) {
133138 boolean onCollectionInfoPage = uri .startsWith (COLLECTION_INFO_PAGE_PATTERN );
134139
135140 StringBuilder sb = new StringBuilder (MIN_HEADER_LENGTH );
136141
137142 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 )
139144 .append (useSingleHost ? FONT_SRC_SELF : FONT_SRC_CDN ).append (SEPARATOR )
140145 .append (REPORT_URI ).append (SEPARATOR )
141146 .append (STYLE_SRC )
0 commit comments