Skip to content

Commit 674055c

Browse files
committed
Fix code scanner complaint re: potential prototype-pollution
Signed-off-by: Geoff Wilson <[email protected]>
1 parent f154eb2 commit 674055c

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

scripts/find-missing-translations.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,28 @@ function getValueAtPath(obj, path) {
113113

114114
// Set value at a dotted path in an object
115115
function setValueAtPath(obj, path, value) {
116-
const parts = path.split(".")
117-
let current = obj
118-
119-
for (let i = 0; i < parts.length; i++) {
120-
const part = parts[i]
121-
122-
// If it's the last part, set the value
123-
if (i === parts.length - 1) {
124-
current[part] = value
125-
} else {
126-
// If the key doesn't exist or isn't an object, create an empty object
127-
if (current[part] === undefined || typeof current[part] !== "object") {
128-
current[part] = {}
129-
}
130-
current = current[part]
131-
}
132-
}
116+
const parts = path.split(".")
117+
let current = obj
118+
119+
for (let i = 0; i < parts.length; i++) {
120+
const part = parts[i]
121+
122+
// Guard against prototype pollution
123+
if (part === "__proto__" || part === "constructor" || part === "prototype") {
124+
continue
125+
}
126+
127+
// If it's the last part, set the value
128+
if (i === parts.length - 1) {
129+
current[part] = value
130+
} else {
131+
// If the key doesn't exist or isn't an object, create an empty object
132+
if (current[part] === undefined || typeof current[part] !== "object") {
133+
current[part] = {}
134+
}
135+
current = current[part]
136+
}
137+
}
133138
}
134139

135140
// Function to check translations for a specific area

0 commit comments

Comments
 (0)