Skip to content

Commit 51e5724

Browse files
committed
refactor: simplify state handling and update UI component rendering in module-registry.js
1 parent ba3e5c8 commit 51e5724

1 file changed

Lines changed: 61 additions & 13 deletions

File tree

internal/api/ui/pages/module-registry.js

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,73 @@
245245
/* ── JS Analysis ────────────────────────────────────────────────────── */
246246
js: {
247247
columns: [
248-
{ id: 'file', label: 'JS FILE', flex: '2', type: 'link-amber' },
249-
{ id: 'type', label: 'TYPE', w: '58px', type: 'label-badge', align: 'center' },
250-
{ id: 'finding', label: 'FINDING', flex: '3', type: 'mono-trunc' },
251-
{ id: 'module', label: 'MODULE', flex: '1', type: 'mod-badge' },
248+
{ id: 'file', label: 'JS FILE', flex: '2', type: 'link-amber' },
249+
{ id: 'sev', label: 'SEV', w: '68px', type: 'sev-badge', align: 'center' },
250+
{ id: 'secretType', label: 'SECRET TYPE', flex: '1', type: 'badge-pill' },
251+
{ id: 'secret', label: 'SECRET VALUE', flex: '3', type: 'mono-trunc' },
252252
],
253-
extract(r, modInfo) {
254-
// Note: r.file is the artifact filename (e.g. js-secrets-vulnerabilities.json), not the target URL.
255-
const file = s(r.target || r.source_file || '-');
256-
const matcher = s(r.matcher || r.finding_type || '');
257-
const value = s(r.finding || r.value || '-');
253+
extract(r) {
254+
const raw = r.raw || {};
255+
// JS file URL (the source .js file where the secret was found)
256+
const file = s(r.target || raw.matched_at || r.source_file || '-');
257+
258+
// Secret type: read from raw.secret_type → parse from finding bracket → template-id → fallback
259+
let secretType = s(raw.secret_type || raw.secretType || '');
260+
if (!secretType) {
261+
// Parse from "[secretType] url -> value" format stored in finding
262+
const m = s(r.finding || '').match(/^\[([^\]]+)\]/);
263+
if (m) secretType = m[1];
264+
}
265+
if (!secretType) {
266+
// Strip "JS Secret Exposure (" prefix from template_id
267+
secretType = s(raw.template_id || r.finding || '—')
268+
.replace(/^JS Secret Exposure\s*\(?\s*/i, '')
269+
.replace(/\)$/, '');
270+
}
271+
272+
// Secret value: read from raw.secret → parse after "->" in finding
273+
let secretVal = s(raw.secret || '');
274+
if (!secretVal) {
275+
const finding = s(r.finding || '');
276+
const arrowIdx = finding.indexOf('->');
277+
if (arrowIdx !== -1) secretVal = finding.slice(arrowIdx + 2).trim();
278+
}
279+
if (!secretVal) secretVal = '—';
280+
281+
// Colour by severity of secret type
282+
const highTypes = new Set(['api_key', 'apikey', 'apikey_patterns', 'private_key', 'aws_access_key_id', 'aws_secret', 'password', 'passwd', 'client_secret', 'client_id_secret']);
283+
const medTypes = new Set(['access_token', 'auth_token', 'bearer_token', 'jwt', 'session', 'refresh_token']);
284+
const tl = secretType.toLowerCase().replace(/\s+/g, '_');
285+
const color = highTypes.has(tl) ? '#f87171' : medTypes.has(tl) ? '#fb923c' : '#a78bfa';
286+
258287
return {
259-
file: { href: toHref(file), label: file, color: '#f59e0b' },
260-
type: { label: 'JS', bg: 'rgba(245,158,11,.12)', color: '#fbbf24' },
261-
finding: matcher ? `[${matcher}] ${value}` : value,
262-
module: modInfo,
288+
file: { href: toHref(file), label: file, color: '#f59e0b' },
289+
sev: sevMeta(r.severity || 'high'),
290+
secretType: { label: secretType || 'unknown', color },
291+
secret: secretVal,
263292
};
264293
},
294+
detail(r) {
295+
const raw = r.raw || {};
296+
const file = s(r.target || raw.matched_at || r.source_file || '');
297+
const finding = s(r.finding || '');
298+
const secret = s(raw.secret || '');
299+
const secType = s(raw.secret_type || raw.secretType || '');
300+
const tmplId = s(raw.template_id || '');
301+
return buildFields([
302+
['JS File', file, { isLink: true }],
303+
['Secret Type', secType || tmplId],
304+
['Secret Value', secret || (() => {
305+
const ai = finding.indexOf('->');
306+
return ai !== -1 ? finding.slice(ai + 2).trim() : '';
307+
})(), { code: true }],
308+
['Severity', s(r.severity)],
309+
['Raw Finding', finding, { full: true }],
310+
]);
311+
},
265312
},
266313

314+
267315
/* ── Misconfig ──────────────────────────────────────────────────────── */
268316
misconfig: {
269317
columns: [

0 commit comments

Comments
 (0)