Skip to content

Commit cc72233

Browse files
authored
miscweb: add CSP exceptions for demos and themeroller sites
Ref #54 Closes gh-67
1 parent 0bb2e32 commit cc72233

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

hieradata/environments/production/roles/miscweb.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ profile::miscweb::sites:
1818
name: jquery/demos.jquerymobile.com
1919
branch: main
2020
allow_php: true
21+
# script-src: unsafe-eval for syntax highlighting on all pages
22+
# img-src: data: for inline SVGs
23+
# style-src|font-src: load fonts from Google Fonts
24+
csp_header: |
25+
default-src 'self';
26+
script-src 'self' 'unsafe-eval';
27+
img-src 'self' data:;
28+
style-src 'self' fonts.googleapis.com;
29+
font-src 'self' fonts.gstatic.com;
30+
report-uri https://csp-report-api.openjs-foundation.workers.dev/;
31+
report-to csp-endpoint
2132
podcast.jquery.com:
2233
repository:
2334
name: jquery/podcast.jquery.com
@@ -42,6 +53,14 @@ profile::miscweb::sites:
4253
}
4354
php_env:
4455
THEMEROLLER_ZIPDIR: /var/cache/themeroller-zip
56+
# style-src: lots of inline styles
57+
# img-src: data: for inline images
58+
csp_header: |
59+
default-src 'self';
60+
style-src 'self' 'unsafe-inline';
61+
img-src 'self' data:;
62+
report-uri https://csp-report-api.openjs-foundation.workers.dev/;
63+
report-to csp-endpoint
4564
bugs.jquery.com:
4665
repository:
4766
name: jquery/bugs.jquery.com

modules/profile/templates/miscweb/site.nginx.erb

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ server {
2020

2121
# Add Content Security Policy headers
2222
add_header Reporting-Endpoints "csp-endpoint='https://csp-report-api.openjs-foundation.workers.dev/'";
23+
<%- if @site['csp_header'] -%>
24+
add_header Content-Security-Policy-Report-Only "
25+
<%= @site['csp_header'] %>
26+
";
27+
<%- else -%>
2328
# script-src: add 'wasm-unsafe-eval' for WebAssembly-driven search on
2429
# bugs.jquery.com, bugs.jqueryui.com, and plugins.jquery.com
2530
# img-src: allow secure.gravatar.com images on plugins.jquery.com
@@ -34,6 +39,7 @@ server {
3439
report-uri https://csp-report-api.openjs-foundation.workers.dev/;
3540
report-to csp-endpoint
3641
";
42+
<%- end -%>
3743

3844
<%- if @site['allow_php'] -%>
3945
index index.php index.html;

modules/profile/types/miscweb/site.pp

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
allow_php => Optional[Boolean],
1010
php_env => Optional[Hash[String[1], String]],
1111
certificate => Optional[String[1]],
12+
csp_header => Optional[String[1]],
1213
}]

0 commit comments

Comments
 (0)