@efraindrummer/ghostdeps 0.3.0 → 0.5.0
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/CHANGELOG.md +20 -0
- package/README.md +131 -5
- package/dist/analyzer.js +4 -1
- package/dist/cli.js +257 -9
- package/dist/clients/npm.js +48 -0
- package/dist/config.js +35 -1
- package/dist/diff/inspect.js +223 -0
- package/dist/fix/remediator.js +124 -0
- package/dist/hooks/githook.js +84 -0
- package/dist/notifications/webhook.js +98 -0
- package/dist/parser/lockfile.js +208 -16
- package/dist/render/html.js +562 -0
- package/dist/render/sarif.js +18 -0
- package/dist/scoring/scoring.js +22 -0
- package/dist/scoring/signals.js +11 -1
- package/dist/security/licenses.js +58 -0
- package/dist/security/typosquatting.js +181 -0
- package/package.json +1 -1
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generador de reportes visuales interactivos y autónomos en HTML.
|
|
3
|
+
* Diseñado para auditorías de seguridad, artifact de CI/CD e inspección visual
|
|
4
|
+
* sin dependencias externas (100% self-contained).
|
|
5
|
+
*/
|
|
6
|
+
import { THRESHOLDS } from '../scoring/scoring.js';
|
|
7
|
+
import { daysSince } from '../utils.js';
|
|
8
|
+
export function escapeHtml(str) {
|
|
9
|
+
return str
|
|
10
|
+
.replace(/&/g, '&')
|
|
11
|
+
.replace(/</g, '<')
|
|
12
|
+
.replace(/>/g, '>')
|
|
13
|
+
.replace(/"/g, '"')
|
|
14
|
+
.replace(/'/g, ''');
|
|
15
|
+
}
|
|
16
|
+
const CATEGORY_COLORS = {
|
|
17
|
+
healthy: { bg: '#064e3b', text: '#34d399', border: '#059669' },
|
|
18
|
+
caution: { bg: '#78350f', text: '#fcd34d', border: '#d97706' },
|
|
19
|
+
critical: { bg: '#7f1d1d', text: '#fca5a5', border: '#dc2626' },
|
|
20
|
+
};
|
|
21
|
+
export function renderHtml(reports, summary, now, meta) {
|
|
22
|
+
const t = meta.thresholds ?? THRESHOLDS;
|
|
23
|
+
const projectTitle = meta.projectName ? escapeHtml(meta.projectName) : 'Proyecto';
|
|
24
|
+
const isoDate = now.toISOString().slice(0, 10);
|
|
25
|
+
const rowsHtml = reports
|
|
26
|
+
.map((r, idx) => {
|
|
27
|
+
const category = r.result?.category ?? 'healthy';
|
|
28
|
+
const score = r.result ? r.result.score : r.status === 'error' ? 'ERR' : 'N/E';
|
|
29
|
+
const days = r.github ? daysSince(r.github.lastCommitAt, now) : null;
|
|
30
|
+
const maint = r.github
|
|
31
|
+
? `${r.github.activeMaintainers}${r.github.activeMaintainersCapped ? '+' : ''}`
|
|
32
|
+
: '—';
|
|
33
|
+
const alert = r.status === 'error'
|
|
34
|
+
? `Error: ${r.reason ?? 'desconocido'}`
|
|
35
|
+
: r.status === 'not-evaluable'
|
|
36
|
+
? `No evaluable: ${r.reason ?? ''}`
|
|
37
|
+
: r.result?.mainAlert
|
|
38
|
+
? r.result.mainAlert.message
|
|
39
|
+
: 'Sin alertas';
|
|
40
|
+
const hasScripts = Boolean(r.signals?.installScripts?.suspicious);
|
|
41
|
+
const rowClass = `report-row cat-${category} ${hasScripts ? 'has-scripts' : ''}`;
|
|
42
|
+
const statusIcon = r.status === 'error'
|
|
43
|
+
? '❌'
|
|
44
|
+
: r.status === 'not-evaluable'
|
|
45
|
+
? '⚪'
|
|
46
|
+
: category === 'critical'
|
|
47
|
+
? '🔴'
|
|
48
|
+
: category === 'caution'
|
|
49
|
+
? '🟡'
|
|
50
|
+
: '🟢';
|
|
51
|
+
const kindBadge = r.kind === 'devDependencies'
|
|
52
|
+
? '<span class="badge badge-dev">dev</span>'
|
|
53
|
+
: r.kind === 'transitive'
|
|
54
|
+
? `<span class="badge badge-trans" title="Vía: ${escapeHtml(r.via.join(' › '))}">transitiva</span>`
|
|
55
|
+
: '<span class="badge badge-prod">prod</span>';
|
|
56
|
+
const scriptBadge = hasScripts
|
|
57
|
+
? '<span class="badge badge-warn" title="Scripts sospechosos detectados">⚠️ script</span>'
|
|
58
|
+
: '';
|
|
59
|
+
const penaltiesHtml = r.result && r.result.penalties.length > 0
|
|
60
|
+
? `<div class="detail-block">
|
|
61
|
+
<h4>Penalizaciones aplicadas</h4>
|
|
62
|
+
<ul class="penalties-list">
|
|
63
|
+
${r.result.penalties
|
|
64
|
+
.map((p) => `<li><span class="penalty-pts">-${p.points}</span> <span>${escapeHtml(p.message)}</span></li>`)
|
|
65
|
+
.join('')}
|
|
66
|
+
</ul>
|
|
67
|
+
</div>`
|
|
68
|
+
: '<p class="text-muted">No se aplicaron penalizaciones.</p>';
|
|
69
|
+
const scriptsDetail = r.npm?.installScripts && r.npm.installScripts.scripts.length > 0
|
|
70
|
+
? `<div class="detail-block">
|
|
71
|
+
<h4>Lifecycle Scripts (${r.npm.installScripts.scripts.length})</h4>
|
|
72
|
+
<div class="scripts-list">
|
|
73
|
+
${r.npm.installScripts.scripts
|
|
74
|
+
.map((s) => {
|
|
75
|
+
const isSusp = s.suspicious;
|
|
76
|
+
return `<div class="script-item ${isSusp ? 'suspicious' : ''}">
|
|
77
|
+
<span class="script-stage">${escapeHtml(s.stage)}</span>
|
|
78
|
+
<code>${escapeHtml(s.command)}</code>
|
|
79
|
+
${isSusp && s.reason ? `<span class="pattern-tag">${escapeHtml(s.reason)}</span>` : ''}
|
|
80
|
+
</div>`;
|
|
81
|
+
})
|
|
82
|
+
.join('')}
|
|
83
|
+
</div>
|
|
84
|
+
</div>`
|
|
85
|
+
: '';
|
|
86
|
+
const viaDetail = r.via && r.via.length > 0
|
|
87
|
+
? `<div class="detail-block">
|
|
88
|
+
<h4>Cadena de dependencia</h4>
|
|
89
|
+
<div class="via-chain">${escapeHtml(r.via.join(' › '))} › <strong>${escapeHtml(r.name)}</strong></div>
|
|
90
|
+
</div>`
|
|
91
|
+
: '';
|
|
92
|
+
const linksDetail = `
|
|
93
|
+
<div class="detail-block links-block">
|
|
94
|
+
<a href="https://www.npmjs.com/package/${encodeURIComponent(r.registryName)}" target="_blank" rel="noopener noreferrer" class="link-btn">Ver en npm ↗</a>
|
|
95
|
+
${r.github
|
|
96
|
+
? `<a href="https://github.com/${encodeURIComponent(r.github.fullName)}" target="_blank" rel="noopener noreferrer" class="link-btn">GitHub (${escapeHtml(r.github.fullName)}) ↗</a>`
|
|
97
|
+
: ''}
|
|
98
|
+
</div>
|
|
99
|
+
`;
|
|
100
|
+
return `
|
|
101
|
+
<tr class="${rowClass}" data-index="${idx}" onclick="toggleDetails(${idx})">
|
|
102
|
+
<td class="text-center">${statusIcon}</td>
|
|
103
|
+
<td>
|
|
104
|
+
<div class="pkg-name">
|
|
105
|
+
<strong>${escapeHtml(r.name)}</strong>
|
|
106
|
+
${kindBadge}
|
|
107
|
+
${scriptBadge}
|
|
108
|
+
</div>
|
|
109
|
+
<div class="pkg-spec text-muted">${escapeHtml(r.spec)}</div>
|
|
110
|
+
</td>
|
|
111
|
+
<td class="text-center font-mono">
|
|
112
|
+
<span class="score-badge score-${category}">${score}</span>
|
|
113
|
+
</td>
|
|
114
|
+
<td class="text-center">${days !== null ? `${days}d` : '—'}</td>
|
|
115
|
+
<td class="text-center">${maint}</td>
|
|
116
|
+
<td>${escapeHtml(alert)}</td>
|
|
117
|
+
</tr>
|
|
118
|
+
<tr id="details-${idx}" class="details-row" style="display: none;">
|
|
119
|
+
<td colspan="6">
|
|
120
|
+
<div class="details-content">
|
|
121
|
+
${penaltiesHtml}
|
|
122
|
+
${scriptsDetail}
|
|
123
|
+
${viaDetail}
|
|
124
|
+
${linksDetail}
|
|
125
|
+
</div>
|
|
126
|
+
</td>
|
|
127
|
+
</tr>
|
|
128
|
+
`;
|
|
129
|
+
})
|
|
130
|
+
.join('');
|
|
131
|
+
return `<!DOCTYPE html>
|
|
132
|
+
<html lang="es">
|
|
133
|
+
<head>
|
|
134
|
+
<meta charset="UTF-8">
|
|
135
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
136
|
+
<title>GhostDeps Reporte — ${projectTitle}</title>
|
|
137
|
+
<style>
|
|
138
|
+
:root {
|
|
139
|
+
--bg: #0f172a;
|
|
140
|
+
--card-bg: #1e293b;
|
|
141
|
+
--card-border: #334155;
|
|
142
|
+
--text: #f8fafc;
|
|
143
|
+
--text-muted: #94a3b8;
|
|
144
|
+
--accent: #38bdf8;
|
|
145
|
+
--crit: #ef4444;
|
|
146
|
+
--crit-bg: #450a0a;
|
|
147
|
+
--caut: #f59e0b;
|
|
148
|
+
--caut-bg: #451a03;
|
|
149
|
+
--good: #10b981;
|
|
150
|
+
--good-bg: #022c22;
|
|
151
|
+
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
152
|
+
}
|
|
153
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
154
|
+
body {
|
|
155
|
+
background: var(--bg);
|
|
156
|
+
color: var(--text);
|
|
157
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
158
|
+
line-height: 1.5;
|
|
159
|
+
padding: 2rem 1rem;
|
|
160
|
+
}
|
|
161
|
+
.container {
|
|
162
|
+
max-width: 1200px;
|
|
163
|
+
margin: 0 auto;
|
|
164
|
+
}
|
|
165
|
+
header {
|
|
166
|
+
margin-bottom: 2rem;
|
|
167
|
+
border-bottom: 1px solid var(--card-border);
|
|
168
|
+
padding-bottom: 1.5rem;
|
|
169
|
+
}
|
|
170
|
+
.header-top {
|
|
171
|
+
display: flex;
|
|
172
|
+
justify-content: space-between;
|
|
173
|
+
align-items: center;
|
|
174
|
+
flex-wrap: wrap;
|
|
175
|
+
gap: 1rem;
|
|
176
|
+
}
|
|
177
|
+
h1 {
|
|
178
|
+
font-size: 1.8rem;
|
|
179
|
+
font-weight: 700;
|
|
180
|
+
display: flex;
|
|
181
|
+
align-items: center;
|
|
182
|
+
gap: 0.5rem;
|
|
183
|
+
}
|
|
184
|
+
.header-meta {
|
|
185
|
+
color: var(--text-muted);
|
|
186
|
+
font-size: 0.9rem;
|
|
187
|
+
margin-top: 0.25rem;
|
|
188
|
+
}
|
|
189
|
+
/* Summary Cards */
|
|
190
|
+
.summary-grid {
|
|
191
|
+
display: grid;
|
|
192
|
+
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
193
|
+
gap: 1rem;
|
|
194
|
+
margin-bottom: 2rem;
|
|
195
|
+
}
|
|
196
|
+
.card {
|
|
197
|
+
background: var(--card-bg);
|
|
198
|
+
border: 1px solid var(--card-border);
|
|
199
|
+
border-radius: 8px;
|
|
200
|
+
padding: 1rem 1.25rem;
|
|
201
|
+
}
|
|
202
|
+
.card-title {
|
|
203
|
+
font-size: 0.85rem;
|
|
204
|
+
text-transform: uppercase;
|
|
205
|
+
letter-spacing: 0.05em;
|
|
206
|
+
color: var(--text-muted);
|
|
207
|
+
margin-bottom: 0.25rem;
|
|
208
|
+
}
|
|
209
|
+
.card-value {
|
|
210
|
+
font-size: 2rem;
|
|
211
|
+
font-weight: 700;
|
|
212
|
+
font-family: var(--font-mono);
|
|
213
|
+
}
|
|
214
|
+
.card-crit { border-left: 4px solid var(--crit); color: #fca5a5; }
|
|
215
|
+
.card-caut { border-left: 4px solid var(--caut); color: #fcd34d; }
|
|
216
|
+
.card-good { border-left: 4px solid var(--good); color: #6ee7b7; }
|
|
217
|
+
.card-total { border-left: 4px solid var(--accent); color: #bae6fd; }
|
|
218
|
+
|
|
219
|
+
/* Controls / Filters */
|
|
220
|
+
.controls-bar {
|
|
221
|
+
display: flex;
|
|
222
|
+
flex-wrap: wrap;
|
|
223
|
+
gap: 1rem;
|
|
224
|
+
margin-bottom: 1.5rem;
|
|
225
|
+
align-items: center;
|
|
226
|
+
justify-content: space-between;
|
|
227
|
+
}
|
|
228
|
+
.filters {
|
|
229
|
+
display: flex;
|
|
230
|
+
flex-wrap: wrap;
|
|
231
|
+
gap: 0.5rem;
|
|
232
|
+
}
|
|
233
|
+
.btn-filter {
|
|
234
|
+
background: var(--card-bg);
|
|
235
|
+
border: 1px solid var(--card-border);
|
|
236
|
+
color: var(--text);
|
|
237
|
+
padding: 0.4rem 0.8rem;
|
|
238
|
+
border-radius: 6px;
|
|
239
|
+
cursor: pointer;
|
|
240
|
+
font-size: 0.85rem;
|
|
241
|
+
transition: all 0.15s ease;
|
|
242
|
+
}
|
|
243
|
+
.btn-filter:hover, .btn-filter.active {
|
|
244
|
+
background: #334155;
|
|
245
|
+
border-color: var(--accent);
|
|
246
|
+
color: #fff;
|
|
247
|
+
}
|
|
248
|
+
.search-box {
|
|
249
|
+
position: relative;
|
|
250
|
+
min-width: 260px;
|
|
251
|
+
}
|
|
252
|
+
.search-input {
|
|
253
|
+
width: 100%;
|
|
254
|
+
background: var(--card-bg);
|
|
255
|
+
border: 1px solid var(--card-border);
|
|
256
|
+
color: var(--text);
|
|
257
|
+
padding: 0.4rem 0.8rem;
|
|
258
|
+
border-radius: 6px;
|
|
259
|
+
font-size: 0.9rem;
|
|
260
|
+
outline: none;
|
|
261
|
+
}
|
|
262
|
+
.search-input:focus {
|
|
263
|
+
border-color: var(--accent);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* Table */
|
|
267
|
+
.table-container {
|
|
268
|
+
background: var(--card-bg);
|
|
269
|
+
border: 1px solid var(--card-border);
|
|
270
|
+
border-radius: 8px;
|
|
271
|
+
overflow-x: auto;
|
|
272
|
+
}
|
|
273
|
+
table {
|
|
274
|
+
width: 100%;
|
|
275
|
+
border-collapse: collapse;
|
|
276
|
+
text-align: left;
|
|
277
|
+
font-size: 0.9rem;
|
|
278
|
+
}
|
|
279
|
+
th {
|
|
280
|
+
background: #1e293b;
|
|
281
|
+
padding: 0.75rem 1rem;
|
|
282
|
+
border-bottom: 1px solid var(--card-border);
|
|
283
|
+
color: var(--text-muted);
|
|
284
|
+
font-weight: 600;
|
|
285
|
+
white-space: nowrap;
|
|
286
|
+
}
|
|
287
|
+
td {
|
|
288
|
+
padding: 0.75rem 1rem;
|
|
289
|
+
border-bottom: 1px solid #1e293b;
|
|
290
|
+
vertical-align: middle;
|
|
291
|
+
}
|
|
292
|
+
tr.report-row {
|
|
293
|
+
cursor: pointer;
|
|
294
|
+
transition: background 0.1s ease;
|
|
295
|
+
border-bottom: 1px solid #334155;
|
|
296
|
+
}
|
|
297
|
+
tr.report-row:hover {
|
|
298
|
+
background: #273549;
|
|
299
|
+
}
|
|
300
|
+
.text-center { text-align: center; }
|
|
301
|
+
.font-mono { font-family: var(--font-mono); }
|
|
302
|
+
.text-muted { color: var(--text-muted); font-size: 0.8rem; }
|
|
303
|
+
|
|
304
|
+
.pkg-name {
|
|
305
|
+
display: flex;
|
|
306
|
+
align-items: center;
|
|
307
|
+
gap: 0.5rem;
|
|
308
|
+
font-size: 0.95rem;
|
|
309
|
+
}
|
|
310
|
+
.badge {
|
|
311
|
+
font-size: 0.7rem;
|
|
312
|
+
padding: 0.15rem 0.4rem;
|
|
313
|
+
border-radius: 4px;
|
|
314
|
+
font-weight: 500;
|
|
315
|
+
text-transform: uppercase;
|
|
316
|
+
}
|
|
317
|
+
.badge-prod { background: #1e3a8a; color: #93c5fd; }
|
|
318
|
+
.badge-dev { background: #374151; color: #d1d5db; }
|
|
319
|
+
.badge-trans { background: #312e81; color: #c7d2fe; }
|
|
320
|
+
.badge-warn { background: #78350f; color: #fde68a; font-weight: 600; }
|
|
321
|
+
|
|
322
|
+
.score-badge {
|
|
323
|
+
display: inline-block;
|
|
324
|
+
min-width: 2.2rem;
|
|
325
|
+
padding: 0.2rem 0.4rem;
|
|
326
|
+
border-radius: 4px;
|
|
327
|
+
font-weight: bold;
|
|
328
|
+
text-align: center;
|
|
329
|
+
}
|
|
330
|
+
.score-healthy { background: var(--good-bg); color: #34d399; border: 1px solid #059669; }
|
|
331
|
+
.score-caution { background: var(--caut-bg); color: #fcd34d; border: 1px solid #d97706; }
|
|
332
|
+
.score-critical { background: var(--crit-bg); color: #fca5a5; border: 1px solid #dc2626; }
|
|
333
|
+
|
|
334
|
+
/* Details Row */
|
|
335
|
+
.details-row td {
|
|
336
|
+
background: #0f172a;
|
|
337
|
+
padding: 1.25rem;
|
|
338
|
+
border-bottom: 1px solid var(--card-border);
|
|
339
|
+
}
|
|
340
|
+
.details-content {
|
|
341
|
+
display: flex;
|
|
342
|
+
flex-direction: column;
|
|
343
|
+
gap: 1rem;
|
|
344
|
+
}
|
|
345
|
+
.detail-block h4 {
|
|
346
|
+
font-size: 0.85rem;
|
|
347
|
+
text-transform: uppercase;
|
|
348
|
+
letter-spacing: 0.05em;
|
|
349
|
+
color: var(--accent);
|
|
350
|
+
margin-bottom: 0.5rem;
|
|
351
|
+
}
|
|
352
|
+
.penalties-list {
|
|
353
|
+
list-style: none;
|
|
354
|
+
display: flex;
|
|
355
|
+
flex-direction: column;
|
|
356
|
+
gap: 0.4rem;
|
|
357
|
+
}
|
|
358
|
+
.penalties-list li {
|
|
359
|
+
display: flex;
|
|
360
|
+
align-items: center;
|
|
361
|
+
gap: 0.5rem;
|
|
362
|
+
font-size: 0.85rem;
|
|
363
|
+
}
|
|
364
|
+
.penalty-pts {
|
|
365
|
+
background: var(--crit-bg);
|
|
366
|
+
color: #fca5a5;
|
|
367
|
+
font-family: var(--font-mono);
|
|
368
|
+
font-size: 0.75rem;
|
|
369
|
+
padding: 0.1rem 0.35rem;
|
|
370
|
+
border-radius: 3px;
|
|
371
|
+
font-weight: bold;
|
|
372
|
+
}
|
|
373
|
+
.scripts-list {
|
|
374
|
+
display: flex;
|
|
375
|
+
flex-direction: column;
|
|
376
|
+
gap: 0.4rem;
|
|
377
|
+
}
|
|
378
|
+
.script-item {
|
|
379
|
+
background: #1e293b;
|
|
380
|
+
padding: 0.4rem 0.6rem;
|
|
381
|
+
border-radius: 4px;
|
|
382
|
+
font-size: 0.85rem;
|
|
383
|
+
display: flex;
|
|
384
|
+
align-items: center;
|
|
385
|
+
gap: 0.5rem;
|
|
386
|
+
flex-wrap: wrap;
|
|
387
|
+
}
|
|
388
|
+
.script-item.suspicious {
|
|
389
|
+
border-left: 3px solid var(--crit);
|
|
390
|
+
background: #2a1515;
|
|
391
|
+
}
|
|
392
|
+
.script-stage {
|
|
393
|
+
color: var(--text-muted);
|
|
394
|
+
font-weight: 600;
|
|
395
|
+
}
|
|
396
|
+
.pattern-tag {
|
|
397
|
+
background: #991b1b;
|
|
398
|
+
color: #fecaca;
|
|
399
|
+
font-size: 0.7rem;
|
|
400
|
+
padding: 0.1rem 0.4rem;
|
|
401
|
+
border-radius: 3px;
|
|
402
|
+
}
|
|
403
|
+
.via-chain {
|
|
404
|
+
font-family: var(--font-mono);
|
|
405
|
+
font-size: 0.85rem;
|
|
406
|
+
color: #cbd5e1;
|
|
407
|
+
}
|
|
408
|
+
.links-block {
|
|
409
|
+
display: flex;
|
|
410
|
+
gap: 0.75rem;
|
|
411
|
+
margin-top: 0.25rem;
|
|
412
|
+
}
|
|
413
|
+
.link-btn {
|
|
414
|
+
color: var(--accent);
|
|
415
|
+
text-decoration: none;
|
|
416
|
+
font-size: 0.85rem;
|
|
417
|
+
border: 1px solid #0284c7;
|
|
418
|
+
padding: 0.25rem 0.6rem;
|
|
419
|
+
border-radius: 4px;
|
|
420
|
+
transition: background 0.15s ease;
|
|
421
|
+
}
|
|
422
|
+
.link-btn:hover {
|
|
423
|
+
background: #0369a1;
|
|
424
|
+
color: #fff;
|
|
425
|
+
}
|
|
426
|
+
footer {
|
|
427
|
+
margin-top: 2rem;
|
|
428
|
+
padding-top: 1rem;
|
|
429
|
+
border-top: 1px solid var(--card-border);
|
|
430
|
+
color: var(--text-muted);
|
|
431
|
+
font-size: 0.8rem;
|
|
432
|
+
display: flex;
|
|
433
|
+
justify-content: space-between;
|
|
434
|
+
flex-wrap: wrap;
|
|
435
|
+
gap: 0.5rem;
|
|
436
|
+
}
|
|
437
|
+
</style>
|
|
438
|
+
</head>
|
|
439
|
+
<body>
|
|
440
|
+
<div class="container">
|
|
441
|
+
<header>
|
|
442
|
+
<div class="header-top">
|
|
443
|
+
<div>
|
|
444
|
+
<h1>👻 GhostDeps Security Report</h1>
|
|
445
|
+
<div class="header-meta">
|
|
446
|
+
<span>Proyecto: <strong>${projectTitle}</strong></span> ·
|
|
447
|
+
<span>Generado el ${isoDate}</span> ·
|
|
448
|
+
<span>v${escapeHtml(meta.version)}</span>
|
|
449
|
+
</div>
|
|
450
|
+
</div>
|
|
451
|
+
</div>
|
|
452
|
+
</header>
|
|
453
|
+
|
|
454
|
+
<div class="summary-grid">
|
|
455
|
+
<div class="card card-total">
|
|
456
|
+
<div class="card-title">Total analizadas</div>
|
|
457
|
+
<div class="card-value">${summary.total}</div>
|
|
458
|
+
</div>
|
|
459
|
+
<div class="card card-crit">
|
|
460
|
+
<div class="card-title">Crítico / Fantasma</div>
|
|
461
|
+
<div class="card-value">${summary.critical}</div>
|
|
462
|
+
</div>
|
|
463
|
+
<div class="card card-caut">
|
|
464
|
+
<div class="card-title">Precaución</div>
|
|
465
|
+
<div class="card-value">${summary.caution}</div>
|
|
466
|
+
</div>
|
|
467
|
+
<div class="card card-good">
|
|
468
|
+
<div class="card-title">Saludable</div>
|
|
469
|
+
<div class="card-value">${summary.healthy}</div>
|
|
470
|
+
</div>
|
|
471
|
+
</div>
|
|
472
|
+
|
|
473
|
+
<div class="controls-bar">
|
|
474
|
+
<div class="filters">
|
|
475
|
+
<button class="btn-filter active" onclick="setFilter('all')">Todas (${summary.total})</button>
|
|
476
|
+
<button class="btn-filter" onclick="setFilter('critical')">🔴 Críticas (${summary.critical})</button>
|
|
477
|
+
<button class="btn-filter" onclick="setFilter('caution')">🟡 Precaución (${summary.caution})</button>
|
|
478
|
+
<button class="btn-filter" onclick="setFilter('healthy')">🟢 Saludables (${summary.healthy})</button>
|
|
479
|
+
<button class="btn-filter" onclick="setFilter('scripts')">⚠️ Install Scripts</button>
|
|
480
|
+
</div>
|
|
481
|
+
<div class="search-box">
|
|
482
|
+
<input type="text" id="searchInput" class="search-input" placeholder="Buscar dependencia o alerta..." oninput="handleSearch()">
|
|
483
|
+
</div>
|
|
484
|
+
</div>
|
|
485
|
+
|
|
486
|
+
<div class="table-container">
|
|
487
|
+
<table>
|
|
488
|
+
<thead>
|
|
489
|
+
<tr>
|
|
490
|
+
<th class="text-center" style="width: 40px;"></th>
|
|
491
|
+
<th>Paquete</th>
|
|
492
|
+
<th class="text-center" style="width: 80px;">Score</th>
|
|
493
|
+
<th class="text-center" style="width: 90px;">Últ. commit</th>
|
|
494
|
+
<th class="text-center" style="width: 80px;">Mant.</th>
|
|
495
|
+
<th>Alerta principal</th>
|
|
496
|
+
</tr>
|
|
497
|
+
</thead>
|
|
498
|
+
<tbody id="reportTableBody">
|
|
499
|
+
${rowsHtml}
|
|
500
|
+
</tbody>
|
|
501
|
+
</table>
|
|
502
|
+
</div>
|
|
503
|
+
|
|
504
|
+
<footer>
|
|
505
|
+
<div>Umbrales: 🟢 ≥ ${t.healthy} · 🟡 ${t.caution}–${t.healthy - 1} · 🔴 < ${t.caution}</div>
|
|
506
|
+
<div>Desarrollado con GhostDeps por @efraindrummer</div>
|
|
507
|
+
</footer>
|
|
508
|
+
</div>
|
|
509
|
+
|
|
510
|
+
<script>
|
|
511
|
+
let currentFilter = 'all';
|
|
512
|
+
|
|
513
|
+
function toggleDetails(idx) {
|
|
514
|
+
const el = document.getElementById('details-' + idx);
|
|
515
|
+
if (!el) return;
|
|
516
|
+
el.style.display = el.style.display === 'none' ? 'table-row' : 'none';
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function setFilter(filter) {
|
|
520
|
+
currentFilter = filter;
|
|
521
|
+
document.querySelectorAll('.btn-filter').forEach(btn => btn.classList.remove('active'));
|
|
522
|
+
event.target.classList.add('active');
|
|
523
|
+
applyFilters();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function handleSearch() {
|
|
527
|
+
applyFilters();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function applyFilters() {
|
|
531
|
+
const q = (document.getElementById('searchInput').value || '').toLowerCase().trim();
|
|
532
|
+
const rows = document.querySelectorAll('tr.report-row');
|
|
533
|
+
|
|
534
|
+
rows.forEach(row => {
|
|
535
|
+
const idx = row.getAttribute('data-index');
|
|
536
|
+
const detailsRow = document.getElementById('details-' + idx);
|
|
537
|
+
let matchFilter = true;
|
|
538
|
+
|
|
539
|
+
if (currentFilter === 'critical') matchFilter = row.classList.contains('cat-critical');
|
|
540
|
+
else if (currentFilter === 'caution') matchFilter = row.classList.contains('cat-caution');
|
|
541
|
+
else if (currentFilter === 'healthy') matchFilter = row.classList.contains('cat-healthy');
|
|
542
|
+
else if (currentFilter === 'scripts') matchFilter = row.classList.contains('has-scripts');
|
|
543
|
+
|
|
544
|
+
let matchSearch = true;
|
|
545
|
+
if (q) {
|
|
546
|
+
const text = row.innerText.toLowerCase();
|
|
547
|
+
matchSearch = text.includes(q);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (matchFilter && matchSearch) {
|
|
551
|
+
row.style.display = '';
|
|
552
|
+
} else {
|
|
553
|
+
row.style.display = 'none';
|
|
554
|
+
if (detailsRow) detailsRow.style.display = 'none';
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
</script>
|
|
559
|
+
</body>
|
|
560
|
+
</html>
|
|
561
|
+
`;
|
|
562
|
+
}
|
package/dist/render/sarif.js
CHANGED
|
@@ -66,6 +66,24 @@ export const SARIF_RULES = {
|
|
|
66
66
|
shortDescription: { text: 'Tiempo excesivo transcurrido desde la última publicación en npm' },
|
|
67
67
|
defaultConfiguration: { level: 'note' },
|
|
68
68
|
},
|
|
69
|
+
'suspicious-install-scripts': {
|
|
70
|
+
id: 'GD011',
|
|
71
|
+
name: 'SuspiciousInstallScript',
|
|
72
|
+
shortDescription: { text: 'Script de ciclo de vida de instalación potencialmente peligroso (pre/install/postinstall)' },
|
|
73
|
+
defaultConfiguration: { level: 'error' },
|
|
74
|
+
},
|
|
75
|
+
'typosquatting': {
|
|
76
|
+
id: 'GD012',
|
|
77
|
+
name: 'TyposquattingSuspect',
|
|
78
|
+
shortDescription: { text: 'Posible intento de typosquatting o suplantación de paquete popular' },
|
|
79
|
+
defaultConfiguration: { level: 'error' },
|
|
80
|
+
},
|
|
81
|
+
'license-violation': {
|
|
82
|
+
id: 'GD013',
|
|
83
|
+
name: 'LicenseComplianceViolation',
|
|
84
|
+
shortDescription: { text: 'Infracción de política de licencias permitidas/denegadas o licencia copyleft' },
|
|
85
|
+
defaultConfiguration: { level: 'warning' },
|
|
86
|
+
},
|
|
69
87
|
};
|
|
70
88
|
export function renderSarif(reports, options) {
|
|
71
89
|
const t = options.thresholds ?? THRESHOLDS;
|
package/dist/scoring/scoring.js
CHANGED
|
@@ -17,6 +17,9 @@ export const DEFAULT_WEIGHTS = Object.freeze({
|
|
|
17
17
|
maintainersChanged: 15,
|
|
18
18
|
newPublisher: 15,
|
|
19
19
|
hijackPattern: 15,
|
|
20
|
+
suspiciousScripts: 35,
|
|
21
|
+
typosquatting: 50,
|
|
22
|
+
licenseViolation: 30,
|
|
20
23
|
dormantRevivalDays: 365,
|
|
21
24
|
});
|
|
22
25
|
export const THRESHOLDS = Object.freeze({
|
|
@@ -30,9 +33,12 @@ export const CATEGORY_LABELS = {
|
|
|
30
33
|
};
|
|
31
34
|
/** Prioridad para desempatar la alerta principal cuando dos penalizaciones pesan igual. */
|
|
32
35
|
const PRIORITY = [
|
|
36
|
+
'typosquatting',
|
|
37
|
+
'suspicious-install-scripts',
|
|
33
38
|
'hijack-pattern',
|
|
34
39
|
'archived',
|
|
35
40
|
'deprecated',
|
|
41
|
+
'license-violation',
|
|
36
42
|
'new-publisher',
|
|
37
43
|
'maintainers-changed',
|
|
38
44
|
'abandoned',
|
|
@@ -101,6 +107,22 @@ export function computeScore(s, w = DEFAULT_WEIGHTS, t = THRESHOLDS) {
|
|
|
101
107
|
: 'junto a otra señal de transferencia';
|
|
102
108
|
add('hijack-pattern', w.hijackPattern, `Patrón de posible secuestro: publicador nuevo ${why}`);
|
|
103
109
|
}
|
|
110
|
+
// --- Scripts de instalación sospechosos ---
|
|
111
|
+
if (s.installScripts?.suspicious) {
|
|
112
|
+
const reasons = s.installScripts.scripts
|
|
113
|
+
.filter((sc) => sc.suspicious)
|
|
114
|
+
.map((sc) => `${sc.stage} (${sc.reason ?? 'sospechoso'})`)
|
|
115
|
+
.join(', ');
|
|
116
|
+
add('suspicious-install-scripts', w.suspiciousScripts ?? 35, `Script de instalación potencialmente peligroso: ${reasons}`);
|
|
117
|
+
}
|
|
118
|
+
// --- Typosquatting / Similitud sospechosa con paquetes populares ---
|
|
119
|
+
if (s.typosquatting) {
|
|
120
|
+
add('typosquatting', w.typosquatting ?? 50, `Posible typosquatting: ${s.typosquatting.similarityReason}`);
|
|
121
|
+
}
|
|
122
|
+
// --- Infracción de políticas de licencias ---
|
|
123
|
+
if (s.licenseDenied) {
|
|
124
|
+
add('license-violation', w.licenseViolation ?? 30, s.licenseDeniedReason ?? 'Infracción de política de licencias de software');
|
|
125
|
+
}
|
|
104
126
|
const total = penalties.reduce((acc, p) => acc + p.points, 0);
|
|
105
127
|
const score = Math.max(0, Math.min(100, 100 - total));
|
|
106
128
|
const sorted = [...penalties].sort((a, b) => b.points - a.points || PRIORITY.indexOf(a.id) - PRIORITY.indexOf(b.id));
|
package/dist/scoring/signals.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { checkLicenseCompliance } from '../security/licenses.js';
|
|
2
|
+
import { detectTyposquatting } from '../security/typosquatting.js';
|
|
1
3
|
import { daysBetween, daysSince } from '../utils.js';
|
|
2
4
|
/** Convierte datos crudos de npm + GitHub en señales normalizadas para el scoring. */
|
|
3
|
-
export function buildSignals(npm, gh, now) {
|
|
5
|
+
export function buildSignals(npm, gh, now, options = {}) {
|
|
4
6
|
const newPublisher = npm.latestPublisher !== null &&
|
|
5
7
|
npm.previousPublishers.length > 0 &&
|
|
6
8
|
!npm.previousPublishers.includes(npm.latestPublisher);
|
|
9
|
+
const typo = detectTyposquatting(npm.name);
|
|
10
|
+
const lic = checkLicenseCompliance(npm.license, options);
|
|
7
11
|
return {
|
|
8
12
|
daysSinceLastCommit: daysSince(gh.lastCommitAt, now),
|
|
9
13
|
daysSinceLastPublish: daysSince(npm.latestPublishedAt, now),
|
|
@@ -15,5 +19,11 @@ export function buildSignals(npm, gh, now) {
|
|
|
15
19
|
repoRedirected: gh.redirected,
|
|
16
20
|
maintainersAdded: npm.maintainersChange?.added ?? [],
|
|
17
21
|
newPublisher,
|
|
22
|
+
installScripts: npm.installScripts,
|
|
23
|
+
typosquatting: typo,
|
|
24
|
+
hasProvenance: npm.hasProvenance,
|
|
25
|
+
license: npm.license,
|
|
26
|
+
licenseDenied: lic.isDenied,
|
|
27
|
+
licenseDeniedReason: lic.reason,
|
|
18
28
|
};
|
|
19
29
|
}
|