Redact group ids in logging
FREEBIE
This commit is contained in:
parent
4c48d12dc3
commit
314b29e426
3 changed files with 70 additions and 13 deletions
|
@ -5,6 +5,7 @@ const _ = require('lodash');
|
||||||
|
|
||||||
const ipc = electron.ipcRenderer;
|
const ipc = electron.ipcRenderer;
|
||||||
const PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
|
const PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
|
||||||
|
const GROUP_REGEX = /(group\()([^)]+)(\))/g;
|
||||||
|
|
||||||
// Default Bunyan levels: https://github.com/trentm/node-bunyan#levels
|
// Default Bunyan levels: https://github.com/trentm/node-bunyan#levels
|
||||||
// To make it easier to visually scan logs, we make all levels the same length
|
// To make it easier to visually scan logs, we make all levels the same length
|
||||||
|
@ -21,6 +22,16 @@ const LEVELS = {
|
||||||
|
|
||||||
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
||||||
|
|
||||||
|
function redactPhone(text) {
|
||||||
|
return text.replace(PHONE_REGEX, "+[REDACTED]$1");
|
||||||
|
}
|
||||||
|
|
||||||
|
function redactGroup(text) {
|
||||||
|
return text.replace(GROUP_REGEX, function(match, before, id, after) {
|
||||||
|
return before + '[REDACTED]' + id.slice(-3) + after;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function now() {
|
function now() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
return date.toJSON();
|
return date.toJSON();
|
||||||
|
@ -32,7 +43,7 @@ function log() {
|
||||||
const consoleArgs = ['INFO ', now()].concat(args);
|
const consoleArgs = ['INFO ', now()].concat(args);
|
||||||
console._log.apply(console, consoleArgs);
|
console._log.apply(console, consoleArgs);
|
||||||
|
|
||||||
const str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
|
const str = redactGroup(redactPhone(args.join(' ')));
|
||||||
ipc.send('log-info', str);
|
ipc.send('log-info', str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +73,7 @@ function formatLine(entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(entries) {
|
function format(entries) {
|
||||||
return entries.map(formatLine).join('\n');
|
return redactGroup(redactPhone(entries.map(formatLine).join('\n')));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch() {
|
function fetch() {
|
||||||
|
|
|
@ -51,6 +51,14 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
idForLogging: function() {
|
||||||
|
if (this.isPrivate()) {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'group(' + this.id + ')';
|
||||||
|
},
|
||||||
|
|
||||||
handleMessageError: function(message, errors) {
|
handleMessageError: function(message, errors) {
|
||||||
this.trigger('messageError', message, errors);
|
this.trigger('messageError', message, errors);
|
||||||
},
|
},
|
||||||
|
@ -195,7 +203,7 @@
|
||||||
}.bind(this)).catch(function(error) {
|
}.bind(this)).catch(function(error) {
|
||||||
console.log(
|
console.log(
|
||||||
'getIdentityKeys error for conversation',
|
'getIdentityKeys error for conversation',
|
||||||
this.id,
|
this.idForLogging(),
|
||||||
error && error.stack ? error.stack : error
|
error && error.stack ? error.stack : error
|
||||||
);
|
);
|
||||||
return lookup;
|
return lookup;
|
||||||
|
@ -207,7 +215,7 @@
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.log(
|
console.log(
|
||||||
'getIdentityKeys error for group member',
|
'getIdentityKeys error for group member',
|
||||||
contact.id,
|
contact.idForLogging(),
|
||||||
error && error.stack ? error.stack : error
|
error && error.stack ? error.stack : error
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -230,7 +238,7 @@
|
||||||
if (this.get('decryptedOldIncomingKeyErrors')) {
|
if (this.get('decryptedOldIncomingKeyErrors')) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
console.log('decryptOldIncomingKeyErrors start for', this.id);
|
console.log('decryptOldIncomingKeyErrors start for', this.idForLogging());
|
||||||
|
|
||||||
var messages = this.messageCollection.filter(function(message) {
|
var messages = this.messageCollection.filter(function(message) {
|
||||||
var errors = message.get('errors');
|
var errors = message.get('errors');
|
||||||
|
@ -245,7 +253,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
var markComplete = function() {
|
var markComplete = function() {
|
||||||
console.log('decryptOldIncomingKeyErrors complete for', this.id);
|
console.log('decryptOldIncomingKeyErrors complete for', this.idForLogging());
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
this.save({decryptedOldIncomingKeyErrors: true}).always(resolve);
|
this.save({decryptedOldIncomingKeyErrors: true}).always(resolve);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -414,7 +422,13 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
addKeyChange: function(id) {
|
addKeyChange: function(id) {
|
||||||
console.log('adding key change advisory for', this.id, id, this.get('timestamp'));
|
console.log(
|
||||||
|
'adding key change advisory for',
|
||||||
|
this.idForLogging(),
|
||||||
|
id,
|
||||||
|
this.get('timestamp')
|
||||||
|
);
|
||||||
|
|
||||||
var timestamp = Date.now();
|
var timestamp = Date.now();
|
||||||
var message = new Whisper.Message({
|
var message = new Whisper.Message({
|
||||||
conversationId : this.id,
|
conversationId : this.id,
|
||||||
|
@ -437,7 +451,12 @@
|
||||||
|
|
||||||
var lastMessage = this.get('timestamp') || Date.now();
|
var lastMessage = this.get('timestamp') || Date.now();
|
||||||
|
|
||||||
console.log('adding verified change advisory for', this.id, id, lastMessage);
|
console.log(
|
||||||
|
'adding verified change advisory for',
|
||||||
|
this.idForLogging(),
|
||||||
|
id,
|
||||||
|
lastMessage
|
||||||
|
);
|
||||||
|
|
||||||
var timestamp = Date.now();
|
var timestamp = Date.now();
|
||||||
var message = new Whisper.Message({
|
var message = new Whisper.Message({
|
||||||
|
@ -548,7 +567,10 @@
|
||||||
queueJob: function(callback) {
|
queueJob: function(callback) {
|
||||||
var previous = this.pending || Promise.resolve();
|
var previous = this.pending || Promise.resolve();
|
||||||
|
|
||||||
var taskWithTimeout = textsecure.createTaskWithTimeout(callback, 'conversation ' + this.id);
|
var taskWithTimeout = textsecure.createTaskWithTimeout(
|
||||||
|
callback,
|
||||||
|
'conversation ' + this.idForLogging()
|
||||||
|
);
|
||||||
|
|
||||||
var current = this.pending = previous.then(taskWithTimeout, taskWithTimeout);
|
var current = this.pending = previous.then(taskWithTimeout, taskWithTimeout);
|
||||||
|
|
||||||
|
@ -564,7 +586,14 @@
|
||||||
sendMessage: function(body, attachments) {
|
sendMessage: function(body, attachments) {
|
||||||
this.queueJob(function() {
|
this.queueJob(function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
console.log('Sending message to conversation', this.id, 'with timestamp', now);
|
|
||||||
|
console.log(
|
||||||
|
'Sending message to conversation',
|
||||||
|
this.idForLogging(),
|
||||||
|
'with timestamp',
|
||||||
|
now
|
||||||
|
);
|
||||||
|
|
||||||
var message = this.messageCollection.add({
|
var message = this.messageCollection.add({
|
||||||
body : body,
|
body : body,
|
||||||
conversationId : this.id,
|
conversationId : this.id,
|
||||||
|
|
|
@ -228,7 +228,12 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function(reason) {
|
unload: function(reason) {
|
||||||
console.log('unloading conversation', this.model.id, 'due to:', reason);
|
console.log(
|
||||||
|
'unloading conversation',
|
||||||
|
this.model.idForLogging(),
|
||||||
|
'due to:',
|
||||||
|
reason
|
||||||
|
);
|
||||||
|
|
||||||
this.timerMenu.remove();
|
this.timerMenu.remove();
|
||||||
this.fileInput.remove();
|
this.fileInput.remove();
|
||||||
|
@ -285,7 +290,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('trimming conversation', this.model.id, 'of', models.length, 'old messages');
|
console.log(
|
||||||
|
'trimming conversation',
|
||||||
|
this.model.idForLogging(),
|
||||||
|
'of',
|
||||||
|
models.length,
|
||||||
|
'old messages'
|
||||||
|
);
|
||||||
|
|
||||||
this.model.messageCollection.remove(models);
|
this.model.messageCollection.remove(models);
|
||||||
_.forEach(models, function(model) {
|
_.forEach(models, function(model) {
|
||||||
|
@ -430,7 +441,13 @@
|
||||||
var view = this.loadingScreen;
|
var view = this.loadingScreen;
|
||||||
if (view) {
|
if (view) {
|
||||||
var openDelta = Date.now() - this.openStart;
|
var openDelta = Date.now() - this.openStart;
|
||||||
console.log('Conversation', this.model.id, 'took', openDelta, 'milliseconds to load');
|
console.log(
|
||||||
|
'Conversation',
|
||||||
|
this.model.idForLogging(),
|
||||||
|
'took',
|
||||||
|
openDelta,
|
||||||
|
'milliseconds to load'
|
||||||
|
);
|
||||||
this.loadingScreen = null;
|
this.loadingScreen = null;
|
||||||
view.remove();
|
view.remove();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue