Skip to content

mjml-browser generated bundle uses some 'eval' code that causes CSP 'unsafe-eval' issue #2742

@makavelithadon

Description

@makavelithadon

Describe the bug
First of all thanks for the incredible work realized !

We use the mjml-browser package to make some basic mjml->html conversion but the mjml-browser bundle contains some code that causes CSP (Content Security Policy) issues:

Screenshot from 2023-09-08 15-56-35

This issue is due to code that is equivalent to use of eval (cf. https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe-eval)

In the bundle file there is at least two occurrences of eval code :

Screenshot from 2023-09-08 15-57-28

And

Screenshot from 2023-09-08 15-57-41

To Reproduce
Steps to reproduce the behavior:

  1. Create a website with CSP and minimal whitelist rules (for example 'strict-dynamic' and 'self' for script-src CSP policy)
  2. require mjml-browser in your code
  3. See error :

Screenshot from 2023-09-08 15-56-35

Expected behavior
No use of unsafe-eval in production code

MJML environment (please complete the following information):

  • OS: Ubuntu 22.04.3 LTS
  • MJML Version 4.14.1
  • MJML Browser Version 4.14.1

Additional context
Saw this issue - webpack/webpack#6461 - so applied some recommended potential solutions, but I was only able to remove the first "eval" code (the call to new Function("return this")) but not the second one (new Function(""+e)).

Maybe an upgrade to a more recent version of webpack can help (tried upgrading to webpack@latest but too much errors at build time)

It's very crucial for us to keep consistent CSP rules to avoid security issues and to stay aligned with best practices in web security.

Thanks in advance for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions