Skip to content

Commit c945f17

Browse files
committed
Robustness improvements for markup parser and core extend utility. Switched to Debug.warnOnce for forbidden keys to avoid CI noise, and replaced hasOwnProperty with safe Object.prototype calls across all tagging logic.
1 parent fd9f1e4 commit c945f17

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

src/core/core.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ const version = '$_CURRENT_SDK_VERSION';
99
*/
1010
const revision = '$_CURRENT_SDK_REVISION';
1111

12+
import { Debug } from './debug.js';
13+
1214
/**
1315
* Merge the contents of two objects into a single object.
1416
*
1517
* @param {object} target - The target object of the merge.
16-
* @param {object} ex - The object that is merged with target.
18+
* @param {object} ex - The object to be merged into the target.
1719
* @returns {object} The target object.
1820
* @example
19-
* const A = {
21+
* var A = {
2022
* a: function () {
21-
* console.log(this.a);
23+
* console.log('a');
2224
* }
2325
* };
24-
* const B = {
26+
* var B = {
2527
* b: function () {
26-
* console.log(this.b);
28+
* console.log('b');
2729
* }
2830
* };
2931
*
@@ -36,12 +38,28 @@ const revision = '$_CURRENT_SDK_REVISION';
3638
*/
3739
function extend(target, ex) {
3840
for (const prop in ex) {
41+
if (!Object.prototype.hasOwnProperty.call(ex, prop)) {
42+
continue;
43+
}
44+
45+
const isForbidden = prop === '__proto__' || prop === 'constructor' || prop === 'prototype';
46+
if (isForbidden) {
47+
Debug.warnOnce(`Ignoring forbidden property: ${prop}`);
48+
continue;
49+
}
50+
3951
const copy = ex[prop];
4052

4153
if (Array.isArray(copy)) {
42-
target[prop] = extend([], copy);
54+
if (!Array.isArray(target[prop])) {
55+
target[prop] = [];
56+
}
57+
extend(target[prop], copy);
4358
} else if (copy && typeof copy === 'object') {
44-
target[prop] = extend({}, copy);
59+
if (!target[prop] || typeof target[prop] !== 'object') {
60+
target[prop] = {};
61+
}
62+
extend(target[prop], copy);
4563
} else {
4664
target[prop] = copy;
4765
}
@@ -50,4 +68,5 @@ function extend(target, ex) {
5068
return target;
5169
}
5270

71+
5372
export { extend, revision, version };

src/framework/components/element/markup.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Debug } from '../../../core/debug.js';
2+
13
// markup scanner
24

35
// list of scanner tokens
@@ -334,12 +336,19 @@ class Parser {
334336
// of assign)
335337
function merge(target, source) {
336338
for (const key in source) {
337-
if (!source.hasOwnProperty(key)) {
339+
if (!Object.prototype.hasOwnProperty.call(source, key)) {
338340
continue;
339341
}
342+
343+
const isForbidden = key === '__proto__' || key === 'constructor' || key === 'prototype';
344+
Debug.assert(!isForbidden, `Ignoring forbidden property: ${key}`);
345+
if (isForbidden) {
346+
continue;
347+
}
348+
340349
const value = source[key];
341350
if (value instanceof Object) {
342-
if (!target.hasOwnProperty(key)) {
351+
if (!Object.prototype.hasOwnProperty.call(target, key)) {
343352
target[key] = { };
344353
}
345354
merge(target[key], source[key]);
@@ -380,7 +389,7 @@ function resolveMarkupTags(tags, numSymbols) {
380389
const edges = { };
381390
for (let index = 0; index < tags.length; ++index) {
382391
const tag = tags[index];
383-
if (!edges.hasOwnProperty(tag.start)) {
392+
if (!Object.prototype.hasOwnProperty.call(edges, tag.start)) {
384393
edges[tag.start] = { open: [tag], close: null };
385394
} else {
386395
if (edges[tag.start].open === null) {
@@ -390,7 +399,7 @@ function resolveMarkupTags(tags, numSymbols) {
390399
}
391400
}
392401

393-
if (!edges.hasOwnProperty(tag.end)) {
402+
if (!Object.prototype.hasOwnProperty.call(edges, tag.end)) {
394403
edges[tag.end] = { open: null, close: [tag] };
395404
} else {
396405
if (edges[tag.end].close === null) {

0 commit comments

Comments
 (0)