Visitar URL original
Angular dev mode errors with a strict CSP without unsafe-eval · Issue #43494 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220131125106/https://github.com/angular/angular/issues/43494
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

Angular dev mode errors with a strict CSP without unsafe-eval #43494

Closed
pbrowning-tt opened this issue Sep 17, 2021 · 1 comment
Closed

Angular dev mode errors with a strict CSP without unsafe-eval #43494

pbrowning-tt opened this issue Sep 17, 2021 · 1 comment

Comments

@pbrowning-tt
Copy link

@pbrowning-tt pbrowning-tt commented Sep 17, 2021 •

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

It seems that Angular calls new Function and global['eval'] from within this file when running in dev mode. As a result, the browser throws CSP errors when trying to implement a strict CSP without unsafe-eval. Thus we have to choose between keeping unsafe-eval in place vs living with a large number of loud errors in the console while developing locally.

To reproduce:

  • Generate a new Angular app with the latest NG CLI
  • Add this CSP
  <meta http-equiv="Content-Security-Policy" content="
    script-src 'self';
    style-src 'self' 'unsafe-inline';
    img-src 'self' data:;
    connect-src 'self';
    default-src 'none';
  ">
  • Run the app locally and notice the errors in the console

Please provide a link to a minimal reproduction of the bug

https://github.com/pbrowning-tt/unsafe-eval-error-minimal-repro

Please provide the exception or error you saw

In Firefox I get "Content Security Policy: The page’s settings blocked the loading of a resource at eval (“script-src”)." pointing to the `return new Function(...args);` line in https://github.com/angular/angular/blob/master/packages/core/src/util/security/trusted_types.ts.  This recurs 13 times in my minimal repro, but many many more times in our proprietary application.

In Chrome there are no _console_ errors, but I get one "page error" pointing to the `const fn = _global['eval'](trustedScriptFromString(body));` in the same trusted_types.ts file.

Please provide the environment you discovered this bug in

Angular CLI: 12.2.6
Node: 12.22.2
Package manager: 6.14.13
OS: Windows 10 x64
Angular: 12.2.0

Anything else?

No response

@ngbot ngbot bot added this to the needsTriage milestone Sep 17, 2021
@JoostK JoostK self-assigned this Sep 25, 2021
JoostK added a commit to JoostK/angular that referenced this issue Sep 25, 2021
…oid CSP violations

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is not considered less of a
problem that the CSP violation.

Fixes angular#43494
JoostK added a commit to JoostK/angular that referenced this issue Sep 25, 2021
…oid CSP violations

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is not considered less of a
problem that the CSP violation.

Fixes angular#43494
JoostK added a commit to JoostK/angular that referenced this issue Sep 25, 2021
…oid CSP violations

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is not considered less of a
problem that the CSP violation.

Fixes angular#43494
JoostK added a commit to JoostK/angular that referenced this issue Sep 25, 2021
…oid CSP violations

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is considered less of a problem
than the CSP violation.

Fixes angular#43494
JoostK added a commit to JoostK/angular that referenced this issue Oct 30, 2021
…oid CSP violations

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is considered less of a problem
than the CSP violation.

Fixes angular#43494
@atscott atscott closed this in 4f8eaac Nov 9, 2021
atscott added a commit that referenced this issue Nov 9, 2021
…oid CSP violations (#43587)

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is considered less of a problem
than the CSP violation.

Fixes #43494

PR Close #43587
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Dec 10, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 10, 2021
dimakuba added a commit to dimakuba/angular that referenced this issue Dec 28, 2021
…oid CSP violations (angular#43587)

This commit removes the dynamic creation of named arrays for internal
runtime storage arrays as they may cause CSP violations in development
mode,  when an application's CSP configuration does not include
`unsafe-eval`.

Named arrays for view data can still be enabled in development mode
using the `ngDevMode=namedConstructors` query parameter when loading the
application.

The usage of native class syntax for named arrays does not have the
desired effect when the code is downleveled to ES5. Since ES5 targets
are becoming increasingly more rare this is considered less of a problem
than the CSP violation.

Fixes angular#43494

PR Close angular#43587
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants