Privacy: Additional tweaks to debug log generation

This commit is contained in:
Scott Nonnenberg 2025-07-23 04:08:36 +10:00 committed by GitHub
parent 9fc0cedebb
commit 510b4f2df7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 38 deletions

View file

@ -12,7 +12,7 @@ describe('Privacy', () => {
describe('redactCardNumbers', () => {
it('should redact anything that looks like a credit card', () => {
const text =
'This is a log line with a card number 1234-1234-1234\n' +
'This is a log line with a card number 1234-1234-1234-12\n' +
'and another one 1234 1234 1234 1234 123';
const actual = Privacy.redactCardNumbers(text);
@ -24,8 +24,6 @@ describe('Privacy', () => {
it('should redact weird credit card numbers', () => {
const text =
'12341234123\n' +
'123412341234\n' +
'1234123412341\n' +
'12341234123412\n' +
'123412341234123\n' +
@ -34,35 +32,29 @@ describe('Privacy', () => {
'123412341234123412\n' +
'1234123412341234123\n' +
'12341234123412341234\n' +
'1-2-3-4-1-2-3-4-1-2-3\n' +
'1-2-3-4-1-2-3-4-1-2-3-4\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4-1\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2-3\n' +
'1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4\n' +
'1 2 3 4 1 2 3 4 1 2 3\n' +
'1 2 3 4 1 2 3 4 1 2 3 4\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'1 2 3 a 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 a 2 3 4\n' +
'123-4-1-2-3-4-1-2-3-4-1\n' +
'123-4-1-2-3-4-1-2-3-4-1-2\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3-4\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3-4-1\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2-3\n' +
'123-4-1-2-3-4-1-2-3-4-1-2-3-4-1-2-3-4\n' +
'123 4 1 2 3 4 1 2 3 4 1\n' +
'123 4 1 2 3 4 1 2 3 4 1 2\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4 1\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'123a412 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n' +
'123 4 1 2 3 4 1 2 3 4 1 2 3 4 1 a 2 3 4\n' +
'';
const actual = Privacy.redactCardNumbers(text);
const expected =
'12341234123\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'1234123412341\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
@ -70,9 +62,7 @@ describe('Privacy', () => {
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED]4\n' +
'1-2-3-4-1-2-3-4-1-2-3\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'123-4-1-2-3-4-1-2-3-4-1\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
@ -80,9 +70,7 @@ describe('Privacy', () => {
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED]-4\n' +
'1 2 3 4 1 2 3 4 1 2 3\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'123 4 1 2 3 4 1 2 3 4 1\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED]\n' +
@ -90,7 +78,7 @@ describe('Privacy', () => {
'[REDACTED]\n' +
'[REDACTED]\n' +
'[REDACTED] 4\n' +
'1 2 3 a [REDACTED]\n' +
'123a[REDACTED]\n' +
'[REDACTED] a 2 3 4\n' +
'';
assert.equal(actual, expected);
@ -98,6 +86,7 @@ describe('Privacy', () => {
it('should not redact things that are close to credit card numbers', () => {
const text = `
INFO 2025-07-22T16:39:12.383Z [background] delivery receipt from [REDACTED]f41.1 1753202353590 for sent message 1753202351897 wasSentEncrypted=true
12--3412341234
1234123 412341234
1e23412341234
@ -105,6 +94,7 @@ describe('Privacy', () => {
const actual = Privacy.redactCardNumbers(text);
const expected = `
INFO 2025-07-22T16:39:12.383Z [background] delivery receipt from [REDACTED]f41.1 1753202353590 for sent message 1753202351897 wasSentEncrypted=true
12--3412341234
1234123 412341234
1e23412341234

View file

@ -24,7 +24,7 @@ const CALL_LINK_ROOT_KEY_PATTERN =
/([A-Z]{4})-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}/gi;
const ATTACHMENT_URL_KEY_PATTERN = /(attachment:\/\/[^\s]+key=)([^\s]+)/gi;
const REDACTION_PLACEHOLDER = '[REDACTED]';
const CARD_NUMBER_PATTERN = /(\d[- ]?){11,18}\d/g;
const CARD_NUMBER_PATTERN = /\d\d(\d[- ]?){11,16}\d/g;
export type RedactFunction = (value: string) => string;
@ -222,15 +222,18 @@ addSensitivePath(APP_ROOT_PATH);
export const redactAll: RedactFunction = text => {
let result = text;
// Do these first, to retain last characters
result = redactAttachmentUrlKeys(result);
result = redactCallLinkRoomIds(result);
result = redactCallLinkRootKeys(result);
result = redactCardNumbers(result);
result = redactGroupIds(result);
result = redactPhoneNumbers(result);
result = redactSensitivePaths(result);
result = redactUuids(result);
// These leave nothing
result = redactCardNumbers(result);
result = redactSensitivePaths(result);
return result;
};