UNPKG

@puberty-labs/clits

Version:

CLiTS (Chrome Logging and Inspection Tool Suite) is a powerful Node.js library for automated Chrome browser testing, logging, and inspection. It provides a comprehensive suite of tools for monitoring network requests, console logs, DOM mutations, and more

36 lines (35 loc) 1.2 kB
// BSD: Provides data sanitization services to redact or mask sensitive information from logs. export class DataSanitizer { constructor(rules = []) { this.rules = rules; // Add default rules for common sensitive data this.addDefaultRules(); } addDefaultRules() { // Rule for passwords (in JSON-like strings) this.rules.push({ pattern: /("password"\s*:\s*)"[^"]*"/gi, replacement: '$1"***REDACTED***"' }); // Rule for email addresses this.rules.push({ pattern: /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi, replacement: '***REDACTED_EMAIL***' }); // Rule for common API keys/tokens this.rules.push({ pattern: /(["']?(?:api_key|token|client_secret)["']?\s*:\s*["'])([^"'\s]+)(["']?)/gi, replacement: '$1***REDACTED***$3' }); } sanitize(data) { let sanitizedData = data; for (const rule of this.rules) { sanitizedData = sanitizedData.replace(rule.pattern, rule.replacement); } return sanitizedData; } addRule(rule) { this.rules.push(rule); } }