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

bug(Layout): createEmptyStyleRule not adding nonce correctly in Chrome #28780

Closed
1 task
remcozigterman opened this issue Mar 26, 2024 · 0 comments · Fixed by #28800
Closed
1 task

bug(Layout): createEmptyStyleRule not adding nonce correctly in Chrome #28780

remcozigterman opened this issue Mar 26, 2024 · 0 comments · Fixed by #28800
Assignees
Labels
area: cdk/layout P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@remcozigterman
Copy link

remcozigterman commented Mar 26, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

The style element that is created with the function createEmptyStyleRule does not have the CSP nonce when the site is serving in Chrome.

The nonce is added the following way:
mediaQueryStyleNode.nonce = nonce; see here

But it should be done this way I think:
mediaQueryStyleNode.addAttribute('nonce', nonce);

Reproduction

StackBlitz link: https://stackblitz.com/edit/components-issue-4szyku?file=src%2Findex.html
Steps to reproduce:

  1. Create a new Angular project
  2. Add ngCspNonce="RANDOM_CSP_NONCE_PLACEHOLDER" to the app-root component in index.html
  3. Add Angular material to the project
  4. Add an Material Module to the appComponent (for example: MatSlideToggleModule)
  5. Serve the application and open the site in Chrome
  6. Inspect the rendered HTML

Expected Behavior

<style type="text/css" nonce="RANDOM_CSP_NONCE_PLACEHOLDER"></style>

Actual Behavior

<style type="text/css"></style>

Environment

  • Angular: 17.3.0
  • CDK/Material: 17.3.1
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows, MacOS
@remcozigterman remcozigterman added the needs triage This issue needs to be triaged by the team label Mar 26, 2024
@crisbeto crisbeto self-assigned this Mar 26, 2024
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/layout and removed needs triage This issue needs to be triaged by the team labels Mar 26, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 30, 2024
Uses `setAttribute` to set the nonce, instead of DOM property in order to work properly in SSR.

Fixes angular#28780.
crisbeto added a commit that referenced this issue Apr 1, 2024
Uses `setAttribute` to set the nonce, instead of DOM property in order to work properly in SSR.

Fixes #28780.
crisbeto added a commit that referenced this issue Apr 1, 2024
Uses `setAttribute` to set the nonce, instead of DOM property in order to work properly in SSR.

Fixes #28780.

(cherry picked from commit 452cde2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/layout P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants