Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Angular Component Styles violate CSP default-src 'self' #454

Open
MrNocTV opened this issue Apr 22, 2020 · 1 comment
Open

Angular Component Styles violate CSP default-src 'self' #454

MrNocTV opened this issue Apr 22, 2020 · 1 comment

Comments

@MrNocTV
Copy link

MrNocTV commented Apr 22, 2020

Context:
This is not just an issue with ng2-completer but also an issue with Angular/React in general. These frameworks are not built with CSP in mind.

Angular will generate <style> element in the DOM when rendering the components if you use component style. Component style is just a component with styleUrls tag.

Issue:
Since ng2-completer is also using component styles so it also vilolates CSP. More specifically, in my project, it will violate default-src 'self'.

Solution:
Stop using component style, we still can keep the structure intact (keep the css file inside the component directory). We just need to add relative link of this css file into styles of angular.json. Angular CLI will not generate <style> for css files in styles, instead it will bundle all files in styles into a single file, and link that file into the DOM using <link>.

@MrNocTV
Copy link
Author

MrNocTV commented Apr 22, 2020

This is the <style> element of ng2-completer in head. If we choose to go with my solution, those styles will be moved in the <link rel=stylesheet href=....> above

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant