⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
security: Expand protection patterns for comprehensive scanning
Daniel Miesslerc3c1cace09bf
diff --git a/.pai-protected.json b/.pai-protected.jsonindex ff64fdc7..d2537479 100644--- a/.pai-protected.json+++ b/.pai-protected.json@@ -41,25 +41,52 @@"validation": "These directories contain private Kai data and must not be committed"},"protected_patterns": {- "description": "String patterns that should never appear in PAI",+ "description": "String patterns that should never appear in PAI - actual data, not documentation mentions","patterns": [- "[email protected]",- "[email protected]",+ "daniel@danielmiessler\\.com",+ "susan@danielmiessler\\.com",+ "[a-z]+@danielmiessler\\.com",+ "[a-z]+@unsupervised-learning\\.com","ANTHROPIC_API_KEY=sk-",- "PERPLEXITY_API_KEY=[^E]",- "ELEVENLABS_API_KEY=[^y]",- "GOOGLE_API_KEY=[^y]",+ "OPENAI_API_KEY=sk-",+ "PERPLEXITY_API_KEY=pplx-",+ "ELEVENLABS_API_KEY=[a-f0-9]",+ "GOOGLE_API_KEY=AIza",+ "CLOUDFLARE_API_TOKEN=[a-zA-Z0-9_-]{40}",+ "GITHUB_TOKEN=gh[ps]_",+ "API_KEY=['\"][a-zA-Z0-9_-]{16,}['\"]",+ "SECRET_KEY=['\"][a-zA-Z0-9_-]{16,}['\"]",+ "Bearer [a-zA-Z0-9_-]{20,}",+ "sk-[a-zA-Z0-9]{20,}",+ "ghp_[a-zA-Z0-9]{36}",+ "gho_[a-zA-Z0-9]{36}",+ "xoxb-[0-9]+-[0-9]+-[a-zA-Z0-9]+",+ "xoxp-[0-9]+-[0-9]+-[a-zA-Z0-9]+","/Users/daniel/.claude/skills/personal","/Users/daniel/.claude/MEMORY","/Users/daniel/.claude/History",- "daemon.plist",- "~/.claude/skills/CORE/USER"+ "/Users/daniel/.claude/skills/CORE/USER",+ "~/.claude/skills/CORE/USER/",+ "daemon\\.plist",+ "Kaleigh Feher",+ "Bryan Brake",+ "Angela Gunn",+ "Susan Miessler",+ "SSN[:\\s]+[0-9]{3}-[0-9]{2}-[0-9]{4}",+ "-----BEGIN RSA PRIVATE KEY-----",+ "-----BEGIN OPENSSH PRIVATE KEY-----",+ "-----BEGIN PGP PRIVATE KEY-----",+ "-----BEGIN EC PRIVATE KEY-----",+ "id_rsa\\.pub",+ "id_ed25519\\.pub"],"exception_files": ["SECURITY.md",".pai-protected.json",".env.example",- "Tools/validate-protected.ts"+ "Tools/validate-protected.ts",+ "README.md",+ "INSTALL.md"]}},diff --git a/Tools/validate-protected.ts b/Tools/validate-protected.tsindex 66609624..be592c52 100644--- a/Tools/validate-protected.ts+++ b/Tools/validate-protected.ts@@ -78,6 +78,74 @@ function checkForbiddenDirectories(stagedFiles: string[], manifest: ProtectedManreturn violations;}+function scanAllFilesForSensitiveContent(stagedFiles: string[], manifest: ProtectedManifest): {+ file: string;+ violations: string[];+}[] {+ const results: { file: string; violations: string[] }[] = [];+ const patternCategory = manifest.protected.protected_patterns;++ if (!patternCategory || !patternCategory.patterns) {+ return results;+ }++ const exceptions = patternCategory.exception_files || [];++ for (const file of stagedFiles) {+ // Skip exception files+ if (exceptions.includes(file)) {+ continue;+ }++ const fullPath = join(PAI_ROOT, file);++ // Skip if file doesn't exist (might be deleted)+ if (!existsSync(fullPath)) {+ continue;+ }++ // Skip binary files+ try {+ const content = readFileSync(fullPath, 'utf-8');+ const violations: string[] = [];++ for (const pattern of patternCategory.patterns) {+ try {+ const regex = new RegExp(pattern, 'gi');+ const matches = content.match(regex);++ if (matches) {+ // Get line numbers for context+ const lines = content.split('\n');+ const matchingLines: number[] = [];+ lines.forEach((line, idx) => {+ if (regex.test(line)) {+ matchingLines.push(idx + 1);+ }+ regex.lastIndex = 0; // Reset regex state+ });++ const lineInfo = matchingLines.length > 0+ ? ` (lines: ${matchingLines.slice(0, 3).join(', ')}${matchingLines.length > 3 ? '...' : ''})`+ : '';+ violations.push(`Sensitive pattern "${pattern}"${lineInfo}`);+ }+ } catch {+ // Invalid regex, skip+ }+ }++ if (violations.length > 0) {+ results.push({ file, violations });+ }+ } catch {+ // Binary file or read error, skip+ }+ }++ return results;+}+function getAllProtectedFiles(manifest: ProtectedManifest): string[] {const files: string[] = [];@@ -202,6 +270,35 @@ async function main() {process.exit(1);}+ // Scan ALL staged files for sensitive content+ console.log(`\n${YELLOW}Scanning ${stagedFiles.length} staged file(s) for sensitive content...${RESET}\n`);+ const sensitiveResults = scanAllFilesForSensitiveContent(stagedFiles, manifest);++ if (sensitiveResults.length > 0) {+ console.log(`${RED}🚫 SENSITIVE CONTENT DETECTED${RESET}\n`);+ for (const result of sensitiveResults) {+ console.log(`${RED}❌${RESET} ${result.file}`);+ for (const violation of result.violations) {+ console.log(` ${RED}→${RESET} ${violation}`);+ }+ }+ console.log('\n' + '='.repeat(60));+ console.log(`\n${RED}🚫 COMMIT BLOCKED${RESET}\n`);+ console.log('Files contain sensitive content that must NOT be in public PAI:');+ console.log(' - API keys, tokens, secrets');+ console.log(' - Personal information (emails, contacts, family)');+ console.log(' - Customer/confidential data');+ console.log(' - Private file paths');+ console.log('\n' + YELLOW + 'To fix:' + RESET);+ console.log(' 1. Remove or redact the sensitive content');+ console.log(' 2. Use placeholder values (e.g., "your_api_key_here")');+ console.log(' 3. Add file to exception_files if it\'s intentional\n');+ process.exit(1);+ }++ console.log(`${GREEN}✅ No sensitive content found in staged files${RESET}\n`);+ console.log('='.repeat(60));+filesToCheck = allProtectedFiles.filter(f => stagedFiles.includes(f));if (filesToCheck.length === 0) {