-
Notifications
You must be signed in to change notification settings - Fork 49.4k
Description
There was a security hack that mentions React here: http://danlec.com/blog/xss-via-a-spoofed-react-element
Ultimately this is a server-side bug and NOT a bug in React itself. This issue is about figuring out if there is something we can do to mitigate issues when you have a JSON parsing bug or some server-side issue.
isValidElement
React is designed to work with plain objects as input, and in fact, we're even getting rid of the _isReactElement
as a way to verify this. We'll allow any JSON object. IMO, there is no problem with the verification here.
All string values are sanitized before inserted into the DOM (except for CSS styles which is a known wontfix issue for IE8).
In earlier versions we used instanceof
checks but that didn't work well with multiple Reacts, it makes it difficult to optimize (inline objects are much faster) and couples JSX permanently to React, which we would like to avoid.
dangerouslySetInnerHTML
One possible solution is to disable this feature and require it to be used imperatively (React.findDOMNode(ref).innerHTML = ''
) which makes for worse performance at insertion time.
However, I don't believe this is the only bad thing once you can insert arbitrary HTML tags. It is certainly the easiest way to gain access to XSS though. You can also insert arbitrary Web Components which could expose data. You can render form elements that can potentially pass data.
What else can we do?
Ultimately this is an issue where <div>{userData}</div>
seems like a valid use case, but if your userData is compromised, it becomes dangerous.
Should React be responsible for protecting itself against arbitrary JSON as children?