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

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

Open

Description

@MrNocTV

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>.

Activity

  1. MrNocTV commented on Apr 22, 2020

    @MrNocTV
    Author

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions