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

messageformat requires unsafe-eval in Content-Security-Policy #180

Closed
koosg opened this issue Oct 16, 2017 · 3 comments
Closed

messageformat requires unsafe-eval in Content-Security-Policy #180

koosg opened this issue Oct 16, 2017 · 3 comments

Comments

@koosg
Copy link

koosg commented Oct 16, 2017

When using a CSP which does not allow unsafe-eval, the 'new Function' throws an EvalError, as per the spec.
However, messageformat uses this:
if (typeof messages != 'object') {
var fn = new Function(
'number, plural, select, fmt', Compiler.funcname(locale),
'return ' + obj);
var rt = this.runtime;
return fn(rt.number, rt.plural, rt.select, this.fmt, pf[locale]);
}

Is there another way to fix this.

@SlexAxton
Copy link
Member

If you build your messages (say, as part of your webpack build), they get built into very small, fast functions that don’t violate unsafe-eval.

Docs: https://messageformat.github.io/build/

@Simon-Tesla
Copy link

I have a use case where the message strings are only available at runtime, not build-time, and I cannot change the CSP to allow eval. Is there any hope for a mechanism that will allow messageformat to work in that environment?

@SlexAxton
Copy link
Member

SlexAxton commented Mar 4, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants