mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-21 07:41:28 +02:00
reNgine 2 could produce a PDF. This produces a deliverable, and it is built the way scan engines are built: sections are plug-and-play directories under reports/, each with a pydantic config model that IS the source of truth. That model feeds GET /reports/catalog, the builder renders its own form from it, and the API validates against it. Adding a section is a directory. Scan Engine is to stages what Report Template is to sections. WeasyPrint 69 renders it, chosen over Chromium and Typst after measuring what each can actually do. Only real CSS Paged Media gives a table of contents with true page numbers, running headers, a PDF outline and footnotes; SysReptor reaches the same verdict and pipes Chromium's HTML into WeasyPrint for exactly that reason. reNgine drops the Chromium hop because it templates in Jinja and draws its charts as SVG in Python, so a browser buys nothing and costs 400 MB per report. Typst was rejected because a user-uploadable theme would then have to be Typst code rather than CSS. A theme is data. shared/definitions/report_theme.py is the schema, six themes ship as YAML, and a user uploads their own; there is no markup in a theme, so there is no injection surface. Fonts are vendored so an offline instance still renders in Latin, Greek and Cyrillic. Everything the document claims is computed once, in reports/analysis/engine.py: a posture score whose every deduction is named, weaknesses ranked by the signals behind the rank rather than severity alone, attack paths that chain observations into a route, a remediation plan ordered by risk removed, per-dimension change against the previous run, and caveats that state what was never assessed. Two narrators read that one brief. Without AI the report still argues its case; with AI the prose is better and the model never sees a row, only the brief, capped and cached per check. An AI failure falls back and the report still completes. Generation is a job. POST /reports queues, the worker walks progress over SSE, and four formats come out of one render: PDF, self-contained HTML, Markdown and JSON. The estimate reads each section's own limits, so the page count it promises is close to the one it delivers. AI moves out of Settings into its own top-level page: connection, a model per tier, what it may be used for, what it has cost, and the narrative cache. Verified on a 1,379-host gov.cy scan: 124 pages in 19.5s across 19 sections, all six themes, and a broken key still producing a complete report. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017f2Mf2HGwFaTRnui4UxpRd
164 lines
5.2 KiB
Python
164 lines
5.2 KiB
Python
"""Markdown and JSON exports, written from the brief rather than scraped from the HTML."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from reports.base import RenderContext
|
|
from shared.definitions.surface import SURFACE_LABELS, SURFACE_ORDER
|
|
from shared.definitions.vulnerabilities import SEVERITY_LABELS, SEVERITY_ORDER
|
|
|
|
|
|
def to_markdown(ctx: RenderContext) -> str:
|
|
brief = ctx.brief
|
|
lines: list[str] = [
|
|
f"# {ctx.spec.title}",
|
|
"",
|
|
f"**Subject** {ctx.data.subject} ",
|
|
f"**Assessed** {ctx.data.observed_label} ",
|
|
f"**Report date** {ctx.now:%d %B %Y}",
|
|
"",
|
|
"## Executive summary",
|
|
"",
|
|
ctx.narrator.executive_summary(brief),
|
|
"",
|
|
"## Surface",
|
|
"",
|
|
"| Dimension | Observed | Previous |",
|
|
"| --- | ---: | ---: |",
|
|
]
|
|
for dimension in SURFACE_ORDER:
|
|
entry = ctx.data.coverage[dimension]
|
|
observed = f"{entry.count:,}" if entry.covered else "Not scanned"
|
|
previous = f"{entry.previous:,}" if entry.previous is not None else "—"
|
|
lines.append(f"| {SURFACE_LABELS[dimension]} | {observed} | {previous} |")
|
|
|
|
if brief.severity:
|
|
lines += [
|
|
"",
|
|
"## Findings by severity",
|
|
"",
|
|
"| Severity | Count |",
|
|
"| --- | ---: |",
|
|
]
|
|
for key in SEVERITY_ORDER:
|
|
if brief.severity.get(key):
|
|
lines.append(f"| {SEVERITY_LABELS[key]} | {brief.severity[key]:,} |")
|
|
|
|
if brief.paths:
|
|
lines += ["", "## Attack paths", ""]
|
|
for path in brief.paths:
|
|
lines += [f"### {path.title}", "", path.detail, ""]
|
|
|
|
if brief.risks:
|
|
lines += [
|
|
"",
|
|
"## Ranked weaknesses",
|
|
"",
|
|
"| # | Weakness | Severity | Seen | Hosts | Why |",
|
|
"| ---: | --- | --- | ---: | ---: | --- |",
|
|
]
|
|
for index, risk in enumerate(brief.risks, start=1):
|
|
why = "; ".join(risk.signals) or "—"
|
|
lines.append(
|
|
f"| {index} | {risk.name} | {SEVERITY_LABELS.get(risk.severity, risk.severity)} "
|
|
f"| {risk.count:,} | {risk.hosts:,} | {why} |"
|
|
)
|
|
|
|
if brief.actions:
|
|
lines += [
|
|
"",
|
|
"## Remediation plan",
|
|
"",
|
|
"| # | Action | Severity | Change | Clears | Assets |",
|
|
"| ---: | --- | --- | --- | ---: | ---: |",
|
|
]
|
|
for index, action in enumerate(brief.actions, start=1):
|
|
lines.append(
|
|
f"| {index} | {action.title} | {SEVERITY_LABELS.get(action.severity, action.severity)} "
|
|
f"| {action.effort} | {action.clears:,} | {action.assets:,} |"
|
|
)
|
|
|
|
if brief.caveats:
|
|
lines += ["", "## Coverage and limitations", ""]
|
|
lines += [f"- {c.text}" for c in brief.caveats]
|
|
|
|
return "\n".join(lines) + "\n"
|
|
|
|
|
|
def to_json(ctx: RenderContext) -> str:
|
|
brief = ctx.brief
|
|
payload = {
|
|
"title": ctx.spec.title,
|
|
"subject": ctx.data.subject,
|
|
"subject_type": ctx.data.subject_type,
|
|
"scope": ctx.spec.scope,
|
|
"generated_at": ctx.now.isoformat(),
|
|
"observed_at": brief.observed_at.isoformat() if brief.observed_at else None,
|
|
"posture": {
|
|
"score": brief.posture.score,
|
|
"grade": brief.posture.grade,
|
|
"deductions": brief.posture.deductions,
|
|
},
|
|
"counts": brief.counts,
|
|
"coverage": brief.coverage,
|
|
"severity": brief.severity,
|
|
"headline": brief.headline,
|
|
"risks": [
|
|
{
|
|
"template_id": r.template_id,
|
|
"name": r.name,
|
|
"severity": r.severity,
|
|
"observations": r.count,
|
|
"hosts": r.hosts,
|
|
"score": r.score,
|
|
"signals": r.signals,
|
|
"kev": r.kev,
|
|
"cves": r.cves,
|
|
"epss": r.epss,
|
|
"cvss": r.cvss,
|
|
"new": r.new,
|
|
}
|
|
for r in brief.risks
|
|
],
|
|
"attack_paths": [
|
|
{
|
|
"key": p.key,
|
|
"title": p.title,
|
|
"detail": p.detail,
|
|
"severity": p.severity,
|
|
"count": p.count,
|
|
"assets": p.assets,
|
|
"evidence": p.evidence,
|
|
}
|
|
for p in brief.paths
|
|
],
|
|
"actions": [
|
|
{
|
|
"title": a.title,
|
|
"severity": a.severity,
|
|
"effort": a.effort,
|
|
"clears": a.clears,
|
|
"assets": a.assets,
|
|
"templates": a.templates,
|
|
"controls": a.controls,
|
|
}
|
|
for a in brief.actions
|
|
],
|
|
"changes": [
|
|
{
|
|
"dimension": c.dimension,
|
|
"added": c.added,
|
|
"gone": c.gone,
|
|
"added_sample": c.added_sample,
|
|
"gone_sample": c.gone_sample,
|
|
}
|
|
for c in brief.changes
|
|
],
|
|
"compliance": brief.compliance,
|
|
"exposure": brief.exposure,
|
|
"hosting": brief.hosting,
|
|
"caveats": [{"kind": c.kind, "text": c.text} for c in brief.caveats],
|
|
}
|
|
return json.dumps(payload, indent=2, default=str)
|