-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fabric js is not csp unsafe-eval compliant #1621
Comments
I believe I did it this way for performance. So that function is compiled as, say, However... I'd love to see the numbers on how much exactly we're saving here. @jdalton could you shed some light on how this kind of pattern affects performance these days (and if it really matters)? |
Imo its a micro optimization, and will be matters if you expects tens of thousands of calls if at all. |
I'd say @Bnaya is right it looks like a micro-opt, I know some have used this technique to improve the performance of v8 in some perf sensitive situations but try it in a real world scenario & see if it hurts. |
@kangax do you know about someone that using fabric as/part of game engine? |
I've heard about few cases of Fabric being used for games. But any frequent Oh, also rendering lots of objects — particles, etc. On Tue, Aug 26, 2014 at 8:47 PM, Bnaya Peretz notifications@github.com
|
Hmm i might have another idea:
|
You mean to make On Wed, Aug 27, 2014 at 7:15 PM, Bnaya Peretz notifications@github.com
|
I mean to create all the possible accsessors in a mixin, but to extend from
|
Thats what i meant: |
@kangax What do you say? |
Pull request #1674 |
Sorry, I did a search for issues but I didn't find this one. As you've said here #1674 (comment), I'm interested in this. I need to use fabric to implement image cropping in a Chrome App. I'm using darkroom.js which uses fabric. Thanks |
I was not aware, thanks for pointing it out. Enabling sandboxing broke some other stuff (webfonts wouldn't load) but I fixed those by loading those as base64 data URIs instead. For reference, I ended up sandboxing the entire index.html page by adding the following to my manifest:
I'm not seeing any negative side effects from this yet, so it should be good. Thanks! :) |
@kangax Hmm, I didn't realize that sandboxing would block me from using the chrome.* APIs (aside from messaging). For sandboxing to work for me I'd need to put fabric in an iframe, which would take a good amount of refactoring to work. I'll just stick with modifying the chunk in of code in createAccessors() which seems to work for me.
|
@francislavoie you can also relax the default chrome app CSP |
@Bnaya unfortunately that's for extensions only. Chrome apps don't allow relaxing 'unsafe-eval'. See here: https://developer.chrome.com/apps/contentSecurityPolicy#but |
Oh, well i understand them. i wish all web pages were strict CSP compliant |
I'm trying to convert my single-page app that's using fabric.js into Chrome App. And faced with the 'unsafe-eval' error. Temporarily, I solved the problem this way:
// using `new Function` for better introspection
|
Any movement here? Will https://github.com/kangax/fabric.js/compare/master...Bnaya:accessors-refactor?expand=1 work? It's a bummer that sites can't fully lock down their apps if they use this library. In one case, this is the final blocker.
Perhaps there could be an "optimized" and "slow" option for sites that value security over micro-optimization? EDIT: sorry, looks like there's a different problem I'm noticing. With https://github.com/kangax/fabric.js/blob/30c64ec9c115276f14fd83e76ca800002d8f31c1/src/node.js#L125 and https://github.com/kangax/fabric.js/blob/30c64ec9c115276f14fd83e76ca800002d8f31c1/lib/json2.js#L474 |
Neil, if you can send a PR, I think I can get this merged. On Fri, Nov 20, 2015 at 6:55 PM, Neil Matatall notifications@github.com
|
I think pre create accessors should be even more performant than new Function, and also CSP compliant, but we can put it behind build flag to save lib size. The thing with precleared accessors is that if someone add new stateProperties you also need to manually add accessor. |
i would choose one way. i would not add extra complexity, there are lot lot of options already. |
I've updated If this is an acceptable solution i can make a PR And performance notice: |
I wonder if we can generate that file instead :) Not to spell everything out like that. |
you need plain js array/object with all the possible stateProps to generate it on build time, or to find a way to collect is from the various classes |
i think i will just trash this accessors... really undecided. |
I see no reason why not if you are pushing breaking changes build anyway. |
in the unperforming/unsecure/uncomfortable way he/she prefers |
thanks so much for your responses! I'm looking forward to being able to integrate this again. |
I've created a fork called secure-fabric.js which fixes the CSP problem and 2 others (although they are overridable by the user if they would like to specify a function as a string in the configuration). You can upgrade to secure-fabric.js easily with bower:
I'm happy to take other pull requests here: https://github.com/cjdelisle/secure-fabric.js |
@cjdelisle I would be great to have your changes as a pull request to this fabric.js repository here. what are the reasons for the fork? the fork has a high risk of being outdated while at the same time the fabric.js repository is maintained very well. |
@mobidev111 as you can see in #1621 (comment) @Bnaya has made a PR already which fixes fabric.js security but @kangax judged it as not interesting to accept so my understanding is that CSP is not a priority for fabric.js |
The issue is already fixed ( cjdelisle@284d9f0 ) and changes to the API are not necessary, although they may be desirable. The fact that this issue has been ongoing since 2014 is the reason why I chose to fork rather than create (yet another) pull request. |
i would not agree with |
apart from that, the pr from @Bnaya was not considered not interesting, there was an ongoing discussion about performance and manual manteinence of the file with the accessor proposed. No CSP is not a priority at all, that is true. Fixing accessors will not fix pattern and clipTo. |
That's a fair point, it seems that in most cases people pass in a function which is then stringified and then re-parsed to a function (for reasons I do not understand). But looking at the code I can see that it will work with a string representation of a function so I chose to preserve this behavior in order to be API-identical while still being CSP compliant (where we recognize the risk with CSP is that it will just fail) Thinking about it, I'd be happy to take a PR to secure-fabric.js which removes this option. Come be the first contributor 😄 |
pull requests are clearly welcomed in this repo, even this issue mentions this (#1621 (comment)) . in this repo your contribution benefits directly the community - and it will be maintained in the long run. this IMHO is the cool thing about open source - proposing a solution and iterating until it serves the requirements of the overall project. |
the point of passing functions in properties that must be stored and restored( clipTo or patternSource ) is that is easy to pass wrong functions with references to vars that are not available after restoring. I'm inclined to remove them all. same for patterns. Now i m more interested in understanding how people will suffer from missing a part of the full-named-accessors. Let's take the text example. If you set with Being generated from props names, named accessors do not give an better mnemonic name to the situation named accessors make docs longer, i prefere a longer jsdoc over the property itself. Positive things of named accessor? can someone help me finding them out? |
so i moved the accessors in a separate files that you can add at build time. the module in excluded by default in 2.0 ( for now ) If the module gets included the accessors get created. I prefer not to have them. This is not closing the issue since clipTo and patterns are still there playing with functions. |
Where is the clipTo/patterns problematic code? |
well is not So when we are doing toJSON/fromJSON a parsing of the function body needs to be done, and i bet is not safe. Those are 2 things i want to remove anyway. pattern: line 56 of pattern.calss.js |
Is this (still?) slated for the 2.0 release ? |
@kangax: can't you do something about this? It's a pretty important issue. |
We have a very strict content security policy and I was initially going to go with fabricjs, however now I cant because of this issue. |
clipTo is gone, so one issue less. So if you want, you can re-evaluate. |
i m not sure what the issue is. fabric 4 it does still make use of creating functions from text. |
FYI It was trivial to patch to be compliant with strict CSP. We forked the project three years ago for this patch so that we could use the library within CryptPad. |
I would prefer not restoring functions from json at all. This is still useful for patterns but since i would like to have patterns defined as groups more than functions, maybe we should let it go |
Due the use in the new Function notation, when preventing eval via csp header (unsafe-eval),
the library breaks.
https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
The use in csp become more and more common.
I believe it will be possible to implement it using regular js without new Function,
is there a reason to keep it that way?
https://github.com/kangax/fabric.js/blob/master/src/util/misc.js#L429-L434
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: