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

[CSP] Blocks data-emotion inline styles #36095

Open
2 tasks done
jnschbrt opened this issue Feb 7, 2023 · 4 comments
Open
2 tasks done

[CSP] Blocks data-emotion inline styles #36095

jnschbrt opened this issue Feb 7, 2023 · 4 comments
Assignees
Labels
external dependency Blocked by external dependency, we can’t do anything about it package: system Specific to @mui/system

Comments

@jnschbrt
Copy link

jnschbrt commented Feb 7, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

Steps:

  1. use create-react-app with mui v5
  2. set the following csp header inside public/index.html
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
  1. set the .env as follows:
INLINE_RUNTIME_CHUNK=false
IMAGE_INLINE_SIZE_LIMIT=0
  1. my app root looks like this:
<ThemeProvider theme={theme}>
  <IntlProvider locale={currentLanguage} messages={messages[currentLanguage]}>
    <CssBaseline />
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Layout />}>
            {...}
        </Route>
      </Routes>
    </BrowserRouter>
  </IntlProvider>
</ThemeProvider>
  1. build or start the app

Current behavior 😯

I dont know why, but I keep getting these empty inline "data-emotion" style tags ..

image

image

setting the style-src directive as "style-src 'self' 'sha256-2NO5...' 'sha256-47DE...';" with the full hashes from the emotion library works. but i dont wanna bind the csp header to this settings. i reckon the hashes change with future mui versions.

Expected behavior 🤔

no data-emotion inline style tags

Context 🔦

I dont use server-side-rendering.
I upload the build output files directly to my aws cloudfront instance.

Your environment 🌎

npx @mui/envinfo
System:
    OS: Windows 10 10.0.22621
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.18.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.22621.1105.0), Chromium (108.0.1462.76)
  npmPackages:
    @emotion/react: ^11.10.5 => 11.10.5 
    @emotion/styled: ^11.10.5 => 11.10.5 
    @mui/base:  5.0.0-alpha.109 
    @mui/core-downloads-tracker:  5.10.17 
    @mui/icons-material: ^5.11.0 => 5.11.0 
    @mui/material: ^5.10.17 => 5.10.17 
    @mui/private-theming:  5.10.16 
    @mui/styled-engine:  5.10.16 
    @mui/system:  5.10.17 
    @mui/types:  7.2.2 
    @mui/utils:  5.10.16 
    @types/react: ^18.0.24 => 18.0.26 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: ^4.6.4 => 4.9.4 

using chrome and edge

@jnschbrt jnschbrt added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 7, 2023
@zannager zannager added the customization: theme Centered around the theming features label Feb 8, 2023
@siriwatknp siriwatknp added external dependency Blocked by external dependency, we can’t do anything about it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer customization: theme Centered around the theming features labels Feb 13, 2023
@siriwatknp
Copy link
Member

@jnschbrt It might be faster to resolve your problem if you open the issue at emotion repo directly.

@jnschbrt
Copy link
Author

emotion-js/emotion#2996

@oliviertassinari oliviertassinari changed the title Content Security Poilicy blocks data-emotion inline styles [Content Security Poilicy] Blocks data-emotion inline styles Aug 21, 2023
@oliviertassinari oliviertassinari added the package: system Specific to @mui/system label Aug 21, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 21, 2023

I don't see any issue, CSP needs to be configured: https://mui.com/material-ui/guides/content-security-policy/#server-side-rendering-ssr, it doesn't look like it was configured in the bug reports.


@brijeshb42 This looks like we should move the CSP guide to be under https://mui.com/system/getting-started/.

@Bonfims
Copy link

Bonfims commented Nov 9, 2023

I don't see any issue, CSP needs to be configured: https://mui.com/material-ui/guides/content-security-policy/#server-side-rendering-ssr, it doesn't look like it was configured in the bug reports.

@brijeshb42 This looks like we should move the CSP guide to be under https://mui.com/system/getting-started/.

and you need to point that we can only config the nonce with a server side rendering project and do not have any information about how to properly achieve this on a build that render on client.

@oliviertassinari oliviertassinari changed the title [Content Security Poilicy] Blocks data-emotion inline styles [CSP] Blocks data-emotion inline styles Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external dependency Blocked by external dependency, we can’t do anything about it package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

5 participants