Skip to content

Commit c1bcde3

Browse files
authored
Force strict equality on vnode constructor (#4986)
* Force strict equality on vnode constructor * Update test (#4989)
1 parent bf7a195 commit c1bcde3

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/create-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ export function Fragment(props) {
8484
* @returns {vnode is VNode}
8585
*/
8686
export const isValidElement = vnode =>
87-
vnode != NULL && vnode.constructor == UNDEFINED;
87+
vnode != NULL && vnode.constructor === UNDEFINED;

src/diff/children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function constructNewChildrenArray(
209209
NULL,
210210
NULL
211211
);
212-
} else if (childVNode.constructor == UNDEFINED && childVNode._depth > 0) {
212+
} else if (childVNode.constructor === UNDEFINED && childVNode._depth > 0) {
213213
// VNode is already in use, clone it. This can happen in the following
214214
// scenario:
215215
// const reuse = <div />

src/diff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function diff(
7373

7474
// When passing through createElement it assigns the object
7575
// constructor as undefined. This to prevent JSON-injection.
76-
if (newVNode.constructor != UNDEFINED) return NULL;
76+
if (newVNode.constructor !== UNDEFINED) return NULL;
7777

7878
// If the previous diff bailed out, resume creating/hydrating.
7979
if (

test/browser/render.test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ describe('render()', () => {
101101
});
102102

103103
it('should not render when detecting JSON-injection', () => {
104-
const vnode = JSON.parse('{"type":"span","children":"Malicious"}');
104+
const vnode = JSON.parse(
105+
'{"type":"span","props":{ "children": "Malicious"}, "__v": 1, "constructor": null}'
106+
);
105107
render(vnode, scratch);
106108
expect(scratch.firstChild).to.be.null;
107109
});

0 commit comments

Comments
 (0)