guard-scanner 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ts-src/scanner.ts CHANGED
@@ -23,7 +23,7 @@ import { PATTERNS } from './patterns.js';
23
23
 
24
24
  // ── Constants ───────────────────────────────────────────────────────────────
25
25
 
26
- export const VERSION = '3.2.0';
26
+ export const VERSION = '4.0.1';
27
27
 
28
28
  const THRESHOLDS_MAP: Record<string, Thresholds> = {
29
29
  normal: { suspicious: 30, malicious: 80 },
@@ -1008,4 +1008,73 @@ export class GuardScanner {
1008
1008
  }],
1009
1009
  };
1010
1010
  }
1011
+ toHTML(): string {
1012
+ const report = this.toJSON();
1013
+ const ts = new Date().toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
1014
+ const severityColor: Record<string, string> = {
1015
+ CRITICAL: '#ff4444', HIGH: '#ff8800', MEDIUM: '#ffcc00', LOW: '#aaaaaa',
1016
+ };
1017
+ const verdictColor: Record<string, string> = {
1018
+ MALICIOUS: '#ff4444', SUSPICIOUS: '#ffcc00', 'LOW RISK': '#44cc88', CLEAN: '#44cc88',
1019
+ };
1020
+
1021
+ const rows = report.findings.map(sr => {
1022
+ const color = verdictColor[sr.verdict] || '#aaaaaa';
1023
+ const findingRows = sr.findings.map(f => {
1024
+ const c = severityColor[f.severity] || '#aaaaaa';
1025
+ const loc = f.file ? `${f.file}${f.line ? ':' + f.line : ''}` : '—';
1026
+ const sample = f.sample ? `<code>${f.sample.replace(/</g, '&lt;')}</code>` : '—';
1027
+ return `<tr><td style="color:${c};font-weight:bold">${f.severity}</td><td>${f.id}</td><td>${f.desc}</td><td>${loc}</td><td>${sample}</td></tr>`;
1028
+ }).join('');
1029
+ const badge = `<span style="background:${color};color:#000;padding:2px 8px;border-radius:4px;font-weight:bold;font-size:0.85em">${sr.verdict}</span>`;
1030
+ return `<tr><td colspan="5" style="background:#1a1a2e;padding:8px 12px;font-weight:bold">
1031
+ 🛡️ ${sr.skill} — ${badge} (risk: ${sr.risk})</td></tr>${findingRows}`;
1032
+ }).join('');
1033
+
1034
+ const total = report.stats.scanned;
1035
+ const safe = report.stats.clean + report.stats.low;
1036
+ const safeRate = total ? Math.round(safe / total * 100) : 0;
1037
+
1038
+ return `<!DOCTYPE html>
1039
+ <html lang="en">
1040
+ <head>
1041
+ <meta charset="UTF-8">
1042
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
1043
+ <title>guard-scanner v${VERSION} Report</title>
1044
+ <style>
1045
+ body { font-family: 'Segoe UI', system-ui, sans-serif; background: #0d0d1a; color: #e0e0e0; margin: 0; padding: 24px; }
1046
+ h1 { color: #7ec8e3; margin: 0 0 4px; }
1047
+ .meta { color: #888; font-size: 0.85em; margin-bottom: 24px; }
1048
+ .stats { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
1049
+ .stat { background: #1a1a2e; border: 1px solid #333; border-radius: 8px; padding: 12px 20px; text-align: center; min-width: 80px; }
1050
+ .stat-label { font-size: 0.75em; color: #888; margin-bottom: 4px; }
1051
+ .stat-val { font-size: 1.8em; font-weight: bold; }
1052
+ table { width: 100%; border-collapse: collapse; margin-top: 8px; }
1053
+ th { background: #1a1a2e; padding: 8px 12px; text-align: left; font-size: 0.85em; color: #888; border-bottom: 1px solid #333; }
1054
+ td { padding: 6px 12px; border-bottom: 1px solid #222; font-size: 0.85em; vertical-align: top; }
1055
+ tr:hover td { background: #13132a; }
1056
+ code { background: #1e1e3a; padding: 1px 4px; border-radius: 3px; font-family: monospace; font-size: 0.9em; word-break: break-all; }
1057
+ .clean { color: #44cc88; font-weight: bold; }
1058
+ .footer { margin-top: 32px; color: #555; font-size: 0.8em; }
1059
+ </style>
1060
+ </head>
1061
+ <body>
1062
+ <h1>🛡️ guard-scanner v${VERSION}</h1>
1063
+ <div class="meta">Generated: ${ts} | Mode: ${report.mode} | Thresholds: suspicious≥${report.thresholds.suspicious}, malicious≥${report.thresholds.malicious}</div>
1064
+ <div class="stats">
1065
+ <div class="stat"><div class="stat-label">Scanned</div><div class="stat-val">${report.stats.scanned}</div></div>
1066
+ <div class="stat"><div class="stat-label">Clean</div><div class="stat-val" style="color:#44cc88">${report.stats.clean}</div></div>
1067
+ <div class="stat"><div class="stat-label">Low Risk</div><div class="stat-val" style="color:#44cc88">${report.stats.low}</div></div>
1068
+ <div class="stat"><div class="stat-label">Suspicious</div><div class="stat-val" style="color:#ffcc00">${report.stats.suspicious}</div></div>
1069
+ <div class="stat"><div class="stat-label">Malicious</div><div class="stat-val" style="color:#ff4444">${report.stats.malicious}</div></div>
1070
+ <div class="stat"><div class="stat-label">Safety Rate</div><div class="stat-val" style="color:${safeRate >= 80 ? '#44cc88' : '#ff8800'}">${safeRate}%</div></div>
1071
+ </div>
1072
+ ${report.findings.length === 0 ? '<p class="clean">✅ All clear — no threats detected.</p>' : `
1073
+ <table>
1074
+ <thead><tr><th>Severity</th><th>Pattern ID</th><th>Description</th><th>Location</th><th>Sample</th></tr></thead>
1075
+ <tbody>${rows}</tbody>
1076
+ </table>`}
1077
+ <div class="footer">guard-scanner v${VERSION} | IoC DB: ${report.iocVersion} | Signatures: ${report.signaturesVersion} | <a href="https://github.com/koatora20/guard-scanner" style="color:#7ec8e3">GitHub</a></div>
1078
+ </body></html>`;
1079
+ }
1011
1080
  }