Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace REACT_ELEMENT_TYPE magicnum with Infinity.
This closes the XSS hole on older browsers that don't support Symbol.

More discussion: #4832 (comment)
  • Loading branch information
STRML committed Jan 12, 2016
commit e7e48fdcf7053db542a0320d3e4ebef5da9545bb
2 changes: 1 addition & 1 deletion src/isomorphic/classic/element/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var canDefineProperty = require('canDefineProperty');
// nor polyfill, then a plain number is used for performance.
var REACT_ELEMENT_TYPE =
(typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) ||
0xeac7;
Infinity;

var RESERVED_PROPS = {
key: true,
Expand Down
6 changes: 4 additions & 2 deletions src/isomorphic/classic/element/__tests__/ReactElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('ReactElement', function() {
});

it('uses the fallback value when in an environment without Symbol', function() {
expect(<div />.$$typeof).toBe(0xeac7);
expect(<div />.$$typeof).toBe(Infinity);
});

it('returns a complete element according to spec', function() {
Expand Down Expand Up @@ -207,7 +207,9 @@ describe('ReactElement', function() {
expect(React.isValidElement({ type: 'div', props: {} })).toEqual(false);

var jsonElement = JSON.stringify(React.createElement('div'));
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true);
// Should be false, even with Symbol not present, due to Infinity value
// which cannot be serialized into/from JSON.
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(false);
});

it('allows the use of PropTypes validators in statics', function() {
Expand Down