Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1430,9 +1430,15 @@ step.
amber with no link.
- **A run's page** (`#security/run/<repo-id>/<run-id>`; the run id is its result file's name). It shows:
- a header with the type, repo, branch and commit, scope or target, account (last 4 digits),
region, start time, duration, status, and the job id with **Copy**;
region, start time, duration, status, and the job id with **Copy**, laid out the same for code
reviews, threat models and pentests;
- for a threat model or pentest, an **Overview** card with the overview Security Agent wrote:
the first paragraph, and the whole document on **Show full overview**. It is drawn as plain
text with headings, paragraphs, lists, inline code and bold only; links show their text and
images their alt text, because the overview comes from AWS and the repo's own docs;
- the counts by severity, then every finding, most severe first, with a severity filter. Open a
finding for its full description. A threat model also shows its recommendation and evidence.
finding for its full description. A threat model also shows its recommendation, the components
and assets it affects (saved from prism-cli 1.20.1 on) and its evidence.
Code reviews and pentests show `No remediation provided by this run type.`: Security Agent
returns no remediation text for them;
- the result file (shown with `~`) and the same run's `prism-cli security findings` (or `security
Expand Down
4 changes: 2 additions & 2 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prism-d1/cli",
"version": "1.19.2",
"version": "1.20.1",
"description": "PRISM D1 Velocity CLI — AI development lifecycle assessment tool",
"author": "andklee",
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions cli/src/codewatch/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface Finding {
stride?: string[];
recommendation?: string;
evidence?: string[];
/** security-threat-model only: the components and assets the threat affects (impactedAssets). Absent before 1.20.1. */
assets?: string[];
/** security-pentest only: the agent's confidence (HIGH | MEDIUM | LOW | FALSE_POSITIVE). */
confidence?: string;
}
Expand Down
67 changes: 67 additions & 0 deletions cli/src/dashboard/markdown-lite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* A small, safe markdown renderer for text that comes from AWS or a repo's own
* docs (a threat model's system overview, a pentest overview): untrusted.
*
* Built only with createElement and text nodes, never innerHTML, and no
* attributes at all. It keeps headings, paragraphs, lists, inline code, bold
* and fenced code. Anything else is text: a link shows its text only, an
* image its alt text, a table or a quote its lines as written, and HTML tags
* appear as the characters they are. A JS string concatenated into page.ts's
* script, like the other page modules; it needs only `document`.
*/
export const MARKDOWN_SCRIPT = `
/** Inline: \`code\` and **bold**; [text](url) and ![alt](src) become their text (a URL may hold one level of parentheses). Everything else is a text node. */
function mdInline(s) {
const out = [];
const re = /(\\x60[^\\x60]+\\x60)|(\\*\\*[^*]+\\*\\*)|(!?\\[([^\\]]*)\\]\\((?:[^()]|\\([^()]*\\))*\\))/g;
let at = 0, m;
while ((m = re.exec(s))) {
if (m.index > at) out.push(document.createTextNode(s.slice(at, m.index)));
if (m[1]) { const c = document.createElement('code'); c.textContent = m[1].slice(1, -1); out.push(c); }
else if (m[2]) { const b = document.createElement('strong'); b.textContent = m[2].slice(2, -2); out.push(b); }
else out.push(document.createTextNode(m[4]));
at = re.lastIndex;
}
if (at < s.length) out.push(document.createTextNode(s.slice(at)));
return out;
}
/**
* Block level: # headings (shown one level under the card's own h2), - * + and 1. lists (nesting
* flattened), \\x60\\x60\\x60 fences and | tables as preformatted text, blank lines between paragraphs.
* Returns the nodes, in order; mdFirst() returns the first paragraph only.
*/
function mdBlocks(text, onlyFirst) {
const nodes = [], lines = String(text || '').replace(/\\r\\n/g, '\\n').split('\\n');
let para = [], list = null, pre = null, preKind = null;
const add = (tag, kids) => { const n = document.createElement(tag); for (const k of kids) n.append(k); nodes.push(n); return n; };
const flushPara = () => { if (para.length) add('p', mdInline(para.join(' '))); para = []; };
const flushList = () => { list = null; };
const flushPre = () => { if (pre !== null) { const n = add('pre', []); n.textContent = pre.join('\\n'); } pre = null; preKind = null; };
for (const raw of lines) {
if (onlyFirst && nodes.some((n) => n.nodeName === 'P')) break;
const line = raw.replace(/\\s+$/, '');
if (preKind === 'fence') { if (/^\\s*\\x60\\x60\\x60/.test(line)) flushPre(); else pre.push(raw); continue; }
if (/^\\s*\\x60\\x60\\x60/.test(line)) { flushPara(); flushList(); flushPre(); pre = []; preKind = 'fence'; continue; }
if (preKind === 'table' && !/^\\s*\\|/.test(line)) flushPre();
if (/^\\s*\\|/.test(line)) { flushPara(); flushList(); if (preKind !== 'table') { pre = []; preKind = 'table'; } pre.push(line.trim()); continue; }
if (!line.trim()) { flushPara(); flushList(); continue; }
const h = /^\\s*(#{1,6})\\s+(.*)$/.exec(line);
if (h) { flushPara(); flushList(); add('h' + Math.min(6, h[1].length + 2), mdInline(h[2].replace(/\\s+#+\\s*$/, ''))); continue; }
const li = /^\\s*([-*+]|\\d+[.)])\\s+(.*)$/.exec(line);
if (li) {
flushPara();
const tag = /\\d/.test(li[1]) ? 'OL' : 'UL';
if (!list || list.nodeName !== tag) list = add(tag.toLowerCase(), []);
const item = document.createElement('li');
for (const k of mdInline(li[2])) item.append(k);
list.append(item);
continue;
}
flushList();
para.push(line.trim().replace(/^>\\s?/, ''));
}
flushPara(); flushPre();
return onlyFirst ? nodes.filter((n) => n.nodeName === 'P').slice(0, 1) : nodes;
}
`;
2 changes: 2 additions & 0 deletions cli/src/dashboard/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SETTINGS_SCRIPT, SETTINGS_STYLE } from './settings-page.js';
import { SECURITY_SCRIPT, SECURITY_STYLE } from './security-page.js';
import { SECURITY_RUNS_SCRIPT, SECURITY_RUNS_STYLE } from './security-runs-page.js';
import { ACCOUNTGUARD_SCRIPT, ACCOUNTGUARD_STYLE } from './accountguard-page.js';
import { MARKDOWN_SCRIPT } from './markdown-lite.js';
import { REPO_SCRIPT } from './repo-page.js';
import { getAssetPath } from '../utils/root.js';

Expand Down Expand Up @@ -587,6 +588,7 @@ async function render() {
return data;
}
${SETUP_SCRIPT}
${MARKDOWN_SCRIPT}
${SECURITY_RUNS_SCRIPT}
${SECURITY_SCRIPT}
${ACCOUNTGUARD_SCRIPT}
Expand Down
35 changes: 28 additions & 7 deletions cli/src/dashboard/security-runs-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ table.runs .rgo { text-align:right; white-space:nowrap; } .rgo a { font-weight:6
table.runs .rrepo small, table.runs .rwhen small { display:inline; margin-left:6px; }
.runfilters .count { margin-left:0; flex-basis:100%; }
}
.rundl { display:grid; grid-template-columns:max-content minmax(0,1fr); gap:6px 18px; font-size:13px; margin:0; }
.rundl { display:grid; grid-template-columns:max-content minmax(0,1fr); gap:6px 18px; font-size:13px; margin:0; align-content:start; }
.rundl dt { color:var(--muted); } .rundl dd { margin:0; overflow-wrap:anywhere; }
.runhead h3 { margin-top:0; }
.runhead { display:grid; grid-template-columns:minmax(0,1.4fr) minmax(0,1fr); gap:18px; }
.runhead { display:grid; grid-template-columns:minmax(0,1.4fr) minmax(0,1fr); gap:18px; align-items:start; }
.runov { overflow-wrap:anywhere; } .runov h3, .runov h4, .runov h5, .runov h6 { margin:14px 0 6px; } .runov p, .runov li { font-size:13px; } .runov ul, .runov ol { padding-left:20px; margin:4px 0 8px; }
.runov pre { white-space:pre-wrap; overflow-wrap:anywhere; font-size:12px; background:var(--raised); border-radius:6px; padding:8px 10px; }
@media (max-width: 860px) { .runhead { grid-template-columns:minmax(0,1fr); } }
.sevboxes { display:flex; flex-wrap:wrap; gap:8px; margin:6px 0 2px; }
.sevbox { border:1px solid var(--line); border-radius:10px; padding:6px 12px; min-width:84px; background:var(--raised); }
Expand Down Expand Up @@ -205,14 +207,14 @@ const RUN_RE = new RegExp('^#security/run/([a-f0-9]{16})/([A-Za-z0-9_-]{1,200})$
function runRoute() { const m = RUN_RE.exec(location.hash); return m ? { repo: m[1], run: m[2] } : null; }
let RUN_DETAIL = null, RUN_KEY = null, RUN_FETCH = null, RUN_SHOWN = null;
/** What the person chose on the run's page (severity filter, open findings): kept across a refresh's repaint, dropped on leaving. */
let RUN_UI = { key: null, pick: '', open: null };
let RUN_UI = { key: null, pick: '', open: null, overview: false };
/**
* Only a run without a verdict yet can change under the page: its copy is read again on every draw
* (route entry, the minute refresh). A finished run and a server's not found (404) are final.
*/
const runStale = (d) => !!d && d.found && (d.run.status === 'running' || d.run.status === 'noverdict');
/** Leaving the drill-down (the router calls this) drops its copy, so coming back always reads the run again. */
function runLeave() { RUN_DETAIL = null; RUN_KEY = null; RUN_SHOWN = null; RUN_UI = { key: null, pick: '', open: null }; }
function runLeave() { RUN_DETAIL = null; RUN_KEY = null; RUN_SHOWN = null; RUN_UI = { key: null, pick: '', open: null, overview: false }; }
/** Draws the cached copy (when there is one and it is not on screen), then reads the run again if it may have changed. */
async function drawRunDetail(root, route) {
Expand Down Expand Up @@ -248,7 +250,7 @@ async function drawRunDetail(root, route) {
function paintRunDetail(root, d, key) {
// Keep which findings are open across a repaint of the same run.
if (RUN_UI.key === key && RUN_SHOWN === key) RUN_UI.open = new Set([...root.querySelectorAll('details[data-fid]')].filter((x) => x.open).map((x) => x.getAttribute('data-fid')));
else if (RUN_UI.key !== key) RUN_UI = { key, pick: '', open: null };
else if (RUN_UI.key !== key) RUN_UI = { key, pick: '', open: null, overview: false };
RUN_SHOWN = key;
const back = el('a', { href: '#security' }, 'Back to Security runs');
if (!d.found) {
Expand Down Expand Up @@ -277,9 +279,9 @@ function runDetail(d) {
...kv('Job', r.job_id ? copyButton(txt(r.job_id)) : null)),
el('div', {},
el('h3', {}, r.type === 'threat-model' ? 'Threats by severity' : 'Findings by severity'),
el('div', { class: 'sevboxes' }, ...RUN_SEVS.map((s) => el('div', { class: 'sevbox ' + ((c[s] || 0) ? s : 'zero') }, el('b', {}, String(c[s] || 0)), el('span', {}, s)))),
d.overview ? el('p', { class: 'fix' }, 'Overview: ' + txt(d.overview)) : null)));
el('div', { class: 'sevboxes' }, ...RUN_SEVS.map((s) => el('div', { class: 'sevbox ' + ((c[s] || 0) ? s : 'zero') }, el('b', {}, String(c[s] || 0)), el('span', {}, s)))))));
const out = [crumbs, head];
if (d.overview) out.push(runOverview(d));
if (r.status === 'failed') out.push(el('section', { class: 'card' }, el('h2', {}, 'Why there is no verdict'), el('p', {}, txt(r.reason) || 'The job did not complete.')));
if (r.status === 'running' || r.status === 'noverdict') out.push(el('section', { class: 'card' }, el('h2', {}, r.status === 'running' ? 'Still running' : 'No verdict fetched yet'),
el('p', { class: 'fix' }, (r.status === 'running' ? 'Findings appear here when the job finishes. ' : 'The job most likely finished. ') + 'Fetch them on the ', el('a', { href: '#security/' + txt(r.repo_id) }, 'Security Agent page'), ', or run the command below.')));
Expand All @@ -291,6 +293,24 @@ function runDetail(d) {
return out;
}
/**
* The run's overview (a threat model's system overview, a pentest's), its own full-width card: the first
* paragraph, then the whole document on Show full overview. Untrusted markdown, drawn by mdBlocks (text only).
*/
function runOverview(d) {
const body = el('div', { class: 'runov' }), toggle = el('button', { type: 'button', 'data-overview-toggle': '' });
const draw = () => {
const full = !!RUN_UI.overview;
body.setAttribute('data-run-overview', full ? 'full' : 'short');
body.replaceChildren(...mdBlocks(d.overview, !full));
toggle.textContent = full ? 'Show less' : 'Show full overview';
toggle.setAttribute('aria-expanded', String(full));
};
toggle.addEventListener('click', () => { RUN_UI.overview = !RUN_UI.overview; draw(); });
draw();
return el('section', { class: 'card', 'data-run-overview-card': '' }, el('h2', {}, 'Overview', el('span', { class: 'sub' }, d.run.type === 'threat-model' ? 'the system as Security Agent described it' : 'from Security Agent')), body, el('div', { class: 'srow-ctl' }, toggle));
}
function runFindingsCard(d) {
const r = d.run, fs = d.findings || [], label = r.type === 'threat-model' ? 'Threats' : 'Findings';
const s = el('section', { class: 'card', 'data-run-findings': String(fs.length) }, el('h2', {}, label, el('span', { class: 'sub' }, fs.length ? 'most severe first; open one for the full description' + (d.no_remediation ? '' : ' and recommendation') : '')));
Expand Down Expand Up @@ -323,6 +343,7 @@ function runFinding(f, d, open, id) {
el('div', { class: 'body' },
el('h4', {}, thr ? 'Threat' : 'Description'), el('p', {}, txt(f.description) || 'No description saved.'),
el('h4', {}, thr ? 'Recommendation' : 'Remediation'), el('p', { class: f.remediation ? null : 'fix' }, f.remediation ? txt(f.remediation) : txt(d.no_remediation) || 'None given.'),
thr ? [el('h4', {}, 'Affected components and assets'), (f.assets || []).length ? el('p', {}, ...f.assets.flatMap((x, i) => i ? [', ', el('code', {}, txt(x))] : [el('code', {}, txt(x))])) : el('p', { class: 'fix' }, 'Not saved for this run (results from prism-cli 1.20.1 on save them).')] : null,
(f.evidence || []).length ? [el('h4', {}, 'Evidence'), el('p', {}, ...f.evidence.flatMap((e, i) => i ? [', ', el('code', {}, txt(e))] : [el('code', {}, txt(e))]))] : null,
f.finding_id ? el('p', { class: 'fix' }, 'Finding id ', el('code', {}, txt(f.finding_id))) : null));
if (open) dt.open = true;
Expand Down
4 changes: 3 additions & 1 deletion cli/src/dashboard/security-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export interface RunFinding {
/** null: this run type gives none (code review and pentest findings carry no remediation text). */
remediation: string | null;
evidence: string[];
/** Threat models: the affected components and assets (saved since 1.20.1). */
assets: string[];
finding_id: string | null;
}

Expand Down Expand Up @@ -219,7 +221,7 @@ export function securityRunDetail(repos: RunRepo[], repoArg: string | null, runA
cwe: f.cwe ?? null, stride: f.stride || [], confidence: f.confidence ?? null,
description: fullText(f),
remediation: type === 'threat-model' && f.recommendation ? f.recommendation : null,
evidence: f.evidence || [], finding_id: f.finding_id || f.threat_id || null,
evidence: f.evidence || [], assets: f.assets || [], finding_id: f.finding_id || f.threat_id || null,
}));
const where = shellWord(tilde(repo.path, home));
const job = shellWord(jobKey(r)!);
Expand Down
1 change: 1 addition & 0 deletions cli/src/security/threat-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export function toThreatModelResult(o: TmBase & { job: TmJob; threats: ThreatRow
...(t.statement ? { description: redact(t.statement) } : {}),
risk_level: t.severity, title: t.title, threat_id: t.threatId, stride: t.stride,
recommendation: redact(t.recommendation), evidence: t.evidence,
...(t.impactedAssets.length ? { assets: t.impactedAssets.map(redact) } : {}),
}));
return makeResult({
kind: 'security-threat-model', hook: 'manual', tool: 'security-agent',
Expand Down
Loading
Loading