question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs(security): add useful guidance to the CSP section of the guide

See original GitHub issue

πŸ“š Docs or angular.io bug report

Description

In the Security Guide for Angular, the section on Content Security Policy (CSP) provides no useful guidance or information on the specific requirements, impediments, or issues related to using a CSP with an Angular application.

πŸ”¬ Minimal Reproduction

What’s the affected URL?**

https://angular.io/guide/security#content-security-policy

Reproduction Steps**

This is the entire guide for using Angular with a Content Security Policy (CSP):


Content security policy

Content Security Policy (CSP) is a defense-in-depth technique to prevent XSS. To enable CSP, configure your web server to return an appropriate Content-Security-Policy HTTP header. Read more about content security policy at An Introduction to Content Security Policy on the HTML5Rocks website.


Expected vs Actual Behavior**

We should clearly state some of the known limitations and configurations for using Angular with a CSP.

Here are some related, known issues that have been around for 1-4 years now

  1. [innerHTML] triggers CSP alert/report
  2. Inline <style> elements violate style-src Content Security Policy
  3. feat: add a customizable nonce attribute for injected style elements
  4. Empty style tag generated when one or more components don’t have styles

Suggested Steps

  1. We should clearly state that allowing 'unsafe-inline' in style-src is required for Angular applications.
  2. We should clearly state that 'self' is required for style-src and script-src in Angular applications.
  3. We should recommend upgrade-insecure-requests.
  4. We should document that connect-src must be configured with 'self' and any other font, script, or style sources that are retrieved by @angular/service-worker.

If there are some little-known work arounds for any of these issues, they should be documented in this guide.

🌍 Your Environment

Browser info

Chrome 85

Anything else relevant?

WebPageTest.org now gives web sites/apps a security grade based on a scan by Snyk.

https://angular.io/guide/security#content-security-policy gets the following score

Screen Shot 2020-06-18 at 12 28 10 AM

Screen Shot 2020-06-18 at 12 29 15 AM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
anno1985commented, Aug 20, 2020
3reactions
jyotitushircommented, Jun 25, 2020

Similar issue is being faced in our application. Our angular7 application is not working without unsafe-inline with β€˜style-src’. Our security team is not allowing to have unsafe inline values in CSP… Is there a work around for this? or by when can we expect a fix from angular.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Security Policy (CSP) - HTTP - MDN Web Docs
Chrome Edge Content‑Security‑Policy Full support. Chrome25. more. Toggle history Full sup... base‑uri Full support. Chrome40. Toggle history Full sup... block‑all‑mixed‑content. Deprecated Full support. ChromeYes. Toggle history...
Read more >
Content security policy - Power Platform | Microsoft Learn
In this article. Configuring CSP; Examples; Organization settings; Configuring CSP without UI. Content Security Policy (CSP) is currentlyΒ ...
Read more >
Content-Security-Policy Header CSP Reference & Examples
The Content-Security-Policy header allows you to restrict how resources such as JavaScript, CSS, or pretty much anything that the browser loads. Although it...
Read more >
Content security policy - web.dev
Content Security Policy can significantly reduce the risk and impact of cross-site scripting attacks in modern browsers.
Read more >
How to Set Up a Content Security Policy (CSP) in 3 Steps
Option 1: Add your CSP via Meta Tags: Β· Option 2: Add your CSP via HTTP Response Header:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found