Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can — learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company 👇

12.6 KB
Raw Blame
// ©AngelaMos | 2026
// markdown.rs

use std::fmt::Write;

use lisdex_triage::severity::Severity;

use crate::advisory::{Advisory, OperatorInput, Provenance};
use crate::bundle::{self, Reproducer};

const NOT_ESTABLISHED: &str = "NOT ESTABLISHED";
const OPERATOR_SUPPLIES: &str = "_(you supply this)_";
const NOT_ASSIGNED: &str = "not assigned; see \"Filing this advisory\" below";
const UNNAMED_SITE: &str = "an unresolved frame";

const PROVENANCE_BANNER: &str = "> **DO NOT FILE THIS ADVISORY.** The crash it describes carries \
     benchmark instrumentation in its call stack, which means it was found in a research build \
     containing deliberately planted bugs rather than in the library as its maintainers ship it. \
     Filing it would report a fabricated vulnerability against real, widely deployed software. \
     lisdex renders it so the run can be audited, not so it can be sent.";

const TREE_PROVENANCE_BANNER: &str = "> **DO NOT FILE THIS ADVISORY.** It was found against a \
     benchmark tree, not against the library as its maintainers ship it. Benchmark suites plant \
     canaries and forward-port real historical CVEs into current source, so a finding from one is \
     either a fabricated bug or a genuine vulnerability that was fixed years ago. This is decided \
     by the target lisdex measured at campaign start, not by the call stack below, which may carry \
     no benchmark frame at all. lisdex renders it so the run can be audited, not so it can be sent.";

const DRAFTED_BY: &str = "_Drafted by lisdex from one fuzzing campaign. Every heading below that \
     reads NOT ESTABLISHED is a field lisdex declines to fill rather than guess, and each states \
     why. Fill them in or delete them before sending this to anyone._";

const SUMMARY_HEADING: &str = "## Summary";
const CVE_HEADING: &str = "### CVE";
const VERSIONS_HEADING: &str = "### Affected versions";
const REPORTER_HEADING: &str = "### Reporter";
const SEVERITY_HEADING: &str = "## Severity";
const POC_HEADING: &str = "## Proof of Concept";
const REMEDIATION_HEADING: &str = "## Remediation and Mitigation";
const ANALYSIS_HEADING: &str = "## Further Analysis";
const TIMELINE_HEADING: &str = "## Timeline";
const FILING_HEADING: &str = "## Filing this advisory";

const REMEDIATION_BODY: &str = "NOT ESTABLISHED. lisdex observes a crash; it does not read the \
     surrounding code to work out which bounds check is missing, and a patch it guessed at would \
     be a patch nobody tested. The maintainer is better placed to write the fix than the tool that \
     found the fault.";

const TIMELINE_BODY: &str = "**Date reported**:\n\n**Date fixed**:\n\n**Date disclosed**:";

const DISCLOSURE_NOTE: &str = "The community norm is 90 days from private notification to \
     publication, and Google Project Zero's 90+30 policy adds 30 days after a patch ships before \
     technical detail goes public. Project Zero additionally began a trial in July 2025 under \
     which it announces a report's *existence* (project, product, filing date, deadline) within a \
     week, while withholding all technical detail until the deadline. That is Project Zero's own \
     practice and binds nobody else, but it is the current shape of the norm.";

const GHSA_ECOSYSTEM_NOTE: &str = "GitHub's advisory form requires an `ecosystem` value, and its \
     accepted list is `rubygems, npm, pip, maven, nuget, composer, go, rust, erlang, actions, pub, \
     other, swift`. **There is no C or C++ ecosystem**, so a library like this one is filed under \
     `other` with a free-text package name.";

const GHSA_CVE_NOTE: &str = "GitHub documents that \"Anyone with admin permissions to a security \
     advisory can request a CVE identification number.\" Reporting privately through a \
     repository's \"Report a vulnerability\" form adds you as a *collaborator*, which is write \
     access, not admin. **An external reporter therefore cannot request a CVE without the \
     maintainer**, and GitHub provides no escalation path if the maintainer never answers; its \
     documented remedy in that case is public disclosure after a reasonable wait.";

const GHSA_CREDIT_NOTE: &str = "GitHub's credit roles include `Tool` (\"Names of tools used in \
     vulnerability discovery or identification\") separately from `Finder` and `Reporter`, so \
     lisdex can be credited without displacing the person who ran it.";

const SYMBOLIZATION_NOTE: &str = "The frames below carry function names and source lines because \
     lisdex resolved them after capturing the report. The script runs the sanitizer with \
     `symbolize=0` deliberately, so a direct run prints raw module offsets instead — that is the \
     same crash, not a different one.";

const PACKAGE_NAME_NOTE: &str = "The name above is whatever this campaign's target was called, \
     which is usually the fuzz harness rather than the library as it is distributed. Check it \
     before filing, and pass `--package` to set it.";

const CVE_RECORD_VERSION_NOTE: &str = "If this is routed to a CVE record rather than a GitHub \
     advisory, the same gap is expressible there: the record format requires `versions` or \
     `defaultStatus` but not both, `defaultStatus` defaults to `unknown`, and the CNA Rules allow \
     a permanent unknown status for a product suspected of being affected but not investigated. \
     Note also that a CVE record must not be the first public disclosure of a vulnerability, so \
     something public has to exist at or before the record.";

const VERSION_NULL_NOTE: &str = "In GitHub's advisory schema `vulnerable_version_range` is a \
     required *key* whose type is string-or-null. Leaving it null is a valid record that says the \
     range is unestablished; inventing one is not.";

const SEVERITY_SCALE_NOTE: &str = "This tier is the one lisdex's triage layer assigns, and it is \
     not the Low/Medium/High/Critical scale advisory forms usually ask for. The two are different \
     axes and lisdex does not translate between them, because the translation would be an opinion \
     wearing the tier's authority.";

const UNASSESSED_SEVERITY_NOTE: &str = "**Severity is unassessed for this finding.** lisdex has no \
     labelled corpus for this class, so it reports the tier its taxonomy uses for *look at this* \
     rather than a judgement it cannot support. Do not read it as low severity.";

const NO_WEAKNESS_NOTE: &str = "No CWE is named. The observed class does not map onto exactly one \
     published weakness, and naming the nearest one would put a wrong identifier in a permanent \
     record.";

const SECURITY_RELEVANT_NOTE: &str = "The triage layer marks this finding security-relevant.";
const NOT_SECURITY_RELEVANT_NOTE: &str = "The triage layer does **not** mark this finding \
     security-relevant. That is a statement about the fault it observed, not a clearance: a \
     maintainer may still consider it a vulnerability.";

fn severity_meaning(severity: Severity) -> &'static str {
    match severity {
        Severity::Exploitable => {
            "the fault class and access direction match cases that have historically been steerable \
             into more than a crash"
        }
        Severity::ProbablyExploitable => {
            "the fault class is one that is often steerable, but this report does not show it here"
        }
        Severity::NotExploitable => {
            "nothing in this report shows memory an attacker could steer, though a reachable crash \
             is still a denial of service"
        }
        Severity::Undefined => {
            "lisdex declines to assign a tier for this class rather than assert one it cannot \
             support"
        }
    }
}

fn refusal(input: OperatorInput) -> String {
    format!("{NOT_ESTABLISHED}. {}", input.why())
}

fn push_summary(out: &mut String, advisory: &Advisory) {
    let site = advisory.crash_site().unwrap_or(UNNAMED_SITE);
    let _ = write!(
        out,
        "{SUMMARY_HEADING}\n\nFuzzing `{}` produced a `{}` reaching `{}`. {} crash{} in this \
         campaign share this fault's stack signature, so they are counted here as one bug, keyed \
         `{}`. The reproducer is {} bytes.\n\n",
        advisory.target(),
        advisory.class(),
        site,
        advisory.crash_count(),
        if advisory.crash_count() == 1 {
            ""
        } else {
            "es"
        },
        advisory.key(),
        advisory.reproducer_bytes()
    );
    let _ = write!(out, "{CVE_HEADING}\n\n{NOT_ASSIGNED}\n\n");
    let _ = write!(
        out,
        "{VERSIONS_HEADING}\n\n{}\n\n",
        refusal(OperatorInput::AffectedVersionRange)
    );
    let _ = write!(out, "{REPORTER_HEADING}\n\n{OPERATOR_SUPPLIES}\n\n");
}

fn push_severity(out: &mut String, advisory: &Advisory) {
    let _ = write!(out, "{SEVERITY_HEADING}\n\n");
    let _ = write!(
        out,
        "lisdex tier: **{}** ({}).\n\n{SEVERITY_SCALE_NOTE}\n\n",
        advisory.severity().as_str(),
        severity_meaning(advisory.severity())
    );
    if !advisory.severity_is_assessed() {
        let _ = write!(out, "{UNASSESSED_SEVERITY_NOTE}\n\n");
    }
    match advisory.weakness() {
        Some(weakness) => {
            let _ = write!(out, "Weakness: **{}** {}\n\n", weakness.id, weakness.name);
        }
        None => {
            let _ = write!(out, "{NO_WEAKNESS_NOTE}\n\n");
        }
    }
    let _ = write!(
        out,
        "{}\n\n",
        if advisory.is_security_relevant() {
            SECURITY_RELEVANT_NOTE
        } else {
            NOT_SECURITY_RELEVANT_NOTE
        }
    );
    let _ = write!(out, "CVSS: {}\n\n", refusal(OperatorInput::CvssVector));
    let _ = write!(
        out,
        "Attacker reachability: {}\n\n",
        refusal(OperatorInput::AttackerReachability)
    );
}

fn push_proof_of_concept(out: &mut String, advisory: &Advisory, bundled: Option<Reproducer>) {
    let _ = write!(
        out,
        "{POC_HEADING}\n\nA {} byte input drives `{}` into this fault.",
        advisory.reproducer_bytes(),
        advisory.target()
    );
    if let Some(reproducer) = bundled {
        let _ = write!(
            out,
            " It is the file `{}` beside this one, and `./{} <path to the built target>` replays \
             it under the same sanitizer options lisdex used. {}",
            bundle::REPRODUCER,
            bundle::REPRODUCE_SCRIPT,
            reproducer.note()
        );
        let _ = write!(out, " {SYMBOLIZATION_NOTE}");
    }
    let _ = write!(
        out,
        " The sanitizer report it produced is reproduced verbatim below; it is the evidence, and \
         it has not been edited.\n\n```\n{}\n```\n\n",
        advisory.sanitizer_report().trim_end()
    );
}

fn push_analysis(out: &mut String, advisory: &Advisory) {
    let _ = write!(
        out,
        "{ANALYSIS_HEADING}\n\nCall stack as the sanitizer reported it:\n\n"
    );
    if advisory.frames().is_empty() {
        let _ = write!(out, "- (the report carried no frames)\n\n");
        return;
    }
    for frame in advisory.frames() {
        let _ = writeln!(out, "- `{frame}`");
    }
    let _ = writeln!(out);
}

fn provenance_banner(advisory: &Advisory) -> &'static str {
    if advisory.tree().is_benchmark() {
        TREE_PROVENANCE_BANNER
    } else {
        PROVENANCE_BANNER
    }
}

fn push_filing(out: &mut String, advisory: &Advisory) {
    let _ = write!(out, "{FILING_HEADING}\n\n");
    if advisory.provenance() == Provenance::SyntheticBenchmark {
        let _ = write!(out, "{}\n\n", provenance_banner(advisory));
        return;
    }
    let _ = writeln!(out, "- {PACKAGE_NAME_NOTE}");
    let _ = writeln!(out, "- {GHSA_ECOSYSTEM_NOTE}");
    let _ = writeln!(out, "- {GHSA_CVE_NOTE}");
    let _ = writeln!(out, "- {GHSA_CREDIT_NOTE}");
    let _ = writeln!(out, "- {VERSION_NULL_NOTE}");
    let _ = writeln!(out, "- {CVE_RECORD_VERSION_NOTE}");
    let _ = write!(out, "- {DISCLOSURE_NOTE}\n\n");
}

#[must_use]
pub fn render(advisory: &Advisory, bundled: Option<Reproducer>) -> String {
    let mut out = String::new();
    let site = advisory.crash_site().unwrap_or(UNNAMED_SITE);
    let _ = write!(
        out,
        "# Security advisory for {}: {} in {}\n\n",
        advisory.target(),
        advisory.class(),
        site
    );
    if advisory.provenance() == Provenance::SyntheticBenchmark {
        let _ = write!(out, "{}\n\n", provenance_banner(advisory));
    }
    let _ = write!(out, "{DRAFTED_BY}\n\n");
    push_summary(&mut out, advisory);
    push_severity(&mut out, advisory);
    push_proof_of_concept(&mut out, advisory, bundled);
    let _ = write!(out, "{REMEDIATION_HEADING}\n\n{REMEDIATION_BODY}\n\n");
    push_analysis(&mut out, advisory);
    let _ = write!(out, "{TIMELINE_HEADING}\n\n{TIMELINE_BODY}\n\n");
    push_filing(&mut out, advisory);
    out
}