-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Replace REACT_ELEMENT_TYPE magicnum with Infinity. #5830
Conversation
This closes the XSS hole on older browsers that don't support Symbol. More discussion: facebook#4832 (comment)
8d2de5c
to
e7e48fd
Compare
Note that this doesn't protect against data coming in through structured cloning, but JSON is by far the most common vector. The use of Symbol() protects against structured cloning / cross-realm communication, but causes very real issues like https://phabricator.babeljs.io/T2517 which can kill applications only in production, on the browsers devs often don't use. Getting the Merging this PR will require coordination with Babel in order to not break |
cc @sebmarkbage |
The downside here is that this is not a magic number. Meaning it is not unique among other frameworks nor within this framework if we add more. |
@sebmarkbage A tad overkill and might impact performance, but having both ( |
Why would we need to have a magicnum that is unique among other frameworks? |
Why not just make it something like |
@yaycmyk The idea is something that can't be JSON serialized, to avoid inadvertent XSS if, say, a server responds with something that looks like a React Element. Infinity can still be cloned via Structured Cloning, but closes the most common hole (XHR/Fetch). |
Ah! Does it have to be a primitive? A cached noop function could work otherwise and would definitely not serialize as far as I'm aware |
Technically, yes, it would work, but it would be impossible to reference via e.g. Babel Helpers, which are meant to be pure and not rely on any external dependencies (such as importing React and grabbing that noop function). This limitation causes problems with Symbols, actually, since a native symbol does not equal a polyfilled one. Plenty of reading at #5138 |
Oh I see. Definitely an interesting problem to solve - thanks for the reading material! One other thought - what about |
Sure, but how would that work on the server? :) |
Well on the server there is the global object, which is replaced with window when using a tool like Browserify. |
The guarantee here is not strong enough so I'm going to close out this PR. Let's continue in #5138 which has much more context. |
This closes the XSS hole on older browsers that don't support Symbol.
More discussion: #4832 (comment)
Figured this would be helpful to get in before 0.15 hits.