Skip to content

Commit e7e48fd

Browse files
committed
Replace REACT_ELEMENT_TYPE magicnum with Infinity.
This closes the XSS hole on older browsers that don't support Symbol. More discussion: facebook#4832 (comment)
1 parent b60e8c2 commit e7e48fd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/isomorphic/classic/element/ReactElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var canDefineProperty = require('canDefineProperty');
2020
// nor polyfill, then a plain number is used for performance.
2121
var REACT_ELEMENT_TYPE =
2222
(typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) ||
23-
0xeac7;
23+
Infinity;
2424

2525
var RESERVED_PROPS = {
2626
key: true,

src/isomorphic/classic/element/__tests__/ReactElement-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ReactElement', function() {
4545
});
4646

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

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

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

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

0 commit comments

Comments
 (0)