Skip to content

Commit e7ed013

Browse files
committed
Throwing spaghetti at the wall
1 parent 9426276 commit e7ed013

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

_extension/src/configurationMiddleware.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function getMergedConfiguration(resource: vscode.Uri | undefined): Record<string
3838
const configs = configSections.map(section => getInspectedConfiguration(section, resource));
3939

4040
// Layer from lowest to highest precedence.
41-
let merged: Record<string, any> = {};
41+
// Use Object.create(null) so the object has no prototype to pollute.
42+
let merged: Record<string, any> = Object.create(null);
4243

4344
// Defaults: javascript < typescript < js/ts
4445
for (let i = configs.length - 1; i >= 0; i--) {
@@ -67,8 +68,9 @@ function getInspectedConfiguration(
6768
resource: vscode.Uri | undefined,
6869
): { explicit: Record<string, any> | null; defaults: Record<string, any> | null; } {
6970
const config = vscode.workspace.getConfiguration(section, resource);
70-
const explicit: Record<string, any> = {};
71-
const defaults: Record<string, any> = {};
71+
// Use Object.create(null) so these objects have no prototype to pollute.
72+
const explicit: Record<string, any> = Object.create(null);
73+
const defaults: Record<string, any> = Object.create(null);
7274
let hasExplicit = false;
7375
let hasDefaults = false;
7476

@@ -162,7 +164,9 @@ function setNestedValue(obj: Record<string, any>, dottedKey: string, value: any)
162164
* Returns a new object; does not mutate inputs.
163165
*/
164166
function deepMerge(a: Record<string, any>, b: Record<string, any>): Record<string, any> {
165-
const result: Record<string, any> = { ...a };
167+
// Use Object.create(null) so the result has no prototype to pollute.
168+
const result: Record<string, any> = Object.create(null);
169+
Object.assign(result, a);
166170
for (const key of Object.keys(b)) {
167171
if (prototypeKeys.has(key)) {
168172
continue;

0 commit comments

Comments
 (0)