Files
Filamenteka/scripts/security/security-check.js
DaX 18110ab159 Major restructure: Remove Confluence, add V2 data structure, organize for dev/prod
- Import real data from PDF (35 Bambu Lab filaments)
- Remove all Confluence integration and dependencies
- Implement new V2 data structure with proper inventory tracking
- Add backwards compatibility for existing data
- Create enhanced UI components (ColorSwatch, InventoryBadge, MaterialBadge)
- Add advanced filtering with quick filters and multi-criteria search
- Organize codebase for dev/prod environments
- Update Lambda functions to support both V1/V2 formats
- Add inventory summary dashboard
- Clean up project structure and documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-20 01:12:50 +02:00

92 lines
2.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
// Patterns that might indicate leaked credentials
const sensitivePatterns = [
/ATATT[A-Za-z0-9+/=]{100,}/g, // Confluence tokens
/ghp_[A-Za-z0-9]{36,}/g, // GitHub tokens
/api[_-]?key[_-]?[=:]\s*["']?[A-Za-z0-9+/=]{20,}/gi,
/token[_-]?[=:]\s*["']?[A-Za-z0-9+/=]{20,}/gi,
/password[_-]?[=:]\s*["']?[^\s"']{8,}/gi,
/secret[_-]?[=:]\s*["']?[A-Za-z0-9+/=]{20,}/gi,
];
// Files to exclude from scanning
const excludePatterns = [
/node_modules/,
/\.git/,
/\.next/,
/dist/,
/build/,
/out/,
/terraform\.tfvars$/,
/\.env/,
/security-check\.js$/,
];
function scanFile(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const issues = [];
sensitivePatterns.forEach(pattern => {
const matches = content.match(pattern);
if (matches) {
matches.forEach(match => {
// Only flag if it's not a placeholder or example
if (!match.includes('example') && !match.includes('YOUR_') && !match.includes('xxx')) {
issues.push({
file: filePath,
pattern: pattern.source,
match: match.substring(0, 20) + '...',
});
}
});
}
});
return issues;
}
function scanDirectory(dir) {
const issues = [];
function walk(currentPath) {
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(currentPath, entry.name);
const relativePath = path.relative(process.cwd(), fullPath);
// Skip excluded paths
if (excludePatterns.some(pattern => pattern.test(relativePath))) {
continue;
}
if (entry.isDirectory()) {
walk(fullPath);
} else if (entry.isFile() && /\.(js|ts|jsx|tsx|json|yml|yaml|md)$/.test(entry.name)) {
const fileIssues = scanFile(fullPath);
issues.push(...fileIssues);
}
}
}
walk(dir);
return issues;
}
// Run the scan
console.log('🔍 Scanning for potential credential leaks...\n');
const issues = scanDirectory(process.cwd());
if (issues.length > 0) {
console.error('❌ Found potential credential leaks:\n');
issues.forEach(issue => {
console.error(`File: ${issue.file}`);
console.error(`Pattern: ${issue.pattern}`);
console.error(`Match: ${issue.match}\n`);
});
process.exit(1);
} else {
console.log('✅ No credential leaks detected');
}