Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx: add Content-Security-Policy-Report-Only header to all non-wordpress content sites #57

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/profile/templates/contentorigin/site.nginx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ server {
expires 30d;

add_header Access-Control-Allow-Origin "*";

# Add Content Security Policy headers
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' code.jquery.com; connect-src 'self'; img-src 'self'; style-src 'self'; report-to https://csp-report-api.openjs-foundation.workers.dev/";
}

location /.well-known/acme-challenge {
Expand Down
3 changes: 3 additions & 0 deletions modules/profile/templates/gruntjscom/site.nginx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ server {
proxy_pass http://localhost:<%= @backend_port %>;
proxy_redirect off;
proxy_buffering off;

# Add Content Security Policy headers
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' code.jquery.com; connect-src 'self'; img-src 'self'; style-src 'self'; report-to https://csp-report-api.openjs-foundation.workers.dev/";
}

location /.well-known/acme-challenge {
Expand Down
6 changes: 6 additions & 0 deletions modules/profile/templates/miscweb/site.nginx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ server {
include /etc/nginx/fastcgi_params;
}
<%- end -%>

location / {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik location blocks are mutually exclusive, so this means this won't apply to .php URLs.

It seems add_header is valid in server blocks directly as well, if you want to do that for miscweb sites (i.e. above before the first location block). https://nginx.org/en/docs/http/ngx_http_headers_module.html

This is fine to me either way as an incremental start. I am making the assumption that this new catch-all location block will inherit the index and try_files directives from the server block.


# Add Content Security Policy headers
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' code.jquery.com; connect-src 'self'; img-src 'self'; style-src 'self'; report-to https://csp-report-api.openjs-foundation.workers.dev/";
}
}

# vim: ts=2 sw=2 et