made compliant with Content-Security-Policy unsafe-eval restrictions #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #30, which would also fix aframevr/aframe#5028.
Disabling inline scripts and unsafe-eval using Content-Security-Policy is a huge security win, stopping whole classes of attacks like XSS.
For more info on CSP, see:
The root cause for the breakage is the code:
which makes creating getters for private properties easy, but at the cost of doing a potentially unsafe implicit eval of a string. Allowing unsafe-eval in CSP works around that, at the expense of completely gutting XSS protections.
What kind of change does this PR introduce? (check at least one)
This PR simply unrolls the property getters to make them static, not dynamically evaluated. Tedious but safer, and there aren't that many private properties. Whether CSP compatibility is a bugfix or a feature is in the eye of the beholder, but many organizations will refuse to make exceptions to their CSP and thus would be unable to use this library or others that depend on it like A-Frame.
Does this PR introduce a breaking change? (check one)
It's simply unrolling the changes made by the wrapper.
Did you test your solution?
I tested it against A-Frame in Vivaldi, Firefox, Safari and the Oculus/Meta Browser on my Oculus Go. I verified using the following Node.js script based on your example:
Problem Description
Make the library and its dependents compliant with Content-Security-Policy
Solution Description
Replace unsafe-eval instances with unrolled equivalent code.
Side Effects, Risks, Impact
Unlikely to be risky
Aditional comments: