mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-27 13:40:47 +00:00
Extract Privacy module
Centralizes how we redact sensitive information.
This commit is contained in:
@@ -1,26 +1,9 @@
|
||||
/* eslint-env node */
|
||||
|
||||
const Path = require('path');
|
||||
|
||||
const ensureError = require('ensure-error');
|
||||
const isString = require('lodash/isString');
|
||||
|
||||
|
||||
const APP_ROOT_PATH = Path.join(__dirname, '..', '..', '..');
|
||||
const APP_ROOT_PATH_PATTERN = new RegExp(APP_ROOT_PATH, 'g');
|
||||
const Privacy = require('../privacy');
|
||||
|
||||
// toLogFormat :: Error -> String
|
||||
exports.toLogFormat = (error) => {
|
||||
const normalizedError = ensureError(error);
|
||||
const stackWithRedactedPaths = exports.redactSensitivePaths(normalizedError.stack);
|
||||
return stackWithRedactedPaths;
|
||||
};
|
||||
|
||||
// redactSensitivePaths :: String -> String
|
||||
exports.redactSensitivePaths = (logLine) => {
|
||||
if (!isString(logLine)) {
|
||||
return logLine;
|
||||
}
|
||||
|
||||
return logLine.replace(APP_ROOT_PATH_PATTERN, '<REDACTED_PATH>');
|
||||
return Privacy.redactAll(normalizedError.stack);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user