Redact stack traces with forward and backslashes
This commit is contained in:
parent
b0da7d965e
commit
a8a7525609
2 changed files with 27 additions and 2 deletions
|
@ -37,10 +37,16 @@ exports._redactPath = (filePath) => {
|
||||||
// _pathToRegExp :: Path -> Maybe RegExp
|
// _pathToRegExp :: Path -> Maybe RegExp
|
||||||
exports._pathToRegExp = (filePath) => {
|
exports._pathToRegExp = (filePath) => {
|
||||||
try {
|
try {
|
||||||
|
const pathWithNormalizedSlashes = filePath.replace(/\//g, '\\');
|
||||||
|
const urlEncodedPath = encodeURI(filePath);
|
||||||
// Safe `String::replaceAll`:
|
// Safe `String::replaceAll`:
|
||||||
// https://github.com/lodash/lodash/issues/1084#issuecomment-86698786
|
// https://github.com/lodash/lodash/issues/1084#issuecomment-86698786
|
||||||
const urlEncodedAppRootPath = escapeRegExp(encodeURI(filePath));
|
const patternString = [
|
||||||
return new RegExp(`${escapeRegExp(filePath)}|${urlEncodedAppRootPath}`, 'g');
|
filePath,
|
||||||
|
pathWithNormalizedSlashes,
|
||||||
|
urlEncodedPath,
|
||||||
|
].map(escapeRegExp).join('|');
|
||||||
|
return new RegExp(patternString, 'g');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,5 +73,24 @@ describe('Privacy', () => {
|
||||||
'path2 file:///[REDACTED]/js/background.js.';
|
'path2 file:///[REDACTED]/js/background.js.';
|
||||||
assert.equal(actual, expected);
|
assert.equal(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should redact stack traces with both forward and backslashes', () => {
|
||||||
|
const testPath = 'C:/Users/Meow/AppData/Local/Programs/signal-desktop-beta';
|
||||||
|
const modifiedTestPath =
|
||||||
|
'C:\\Users\\Meow\\AppData\\Local\\Programs\\signal-desktop-beta';
|
||||||
|
const text = 'This is a log line with sensitive information:\n' +
|
||||||
|
`path1 ${testPath}\\main.js\n` +
|
||||||
|
'phone1 +12223334455 ipsum\n' +
|
||||||
|
'group1 group(123456789) doloret\n' +
|
||||||
|
`path2 ${modifiedTestPath}\\js\\background.js.`;
|
||||||
|
|
||||||
|
const actual = Privacy._redactPath(testPath)(text);
|
||||||
|
const expected = 'This is a log line with sensitive information:\n' +
|
||||||
|
'path1 [REDACTED]\\main.js\n' +
|
||||||
|
'phone1 +12223334455 ipsum\n' +
|
||||||
|
'group1 group(123456789) doloret\n' +
|
||||||
|
'path2 [REDACTED]\\js\\background.js.';
|
||||||
|
assert.equal(actual, expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue