fix: prevent sensitive data logging (#70)

* feat: Add sensitive data masking to packet logging by introducing a sanitization function and a list of sensitive keys.

* test: mock console methods in logger tests and restore after each test

* refactor: remove redundant sensitive data masking functions and integrate safeStringifyPacket utility for improved logging

* fix: run format:write

* test: enhance logger tests with error handling for directory setup and cleanup

* refactor: optimize sensitive data masking logic by checking for exact matches in sensitive keys

* refactor: enhance sensitive data masking to handle circular references and improve sanitization logic

* refactor: update sensitive data masking comments and test descriptions to improve clarity and consistency

* test: enhance logger tests with dynamic log directory creation and cleanup after tests

* test: add unit tests for handling malformed JSON strings in sensitive data masking
This commit is contained in:
Riccardo Venturini authored and GitHub committed 2026-02-08 14:31:04 +08:00
1 parent 56137092be
commit 5155e37fd1
5 files changed
+238 -22

No files matched your search

+1 -16
View File
@@ -28,25 +28,10 @@ import { rpcHandler } from './ipc/handler';
import { ConfigManager } from './ipc/config/manager';
import { AppConfig } from './types/config';
import { isAutoStartLaunch, syncAutoStart } from './utils/autoStart';
import { safeStringifyPacket } from './utils/sensitiveDataMasking';
const packetLogPath = path.join(app.getPath('userData'), 'orpc_packets.log');
/**
* Safely stringify an object, handling circular references
*/
function safeStringifyPacket(obj: unknown): string {
const seen = new WeakSet();
return JSON.stringify(obj, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return '[Circular]';
}
seen.add(value);
}
return value;
});
}
function logPacket(data: any) {
try {
fs.appendFileSync(