Skip to content

Commit 4d0922e

Browse files
committed
Set Content-Security-Policy header on responses.
Enable report-only mode for now. Addressed to #226
1 parent dab9b40 commit 4d0922e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,26 @@ protected void configure(HttpSecurity http) throws Exception {
116116
// TODO: GH #27
117117
.disable()
118118
.headers()
119-
// TODO
120-
.disable();
119+
.defaultsDisabled() // TODO
120+
.contentSecurityPolicy(
121+
// default policy prevents loading resources from any source
122+
"default-src 'none'; " +
123+
// 'self' is required for: our own CSS files
124+
// 'https://cdn.rawgit.com' is required for: languages.min.css (TODO: GH #246)
125+
"style-src 'self' https://cdn.rawgit.com; " +
126+
// 'self' is required for: our own JS files
127+
// 'unsafe-inline' is required for: jquery.min.js (that is using code inside of event handlers.
128+
// We can't use hashing algorithms because they aren't supported for handlers. In future,
129+
// we should get rid of jQuery or use 'unsafe-hashed-attributes' from CSP3. Details:
130+
// https://github.com/jquery/jquery/blob/d71f6a53927ad02d728503385d15539b73d21ac8/jquery.js#L1441-L1447
131+
// and https://w3c.github.io/webappsec-csp/#unsafe-hashed-attributes-usage)
132+
"script-src 'self' 'unsafe-inline'; " +
133+
// 'https://cdn.rawgit.com' is required for: languages.png (TODO: GH #246)
134+
// 'https://raw.githubusercontent.com' is required for: languages.png (TODO: GH #246)
135+
"img-src https://cdn.rawgit.com https://raw.githubusercontent.com; " +
136+
// 'self' is required for: glyphicons-halflings-regular.woff2 from bootstrap
137+
"font-src 'self'"
138+
).reportOnly();
121139
}
122140

123141
// Used in ServicesConfig.getUserService()

0 commit comments

Comments
 (0)