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

build(docker): set standardized headers in NGINX #729

Merged
merged 7 commits into from
Apr 16, 2024

Conversation

sybereal
Copy link
Collaborator

Set a number of security headers on all responses from NGINX:

  • Content-Security-Policy
  • Cross-Origin-Embedder-Policy
  • Cross-Origin-Opener-Policy
  • Cross-Origin-Resource-Policy
  • Origin-Agent-Cluster
  • Referrer-Policy
  • X-Content-Type-Options
  • X-Download-Options
  • X-Frame-Options
  • X-XSS-Protection

What issues does this PR close? N/A

Checklist

Preview Give feedback

Angular's implementation of style inlining adds an inline onload handler
to the stylesheet <link> tag, which conflicts with CSP.
There are workarounds of questionable reliability, but this actually
works, at the cost of a slight load-time penalty.
Subresource integrity [1] is a feature in recent web browsers that
allows annotating scripts, stylesheets, and others with an `integrity`
attribute containing a hash of the contents.
These hashes can then be used together with CSP to ensure only trusted
scripts may be loaded.

Enabling this Angular build option only emits the `integrity` attribute
on generated <script> and <link> tags; setting a matching CSP header has
to be done in the web server configuration.

[1]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
Replace isomorphic-dompurify with DomSanitizer from
@angular/platform-browser.
This helps in supporting the `trusted-types` CSP directive, as it can be
reduced to just Angular-related types with this.

The removed portions about rel="noopener noreferrer" will be covered by
the Cross-Origin-Opener-Policy and Referrer-Policy security headers.
Add a minimal script that can be used to generate valid CSP hashes from
a list of input files passed on the command line.
@sybereal sybereal requested review from richardtreier and kulgg April 16, 2024 14:55
Set the following headers:

- Content-Security-Policy
- Cross-Origin-Embedder-Policy
- Cross-Origin-Opener-Policy
- Cross-Origin-Resource-Policy
- Origin-Agent-Cluster
- Referrer-Policy
- X-Content-Type-Options
- X-Download-Options
- X-Frame-Options
- X-XSS-Protection

Specifically, the combination of Cross-Origin-Opener-Policy and
Referrer-Policy takes the role of setting `rel="noreferrer noopener"` on
external links, which was removed in a prior commit replacing the HTML
sanitizer used for Markdown rendering.

* Generate hashes of JS files during the build process
* Template hashes into CSP
* Include headers in NGINX configuration
@sybereal sybereal force-pushed the build/docker-nginx-standard-headers branch from 5d57f65 to 6fe806d Compare April 16, 2024 15:10
Copy link
Collaborator

@richardtreier richardtreier left a comment

Choose a reason for hiding this comment

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

LGTM

@richardtreier richardtreier merged commit bd4dbce into main Apr 16, 2024
12 checks passed
@richardtreier richardtreier deleted the build/docker-nginx-standard-headers branch April 16, 2024 15:12
kulgg added a commit that referenced this pull request Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants