Skip to content

Commit f89d726

Browse files
committedDec 6, 2023
fix: added better protection against CSPP, thanks @kevin-mizu
1 parent c29aa90 commit f89d726

9 files changed

+1224
-586
lines changed
 

‎dist/purify.cjs.js

+398-193
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.es.mjs

+398-193
Large diffs are not rendered by default.

‎dist/purify.es.mjs.map

+1-1
Large diffs are not rendered by default.

‎dist/purify.js

+398-193
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,40 @@ function addToSet(set, array, transformCaseFunc = stringToLowerCase) {
107107
return set;
108108
}
109109

110+
/**
111+
* Clean up an array to harden against CSPP
112+
*
113+
* @param {Array} array - The array to be cleaned.
114+
* @returns {Array} The cleaned version of the array
115+
*/
116+
function cleanArray(array) {
117+
for (let index = 0; index < array.length; index++) {
118+
if (getOwnPropertyDescriptor(array, index) === undefined) {
119+
array[index] = null;
120+
}
121+
}
122+
123+
return array;
124+
}
125+
110126
/**
111127
* Shallow clone an object
112128
*
113129
* @param {Object} object - The object to be cloned.
114130
* @returns {Object} A new object that copies the original.
115131
*/
116-
export function clone(object) {
132+
function clone(object) {
117133
const newObject = create(null);
118134

119135
for (const [property, value] of entries(object)) {
120136
if (getOwnPropertyDescriptor(object, property) !== undefined) {
121-
newObject[property] = value;
137+
if (Array.isArray(value)) {
138+
newObject[property] = cleanArray(value);
139+
} else if (typeof value === 'object' && value.constructor === Object) {
140+
newObject[property] = clone(value);
141+
} else {
142+
newObject[property] = value;
143+
}
122144
}
123145
}
124146

@@ -172,6 +194,7 @@ export {
172194
isFrozen,
173195
setPrototypeOf,
174196
seal,
197+
clone,
175198
create,
176199
// RegExp
177200
regExpTest,

0 commit comments

Comments
 (0)
Please sign in to comment.