Skip to content

Commit

Permalink
feat: strip sensitive info form logs
Browse files Browse the repository at this point in the history
fix(commons): fix serializing uint8array
  • Loading branch information
blakebyrnes committed Mar 19, 2024
1 parent e63fcdd commit 194da26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 10 additions & 5 deletions commons/lib/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ class Log implements ILog {
}
}

function translateValueToPrintable(value: any, depth = 0): any {
function translateValueToPrintable(key: string, value: any, depth = 0): any {
if (value === undefined || value === null) return;

if (key === 'password' || key === 'suri') {
return '********';
}

if (value instanceof Error) {
return value.toString();
}
Expand All @@ -153,11 +158,11 @@ function translateValueToPrintable(value: any, depth = 0): any {

if (typeof value === 'object') {
if (Array.isArray(value)) {
return value.map(x => translateValueToPrintable(x, depth + 1));
return value.map((x, i) => translateValueToPrintable(i as any, x, depth + 1));
}
const result: any = {};
for (const [key, subValue] of Object.entries(value)) {
result[key] = translateValueToPrintable(subValue, depth + 1);
for (const [subKey, subValue] of Object.entries(value)) {
result[subKey] = translateValueToPrintable(subKey, subValue, depth + 1);
}
return result;
}
Expand Down Expand Up @@ -191,7 +196,7 @@ export function translateToPrintable(
continue;
}

const printable = translateValueToPrintable(value);
const printable = translateValueToPrintable(key, value);
if (printable === null || printable === undefined) continue;
printData[key] = printable;
}
Expand Down
14 changes: 8 additions & 6 deletions commons/lib/TypeSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ export default class TypeSerializer {
}

if (ArrayBuffer.isView(value)) {
// @ts-ignore
const binary = new TextDecoder('utf8').decode(value.buffer);
const binary = Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))
.map(byte => String.fromCharCode(byte))
.join('');
return {
__type: Types.ArrayBuffer64,
value: globalThis.btoa(binary),
Expand All @@ -186,8 +187,7 @@ export default class TypeSerializer {
};
}
if (value instanceof ArrayBuffer) {
// @ts-ignore
const binary = new TextDecoder('utf8').decode(value);
const binary = Array.from(new Uint8Array(value)).map(byte => String.fromCharCode(byte)).join('');
return {
__type: Types.ArrayBuffer64,
value: globalThis.btoa(binary),
Expand Down Expand Up @@ -219,8 +219,10 @@ export default class TypeSerializer {
}

const decoded = globalThis.atob(value);
// @ts-ignore
const uint8Array = new TextEncoder().encode(decoded);
const uint8Array = new Uint8Array(new ArrayBuffer(decoded.length));
for (let i = 0; i < decoded.length; i++) {
uint8Array[i] = decoded.charCodeAt(i);
}
if (!entry.args) return uint8Array;

const { arrayType, byteOffset, byteLength } = entry.args;
Expand Down

0 comments on commit 194da26

Please sign in to comment.