transloco icon indicating copy to clipboard operation
transloco copied to clipboard

Bug(scope):Message format compile throwing unsafe eval errors

Open bh2989 opened this issue 1 year ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Which Transloco package(s) are the source of the bug?

MessageFormat

Is this a regression?

Yes

Current behavior

We are trying to remove 'unsafe-eval' from CSP, getting below error. EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'

image

Expected behavior

There should not be error after removing unsafe-eval from CSP as we handled through nonce

Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.

https://github.com/jsverse/transloco/issues/364

Transloco Config

No response

Please provide the environment you discovered this bug in

Transloco: 
Angular: 
Node: 
Package Manager: 
OS:

Browser

No response

Additional context

No response

I would like to make a pull request for this bug

Yes 🚀

bh2989 avatar Sep 16 '24 07:09 bh2989

@bh2989 Please provide the environment information.

shaharkazaz avatar Sep 16 '24 20:09 shaharkazaz

@shaharkazaz I have the same issue

Image

Transloco: "@jsverse/transloco": "^7.4.2", "@jsverse/transloco-messageformat": "^7.0.1", "@jsverse/transloco-persist-lang": "^7.0.1", "@jsverse/transloco-persist-translations": "^7.0.1",

Angular: "@angular/animations": "^18.1.0", "@angular/cdk": "^18.1.0", "@angular/common": "^18.1.0", "@angular/compiler": "^18.1.0", "@angular/core": "^18.1.0", "@angular/forms": "^18.1.0", "@angular/material": "^18.1.0"

Node: v22.3.0 Package Manager: npm OS: Windows

Any suggestion how to get rid of this issue?

plaskowski-bqs avatar Feb 06 '25 12:02 plaskowski-bqs

Same here with latest versions of Angular and Transloco

devfservant avatar Apr 12 '25 04:04 devfservant

This CSP issue could be resolved by adding a trustedTypesPolicy config option.

Currently, MessageFormat fails with Trusted Types because new Function() requires a TrustedScript.

Proposed API:

TranslocoModule.forRoot({
  config: {
    trustedTypesPolicy: 'custom-policy-name'
  }
})

Use trustedTypes.getPolicy(policyName)?.createScript() before new Function().

This would eliminate the need for 'unsafe-eval' in CSP while supporting custom policy names.

agentx-cgn avatar Jul 08 '25 10:07 agentx-cgn

Same issue here on the latest packages. Is anyone looking at this?

mgm87 avatar Oct 20 '25 16:10 mgm87