-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 issue #1423
Comments
Thanks for the report! Can you please provide a repo so we can test against? |
I am afraid not. This happened in our main repo and it's not one I can not share. It's really easy to repro, though. All you need is to set a CSP and load RS. Btw, this is the culprit. Apparently CSP treats |
@dbismut I haven't looked at this properly but do you have any immediate thoughts on this? |
@joshuaellis I guess we can try the Proxy method in this article instead https://hackernoon.com/creating-callable-objects-in-javascript-d21l3te1. |
I agree that this is an issue. The "unsafe eval" issue prevents the upgraded plugin from running in environments which have some thought put into their CSP rules. |
An update, we're currently looking into how viable it is to use the If anyone has any suggestions how else we might tackle the issue, we'd love to hear it. |
This comment has been minimized.
This comment has been minimized.
Using |
As a rule we don't officially support IE11. AFAIK if you need to, you should run this module through I'll be looking to implement this in a |
This has been released in 9.2.0-beta.5, it'd be really helpful if someone could confirm our change has solved the issue 😄 |
@joshuaellis Will upgrade and get back to you soon enough :) |
It looks/works fine. Can't test it on an IE (at the moment), though. |
See above comment, this originally to do with a package |
I'm not an expert but I know instantiating Function is banned, so instantiating anything extending Function is probably as well. |
You may not be an expert, but you've definitely taught me something! ⭐ |
I've opened a new PR that completely basically reverts the state of |
This has been causing me grief as well, and to be honest, I have a small amount of code that I want to move to v9, and the calling pattern is trivial to change as part of the API update, compared to the execution environment headaches that come from the implicit eval() used to maintain backwards compatibility.
|
@chris-armstrong thanks! To be honest I really did think the same, but the amount of people who seemed bewildered by the change at the time was crazy! Hopefully though, the PR will resolve this, I don't normally work in strict environments so wasn't aware of this, nor is there a way to test this yet! |
Currently I'm just patching {
test: /node_modules\/@react-spring\/core/,
loader: "string-replace-loader",
options: {
multiple: [
{
search: "class SpringRef extends Function",
replace: "class SpringRef",
strict: true,
},
{
search: `super("return arguments.callee._call.apply(arguments.callee, arguments)");`,
replace: "",
strict: true,
},
],
},
} I used webpack string-replace-loader but something like patch-package would also work fine. How about offering a flag to disable the callable behavior? I think we can do something like below. export class SpringRef<State extends Lookup = Lookup> {
static disableCallable: boolean = false;
readonly current: Controller<State>[] = []
constructor() {
if (!SpringRef.disableCallable) {
Function.call(this, 'return arguments.callee._call.apply(arguments.callee, arguments)');
}
}
} Then set this flag at the script entry when using csp. import { SpringRef } from "@react-spring/web";
SpringRef.disableCallable = true; We might bundle a simple check to automatically set this flag. try {
new Function('');
} catch (e) {
SpringRef.disableCallable = true;
} |
Thanks for the suggestion @crux153, would you have to set |
@joshuaellis However, I found that it is not feasible to conditionally inherit from Most simple approach is to have two copy of SpringRef, one that extends Function and one not callable. Since multiple inheritance is not supported in JavaScript. I haven't found any way to accomplish this without code duplication. |
@joshuaellis Ok, I think I found a way of doing this. function noUnsafeEval() {
try {
new Function('')
return false
} catch (e) {
return true
}
}
const ConditionalCallable = (() => {
if ((window as any).REACT_SPRING_DISABLE_CALLABLE_REF || noUnsafeEval()) {
return class {}
} else {
return class extends Function {
constructor() {
super(
'return arguments.callee._call.apply(arguments.callee, arguments)'
)
}
}
}
})()
export class SpringRef<State extends Lookup = Lookup> extends ConditionalCallable {} This will simply disable the callable behavior in CSP-enabled environments without One can also disable it explicitly with a global variable like window.REACT_SPRING_DISABLE_CALLABLE_REF = true Using the same approach, we can also enable the You can see the full version here, and I'll create a PR if you like it. |
Thanks @crux153 i've just released It'd be great if anyone could try this and let me know if it's resolved the issue? |
@joshuaellis Gave it a go. Did not work ;( |
Interesting, I wonder why this would give us said error when we're not extending from |
@joshuaellis Let me try something else - there's a chance I might be not testing it properly. Will get back a bit later. |
@joshuaellis it seems it does not work, still. I am sure it will be dealt with eventually, though :) |
Can you share any error messages? I'm really not sure why this wouldn't work considering we've removed the extension of |
At first testing it works here! Good job! I'll let you know if I run into any other problem but so far so good. |
@joshuaellis somehow I still see this - not sure why (considering that you mentioned removing the Function extension). |
@joshuaellis So, for this to work, I had to add a yarn resolution to the latest beta. Not sure why (yet), but it did the trick. Thank you - and apologies for the confusion. |
It looks like the issue is resolved, it's released on |
Can also confirm that 9.2.0 fixed this issue for me. |
And another.. |
🐛 Bug Report
As of the this commit React Spring won't work whenever a CSP without
'unsafe-eval'
directive is active.To Reproduce
Set content security policy (CSP) without
'unsafe-eval'
inconnect-src
directive.The text was updated successfully, but these errors were encountered: