[MM-50712] Fix local prototype pollution flaw (#2567)

* [MM-50712] Fix local prototype pollution flaw

* Update src/main/diagnostics/steps/internal/loggerHooks.test.js

Co-authored-by: Daniel Espino García <larkox@gmail.com>

---------

Co-authored-by: Daniel Espino García <larkox@gmail.com>
This commit is contained in:
Devin Binnie
2023-02-28 09:48:48 -05:00
committed by GitHub
parent d1f6fc5a5f
commit 2009d0290b
2 changed files with 12 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
import {MASK_EMAIL, MASK_PATH} from 'common/constants';
import {maskMessageDataHook} from './loggerHooks';
import {obfuscateByType} from './obfuscators';
const loggerMock = {
transports: {
@@ -59,6 +60,13 @@ describe('main/diagnostics/loggerHooks', () => {
expect(URLs.some((url) => result.includes(url))).toBe(false);
});
it('should not allow local prototype pollution', () => {
const obj = JSON.parse('{"__proto__":["1","2","3","4"]}');
expect(obj instanceof Array).toBe(false);
const obf = obfuscateByType(obj);
expect(obf instanceof Array).toBe(false);
});
describe('should mask paths for all OSs', () => {
it('darwin', () => {
const originalPlatform = process.platform;

View File

@@ -60,7 +60,10 @@ function maskDataInArray(arr: unknown[]): unknown[] {
function maskDataInObject(obj: Record<string, unknown>): Record<string, unknown> {
return Object.keys(obj).reduce<Record<string, unknown>>((acc, key) => {
acc[key] = obfuscateByType(obj[key]);
// Avoid local prototype pollution
if (key !== '__proto__') {
acc[key] = obfuscateByType(obj[key]);
}
return acc;
}, {});
}