345 lines
27 KiB
JavaScript
345 lines
27 KiB
JavaScript
// The Security Audit window: the user's site in development checked for vulnerabilities. Deterministic checks first (fast, no
|
|
// AI: Symfony's configuration, the PHP code followed from the request to SQL / shell / redirects / unserialize, Twig |raw,
|
|
// IDOR candidates, mass assignment, uploads, secrets git carries, Docker files, composer / npm audit, the local site's
|
|
// headers), then, only on what is chosen, an AI review (Claude, OpenCode or a chat server, as the Translations window) that
|
|
// confirms, explains and proposes patches. A patch is shown as a diff, written in one click, then everything is checked again.
|
|
// Exploit proofs: read-only GET requests to the LOCAL development site only (the backend refuses any other host), run before
|
|
// and after the fix. Statuses (open / fixed / accepted risk / false positive) and the history live in .jumphp/security/.
|
|
// The PHP side: ide/src/Audit.
|
|
import { backend } from './backend.js';
|
|
import { el, clear, icon, notify, prefs, t, dialog, prompt } from './ui.js';
|
|
import { fileLink } from './symfony-events.js';
|
|
|
|
// tr() marks a text for the translation files (i18n.test.mjs reads its literals); t() shows it in the interface's language
|
|
const tr = (s) => s;
|
|
const SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'];
|
|
void [tr('critical'), tr('high'), tr('medium'), tr('low'), tr('info'), tr('confirmed'), tr('false positive'), tr('uncertain')];
|
|
const STATUS = { open: tr('Open'), fixed: tr('Fixed'), accepted: tr('Accepted risk'), false_positive: tr('False positive') };
|
|
const OWASP = {
|
|
A01: tr('Broken Access Control'), A02: tr('Cryptographic Failures'), A03: tr('Injection'), A04: tr('Insecure Design'), A05: tr('Security Misconfiguration'),
|
|
A06: tr('Vulnerable and Outdated Components'), A07: tr('Identification and Authentication Failures'), A08: tr('Software and Data Integrity Failures'),
|
|
A09: tr('Security Logging and Monitoring Failures'), A10: tr('Server-Side Request Forgery'),
|
|
};
|
|
|
|
/** each rule: its title, why it matters, how to fix it (English keys, translated by t()) */
|
|
const RULES = {
|
|
sql_injection: [tr('SQL built from request data'), tr('Text from the request is concatenated or interpolated into an SQL / DQL query: a quote changes the query (read other rows, bypass a login, dump the database).'), tr('Use parameters (:name or ?) with setParameter() / executeQuery($sql, [$value]); never build SQL with request text. Column names: an allow-list.')],
|
|
command_injection: [tr('Shell command built from data'), tr('A shell command is built from a variable: request text can add its own commands (; | $()).'), tr('Pass the arguments as an array to Symfony Process (new Process([...])) or escape each one with escapeshellarg().')],
|
|
unserialize_input: [tr('unserialize() on request data'), tr('unserialize() on data a visitor controls can create objects of any class (object injection, sometimes code execution).'), tr('Use json_decode(), or unserialize($data, [\'allowed_classes\' => false]).')],
|
|
open_redirect: [tr('Redirect to an address from the request'), tr('The redirect target comes from the request: a link to your site can send visitors to a phishing page.'), tr('Redirect to a route name (generateUrl), or check the target against an allow-list of paths / hosts.')],
|
|
unrestricted_upload: [tr('Upload saved without checks'), tr('An uploaded file is moved without checking its type or size; with its original name, a .php file can land in a public folder.'), tr('Validate with the File / Image constraint (mimeTypes, maxSize), name the file yourself (uniqid + guessExtension()) and store it outside public/.')],
|
|
idor_candidate: [tr('Object loaded by id without an access check (IDOR)'), tr('The route loads an entity from the id in the URL and nothing checks that the visitor may see it: changing the id shows another user\'s data.'), tr('Add #[IsGranted(\'VIEW\', \'subject\')] with a voter, or check the owner ($entity->getOwner() === $this->getUser()).')],
|
|
mass_assignment: [tr('Mass assignment from the request'), tr('Every field of the request calls a setter or writes a property: a visitor can set fields the form does not show (roles, price, owner).'), tr('Use a Symfony form or a DTO with only the allowed fields, or an explicit list of fields.')],
|
|
xss_response: [tr('Response written with request text (XSS)'), tr('Request text goes into an HTML response without escaping: a link can run JavaScript in the visitor\'s browser.'), tr('Render a Twig template (escaped by default) or escape with htmlspecialchars().')],
|
|
xss_raw: [tr('|raw on a variable (XSS)'), tr('The |raw filter turns off Twig\'s escaping: when the value comes from a visitor, their HTML and JavaScript run in the page.'), tr('Remove |raw, or clean the HTML first (sanitize_html filter of symfony/html-sanitizer).')],
|
|
xss_autoescape_off: [tr('Escaping turned off in a template'), tr('{% autoescape false %} prints every variable of the block as raw HTML.'), tr('Remove the block or use {% autoescape \'html\' %}; mark only trusted values with |raw.')],
|
|
csrf_disabled_form: [tr('CSRF protection turned off on a form'), tr('The form accepts submissions from any other site the user visits while logged in.'), tr('Remove \'csrf_protection\' => false (or set it to true).')],
|
|
cors_header_wildcard: [tr('Access-Control-Allow-Origin: * set in code'), tr('Any web site can read this answer from the visitor\'s browser.'), tr('Answer with the allowed origins only (nelmio/cors-bundle).')],
|
|
csrf_disabled_global: [tr('CSRF protection turned off for the whole application'), tr('Forms accept submissions made from other sites.'), tr('Set framework.csrf_protection to true.')],
|
|
firewall_unsecured: [tr('A firewall without security'), tr('security: false on this firewall: no user, no access_control and no protection for its paths.'), tr('Remove security: false (keep it for the dev firewall of the profiler and assets only).')],
|
|
access_control_gap: [tr('Sensitive route without access control'), tr('This route (admin, account, API…) has no #[IsGranted], no access_control rule and no check in its code: anyone can open it.'), tr('Add an access_control rule (- { path: ^/admin, roles: ROLE_ADMIN }) or #[IsGranted] on the controller.')],
|
|
cors_wildcard: [tr('CORS open to every origin'), tr('allow_origin * (with credentials: the worst) lets any site call the API with the visitor\'s session.'), tr('List the allowed origins (an environment variable per environment).')],
|
|
debug_in_prod: [tr('Debug mode in production'), tr('APP_DEBUG=1 in a production environment shows stack traces, configuration and the profiler to visitors.'), tr('Set APP_DEBUG=0 for production.')],
|
|
app_secret_weak: [tr('Weak or default APP_SECRET for production'), tr('APP_SECRET signs cookies, CSRF tokens and login links: a known or short value lets them be forged.'), tr('Generate a long random value and keep it out of git (secrets:set or the server\'s environment).')],
|
|
trusted_proxies_all: [tr('Every proxy trusted'), tr('Trusting 0.0.0.0/0 lets any client fake its IP address and the scheme (X-Forwarded-*).'), tr('Trust only your proxy\'s addresses (or REMOTE_ADDR behind a single load balancer).')],
|
|
secret_committed: [tr('Secret committed to git'), tr('A key or password is in a file git tracks: anyone with the repository (or its history) can use it.'), tr('Revoke / rotate the secret, move it to .env.local or secrets:set, and remove it from the history.')],
|
|
private_key_committed: [tr('Private key committed to git'), tr('A private key (or Symfony\'s production decryption key) is in the repository: everything it protects is exposed.'), tr('Rotate the key, remove the file from git (git rm --cached) and add it to .gitignore.')],
|
|
env_local_committed: [tr('.env.local committed to git'), tr('.env.local holds this computer\'s real values (passwords, keys) and must never be committed.'), tr('git rm --cached the file and add it to .gitignore.')],
|
|
dependency_vulnerable: [tr('Package with a known vulnerability'), tr('A security advisory affects the installed version of this package.'), tr('Update the package (composer update vendor/package, npm audit fix) to a fixed version.')],
|
|
docker_privileged: [tr('Privileged container'), tr('privileged: true gives the container full access to the host.'), tr('Remove privileged; add only the capabilities it needs (cap_add).')],
|
|
docker_socket_mounted: [tr('Docker socket mounted in a container'), tr('With /var/run/docker.sock a container controls Docker: it is root on the host.'), tr('Do not mount the socket, or use a restricted proxy.')],
|
|
docker_db_port_exposed: [tr('Database port open on every interface'), tr('The database is published on all the computer\'s interfaces: anyone on the network can try its password.'), tr('Bind it to this computer only: "127.0.0.1:5432:5432", or do not publish it.')],
|
|
docker_root_user: [tr('Container running as root'), tr('The process runs as root inside the container: a flaw in the application gives root there.'), tr('Add a USER instruction (or user: in compose) with an unprivileged user.')],
|
|
docker_latest_tag: [tr('Image without a fixed version'), tr('An image without a tag (or :latest) changes under you: builds are not reproducible and updates are not reviewed.'), tr('Pin a version tag (postgres:16-alpine) or a digest.')],
|
|
header_missing: [tr('Security header missing'), tr('The local site does not send this header, which limits clickjacking, MIME sniffing, leaks of the address or script injection.'), tr('Add it in the web server or with a response listener (nelmio/security-bundle).')],
|
|
header_leak: [tr('Server version disclosed'), tr('The answer tells the exact version of PHP or of the server, which helps an attacker pick an exploit.'), tr('Hide it (expose_php = Off, server_tokens off).')],
|
|
logic_flaw: [tr('Logic flaw (AI)'), '', ''],
|
|
};
|
|
const VERDICT = { vulnerable: tr('Vulnerable'), not_reproduced: tr('Not reproduced'), inconclusive: tr('Inconclusive') };
|
|
|
|
function styles() {
|
|
if (document.getElementById('security-audit-css')) return;
|
|
document.head.append(el('link', { id: 'security-audit-css', rel: 'stylesheet', href: new URL('../css/security-audit.css', import.meta.url).href }));
|
|
}
|
|
|
|
export function ruleTitle(f) { return f.rule === 'logic_flaw' && f.title ? f.title : t(RULES[f.rule]?.[0] || f.rule); }
|
|
|
|
export class SecurityAuditPanel {
|
|
constructor(app) {
|
|
this.app = app;
|
|
this.node = el('div.sa-view');
|
|
this.data = null;
|
|
this.tab = 'findings';
|
|
this.selected = null;
|
|
this.severity = prefs.get('saSeverity', 'all');
|
|
this.status = prefs.get('saStatus', 'open');
|
|
this.busy = '';
|
|
this.diff = {}; // finding id => {diff, changes, source}
|
|
this.proving = '';
|
|
styles();
|
|
this.render();
|
|
}
|
|
|
|
title() { return t('Security Audit'); }
|
|
|
|
actions() {
|
|
return [el('button', { title: t('Run the audit'), onclick: () => this.run() }, icon('zap'))];
|
|
}
|
|
|
|
shown() { if (!this.data && !this.busy) this.load(); }
|
|
|
|
async load() {
|
|
try { this.data = await backend.invoke('audit.state'); } catch (e) { notify(e.message, 'error', { title: t('Security Audit') }); }
|
|
this.render();
|
|
}
|
|
|
|
get findings() { return this.data?.audit?.findings || []; }
|
|
|
|
find(id) { return this.findings.find((f) => f.id === id) || null; }
|
|
|
|
async run() {
|
|
this.busy = t('Auditing the project…');
|
|
this.render();
|
|
try {
|
|
this.data = await backend.invoke('audit.run', { deps: prefs.get('saDeps', true), site: prefs.get('saSite', true) });
|
|
const n = this.findings.filter((f) => f.status === 'open').length;
|
|
notify(t('{n} open findings', { n }), n ? 'warning' : 'info', { title: t('Security Audit') });
|
|
} catch (e) { notify(e.message, 'error', { title: t('Security Audit') }); }
|
|
this.busy = '';
|
|
this.render();
|
|
}
|
|
|
|
async setStatus(f, status) {
|
|
let note = '';
|
|
if (status === 'accepted' || status === 'false_positive') {
|
|
note = await prompt(status === 'accepted' ? t('Why is this risk accepted?') : t('Why is it a false positive?'), { value: f.note || '', placeholder: t('A note kept with the finding') });
|
|
if (note === null) return;
|
|
}
|
|
try {
|
|
await backend.invoke('audit.status', { id: f.id, status, note });
|
|
f.status = status;
|
|
f.note = note;
|
|
} catch (e) { notify(e.message, 'error'); }
|
|
this.render();
|
|
}
|
|
|
|
async saveSite(url) {
|
|
try {
|
|
const r = await backend.invoke('audit.site', { url });
|
|
this.data.site = r.site;
|
|
notify(t('Local site: {url}', { url: r.site || '—' }), 'info');
|
|
} catch (e) { notify(e.message, 'error', { title: t('Security Audit') }); }
|
|
this.render();
|
|
}
|
|
|
|
async showPatch(f) {
|
|
try {
|
|
this.diff[f.id] = await backend.invoke('audit.patch', { id: f.id });
|
|
} catch (e) { notify(e.message, 'error'); }
|
|
this.render();
|
|
}
|
|
|
|
openDiff(f) {
|
|
const c = this.diff[f.id]?.changes?.[0];
|
|
if (c) this.app.editors.openDiff(c.path, { original: c.before, modified: c.after, readOnly: true, title: `${c.path} (${t('fix')})` }).catch((e) => notify(e.message, 'error'));
|
|
}
|
|
|
|
async applyPatch(f) {
|
|
const p = this.diff[f.id];
|
|
if (!p) return;
|
|
this.busy = t('Writing the fix and checking again…');
|
|
this.render();
|
|
try {
|
|
const r = await backend.invoke('audit.apply', { changes: p.changes, id: f.id });
|
|
delete this.diff[f.id];
|
|
this.data.audit = r.audit;
|
|
this.app.editors.reloadFromDisk?.();
|
|
notify(r.isFixed ? t('Fixed: the check no longer finds it') : t('Written, but the check still finds it'), r.isFixed ? 'info' : 'warning', { title: ruleTitle(f) });
|
|
this.busy = '';
|
|
// the proof again, after the fix
|
|
if (r.isFixed && f.provable && (f.probes || []).length) await this.prove(f.id);
|
|
} catch (e) { notify(e.message, 'error'); }
|
|
this.busy = '';
|
|
this.render();
|
|
}
|
|
|
|
async prove(id) {
|
|
this.proving = id;
|
|
this.render();
|
|
try {
|
|
const r = await backend.invoke('audit.probe', { id });
|
|
const f = this.find(id);
|
|
if (f) f.probes = r.runs;
|
|
const v = r.result.verdict;
|
|
notify(`${t(VERDICT[v] || v)}: ${r.result.evidence}`, v === 'vulnerable' ? 'warning' : 'info', { title: t('Exploit proof') });
|
|
} catch (e) { notify(e.message, 'error', { title: t('Exploit proof') }); }
|
|
this.proving = '';
|
|
this.render();
|
|
}
|
|
|
|
async aiDialog(ids = null) {
|
|
const providers = (await backend.invoke('ai.providers').catch(() => [{ id: 'claude', name: 'Claude', kind: 'claude' }]))
|
|
.filter((p) => ['claude', 'opencode', 'chat'].includes(p.kind));
|
|
const provider = el('select.input.small', {}, ...providers.map((p) => el('option', { value: p.id }, p.name)));
|
|
provider.value = prefs.get('saAiProvider', providers[0]?.id || 'claude');
|
|
const model = el('input.input.small', { placeholder: t('model (optional): sonnet, haiku, opus…'), value: prefs.get('saAiModel:' + provider.value, '') });
|
|
provider.addEventListener('change', () => { model.value = prefs.get('saAiModel:' + provider.value, ''); });
|
|
const open = this.findings.filter((f) => f.status === 'open' && ['critical', 'high', 'medium'].includes(f.severity) && !f.review && f.rule !== 'dependency_vulnerable' && !f.site);
|
|
const active = this.app.editors.activePath?.() || '';
|
|
const scope = el('select.input.small', {},
|
|
...(ids ? [el('option', { value: 'chosen' }, t('This finding'))] : []),
|
|
el('option', { value: 'open' }, t('Open findings not reviewed yet, medium and above ({n})', { n: open.length })),
|
|
...(active ? [el('option', { value: 'file' }, t('The file open in the editor: {file}', { file: active }))] : []));
|
|
const logic = el('input', { type: 'checkbox', checked: true });
|
|
dialog({
|
|
title: t('Review with the AI'),
|
|
body: el('div.sa-form', {},
|
|
el('p.sa-muted', {}, t('Only the chosen findings and their code are sent, a few files per request, secrets masked. The AI confirms or rejects each finding and proposes patches; nothing is written before you apply one.')),
|
|
el('label', {}, t('What')), scope,
|
|
el('label', {}, t('With')), provider, model,
|
|
el('label.sa-check', {}, logic, t('Also look for logic flaws in the same code'))),
|
|
buttons: [{ label: 'Cancel' }, {
|
|
label: tr('Review'), primary: true, action: () => {
|
|
prefs.set('saAiProvider', provider.value);
|
|
prefs.set('saAiModel:' + provider.value, model.value.trim());
|
|
const payload = scope.value === 'chosen' ? { ids } : scope.value === 'file' ? { files: [active] } : { ids: open.map((f) => f.id) };
|
|
this.runAi({ ...payload, provider: provider.value, model: model.value.trim(), logic: logic.checked });
|
|
},
|
|
}],
|
|
});
|
|
}
|
|
|
|
async runAi(p) {
|
|
this.busy = t('The AI is reviewing…');
|
|
this.render();
|
|
const extra = p.provider === 'claude' || p.provider === 'opencode' ? {} : { key: prefs.get('aiKey:' + p.provider, ''), baseUrl: prefs.get('aiBase:' + p.provider, '') };
|
|
try {
|
|
const r = await backend.invoke('audit.ai', { ...p, ...extra });
|
|
this.data = { ...this.data, ...r };
|
|
notify(t('{n} findings reviewed, {m} new', { n: r.reviewed, m: r.new }) + (r.errors?.length ? '\n' + r.errors.join('\n') : ''), r.errors?.length ? 'warning' : 'info', { title: t('Review with the AI') });
|
|
} catch (e) { notify(e.message, 'error', { title: t('Review with the AI') }); }
|
|
this.busy = '';
|
|
this.render();
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------- render
|
|
|
|
visible() {
|
|
return this.findings.filter((f) => (this.severity === 'all' || f.severity === this.severity) && (this.status === 'all' || f.status === this.status));
|
|
}
|
|
|
|
render() {
|
|
clear(this.node);
|
|
const counts = Object.fromEntries(SEVERITIES.map((s) => [s, this.findings.filter((f) => f.severity === s && f.status === 'open').length]));
|
|
const site = el('input.input.small.sa-site', { value: this.data?.site || '', placeholder: 'http://localhost:8000', title: t('The local development site (exploit proofs and headers go there only)') });
|
|
site.addEventListener('change', () => this.saveSite(site.value));
|
|
const sev = el('select.input.small', { onchange: (e) => { this.severity = e.target.value; prefs.set('saSeverity', this.severity); this.render(); } },
|
|
el('option', { value: 'all' }, t('All severities')), ...SEVERITIES.map((s) => el('option', { value: s, selected: this.severity === s }, t(s))));
|
|
const st = el('select.input.small', { onchange: (e) => { this.status = e.target.value; prefs.set('saStatus', this.status); this.render(); } },
|
|
el('option', { value: 'all' }, t('All statuses')), ...Object.entries(STATUS).map(([k, v]) => el('option', { value: k, selected: this.status === k }, t(v))));
|
|
const opt = (key, label) => {
|
|
const box = el('input', { type: 'checkbox', checked: prefs.get(key, true), onchange: (e) => prefs.set(key, e.target.checked) });
|
|
return el('label.sa-check', {}, box, t(label));
|
|
};
|
|
this.node.append(el('div.sa-bar', {},
|
|
el('button.btn.small.primary', { disabled: !!this.busy, onclick: () => this.run() }, icon('zap'), t('Run the audit')),
|
|
el('button.btn.small', { disabled: !!this.busy || !this.data?.audit, onclick: () => this.aiDialog() }, icon('claude'), t('Review with the AI…')),
|
|
opt('saDeps', 'Packages (composer / npm audit)'), opt('saSite', 'Site headers'),
|
|
el('span.sa-sep'), el('span.sa-muted', {}, t('Local site')), site,
|
|
el('span.sa-sep'), sev, st,
|
|
el('span.sa-tabs', {}, ...[['findings', 'Findings'], ['history', 'History']].map(([k, l]) => el('button.btn.small' + (this.tab === k ? '.active' : ''), { onclick: () => { this.tab = k; this.render(); } }, t(l))))));
|
|
const summary = el('div.sa-summary', {},
|
|
...SEVERITIES.map((s) => el(`span.sa-sev.${s}`, { title: t(s) }, `${t(s)} ${counts[s]}`)),
|
|
this.data?.audit ? el('span.sa-muted', {}, t('Audit of {date}, {ms} ms', { date: new Date(this.data.audit.at).toLocaleString(), ms: this.data.audit.ms ?? 0 })) : null,
|
|
this.busy ? el('span.sa-busy', {}, this.busy) : null);
|
|
this.node.append(summary);
|
|
if (this.data?.audit?.errors?.length) this.node.append(el('div.sa-errors', {}, ...this.data.audit.errors.map((e) => el('div', {}, e))));
|
|
if (this.tab === 'history') { this.node.append(this.renderHistory()); return; }
|
|
if (!this.data?.audit) {
|
|
this.node.append(el('div.sa-empty', {}, el('p', {}, t('No audit yet. Run it: the checks take a few seconds and need no AI.')),
|
|
el('button.btn.primary', { onclick: () => this.run() }, t('Run the audit'))));
|
|
return;
|
|
}
|
|
const list = this.visible();
|
|
if (!this.selected || !list.some((f) => f.id === this.selected)) this.selected = list[0]?.id || null;
|
|
const rows = el('div.sa-list', {}, ...list.map((f) => el('div.sa-row' + (f.id === this.selected ? '.sel' : '') + (f.status !== 'open' ? '.done' : ''), { onclick: () => { this.selected = f.id; this.render(); } },
|
|
el(`span.sa-sev.${f.severity}`, {}, t(f.severity)),
|
|
el('span.sa-title', {}, ruleTitle(f)),
|
|
f.review ? el('span.sa-ai.' + f.review.verdict, { title: t('AI: {verdict}', { verdict: t(f.review.verdict.replace('_', ' ')) }) }, 'AI') : null,
|
|
(f.probes || []).length ? el('span.sa-proof.' + f.probes[f.probes.length - 1].verdict, { title: t('Exploit proof') }, icon('bug')) : null,
|
|
el('span.sa-file', { title: f.site ? f.file : `${f.file}:${f.line}` }, f.site ? f.file.replace(/^https?:\/\//, '') : `${f.file.split('/').pop()}:${f.line}`),
|
|
f.status !== 'open' ? el('span.sa-status', {}, t(STATUS[f.status])) : null)));
|
|
if (!list.length) rows.append(el('div.sa-empty', {}, t('Nothing with these filters.')));
|
|
const f = this.find(this.selected);
|
|
this.node.append(el('div.sa-body', {}, rows, el('div.sa-detail', {}, f ? this.renderFinding(f) : null)));
|
|
}
|
|
|
|
renderFinding(f) {
|
|
const rule = RULES[f.rule] || ['', '', ''];
|
|
const owasp = (f.owasp || '').slice(0, 3);
|
|
const out = [
|
|
el('div.sa-head', {},
|
|
el(`span.sa-sev.${f.severity}`, {}, t(f.severity)),
|
|
el('h3', {}, ruleTitle(f)),
|
|
el('span.sa-owasp', { title: OWASP[owasp] ? t(OWASP[owasp]) : '' }, `${owasp} ${OWASP[owasp] ? t(OWASP[owasp]) : ''}`),
|
|
el('span.sa-status', {}, t(STATUS[f.status] || f.status))),
|
|
el('div.sa-where', {}, f.site ? el('code', {}, f.file) : fileLink(this.app, f.file, f.line, `${f.file}:${f.line}`),
|
|
f.route ? el('span.sa-muted', {}, ` · ${(f.route.methods || []).join('|')} ${f.route.path}`) : null,
|
|
f.input ? el('span.sa-muted', {}, ' · ' + t('input: {kind} {name}', { kind: f.input.kind, name: f.input.name || '' })) : null),
|
|
f.snippet ? el('pre.sa-code', {}, f.snippet) : null,
|
|
];
|
|
const why = f.rule === 'logic_flaw' ? f.explanation : t(rule[1]);
|
|
const fix = f.rule === 'logic_flaw' ? f.fix : t(rule[2]);
|
|
if (f.rule === 'header_missing' && f.header) out.push(el('p', {}, el('code', {}, f.header)));
|
|
if (f.advisory) out.push(el('p', {}, el('b', {}, f.package), ' ', f.advisory.title, ' ', f.advisory.cve ? el('code', {}, f.advisory.cve) : null, ' ', f.advisory.affected ? el('span.sa-muted', {}, f.advisory.affected) : null,
|
|
f.advisory.link ? el('a', { href: '#', onclick: (e) => { e.preventDefault(); this.app.openUrl?.(f.advisory.link); } }, ' ↗') : null));
|
|
if (why) out.push(el('div.sa-sec', {}, el('h4', {}, t('Why it matters')), el('p', {}, why)));
|
|
if (fix) out.push(el('div.sa-sec', {}, el('h4', {}, t('How to fix')), el('p', {}, fix)));
|
|
if (f.review) {
|
|
out.push(el('div.sa-sec.sa-review.' + f.review.verdict, {},
|
|
el('h4', {}, t('AI review: {verdict}', { verdict: t(f.review.verdict.replace('_', ' ')) })),
|
|
f.review.explanation ? el('p', {}, f.review.explanation) : null,
|
|
f.review.fix ? el('p', {}, el('b', {}, t('Fix: ')), f.review.fix) : null,
|
|
f.review.patchRejected ? el('p.sa-muted', {}, t('Its patch did not match the file and was dropped.')) : null));
|
|
}
|
|
// the fix as a diff
|
|
if (f.patch && f.status === 'open') {
|
|
const d = this.diff[f.id];
|
|
out.push(el('div.sa-sec', {}, el('h4', {}, t('Proposed fix'), ' ', el('span.sa-muted', {}, f.patch.source === 'ai' ? t('(from the AI)') : t('(from the rule)'))),
|
|
d ? el('pre.sa-diff', {}, ...d.diff.split('\n').map((l) => el('span' + (l.startsWith('+') && !l.startsWith('+++') ? '.add' : l.startsWith('-') && !l.startsWith('---') ? '.del' : l.startsWith('@@') ? '.hunk' : ''), {}, l + '\n'))) : null,
|
|
el('div.sa-actions', {},
|
|
d ? el('button.btn.small.primary', { disabled: !!this.busy, onclick: () => this.applyPatch(f) }, icon('check'), t('Apply the fix and check again'))
|
|
: el('button.btn.small', { onclick: () => this.showPatch(f) }, icon('diff'), t('Show the diff')),
|
|
d ? el('button.btn.small', { onclick: () => this.openDiff(f) }, icon('diff'), t('Open in the editor')) : null)));
|
|
}
|
|
// exploit proof
|
|
if (f.provable) {
|
|
const runs = f.probes || [];
|
|
out.push(el('div.sa-sec.sa-probe', {}, el('h4', {}, t('Exploit proof')),
|
|
el('p.sa-muted', {}, t('Read-only GET requests to the local development site only ({site}): no write, no delete, no flood. They are saved in http-requests/security-probes/ for the HTTP Client.', { site: this.data?.site || '—' })),
|
|
el('div.sa-actions', {}, el('button.btn.small' + (runs.length ? '' : '.primary'), { disabled: this.proving === f.id || !this.data?.site, onclick: () => this.prove(f.id) }, icon('bug'),
|
|
this.proving === f.id ? t('Running…') : runs.length ? t('Run the proof again') : t('Run the proof'))),
|
|
...runs.slice().reverse().map((r, i) => el('div.sa-run.' + r.verdict, {},
|
|
el('div.sa-run-head', {}, el('b', {}, t(VERDICT[r.verdict] || r.verdict)), el('span.sa-muted', {}, ` · ${r.after ? t('after the fix') : t('before the fix')} · ${new Date(r.at).toLocaleString()}`)),
|
|
el('div', {}, r.evidence),
|
|
i === 0 ? el('table.sa-steps', {}, ...(r.steps || []).map((s) => el('tr', {}, el('td', {}, s.label), el('td', {}, String(s.status || s.error || '')), el('td', {}, el('code', {}, s.url))))) : null,
|
|
i === 0 && r.steps?.some((s) => s.excerpt) ? el('pre.sa-code', {}, r.steps.filter((s) => s.excerpt).map((s) => s.excerpt).join('\n')) : null))));
|
|
}
|
|
// status
|
|
out.push(el('div.sa-sec', {}, el('h4', {}, t('Status')),
|
|
el('div.sa-actions', {},
|
|
...Object.entries(STATUS).map(([k, v]) => el('button.btn.small' + (f.status === k ? '.active' : ''), { onclick: () => this.setStatus(f, k) }, t(v))),
|
|
f.site || f.rule === 'dependency_vulnerable' ? null : el('button.btn.small', { disabled: !!this.busy, onclick: () => this.aiDialog([f.id]) }, icon('claude'), t('Ask the AI'))),
|
|
f.note ? el('p.sa-muted', {}, t('Note: {note}', { note: f.note })) : null));
|
|
return out;
|
|
}
|
|
|
|
renderHistory() {
|
|
const audits = this.data?.history || [];
|
|
if (!audits.length) return el('div.sa-empty', {}, t('No audit yet.'));
|
|
return el('div.sa-history', {}, el('table.sa-steps', {},
|
|
el('tr', {}, el('th', {}, t('Date')), ...SEVERITIES.map((s) => el('th', {}, t(s))), el('th', {}, t('Total')), el('th', {}, t('Fixed'))),
|
|
...audits.map((a) => el('tr', {}, el('td', {}, new Date(a.at).toLocaleString()), ...SEVERITIES.map((s) => el('td', {}, String(a.counts?.[s] ?? 0))),
|
|
el('td', {}, String(a.total)), el('td', {}, String(a.fixed || 0))))));
|
|
}
|
|
}
|