Skip to content
Merged
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
24 changes: 22 additions & 2 deletions report/findings.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func FindingsMarkdown(fs []*db.DBFinding, generatedAt time.Time) string {
fmt.Fprintf(&b, "%s\n\n", s)
}
if e := strings.TrimSpace(f.Evidence); e != "" {
fmt.Fprintf(&b, "**Evidence:**\n\n```\n%s\n```\n\n", e)
fmt.Fprintf(&b, "**Evidence:**\n\n%s\n", fencedBlock(e))
}
b.WriteString(qualityNarrative(q))
b.WriteString(detailedReportFull(f.Report, "**Detailed report:**"))
Expand Down Expand Up @@ -115,7 +115,7 @@ func SingleFindingMarkdown(f *db.DBFinding, generatedAt time.Time) string {
fmt.Fprintf(&b, "## Summary\n\n%s\n\n", s)
}
if e := strings.TrimSpace(f.Evidence); e != "" {
fmt.Fprintf(&b, "## Evidence\n\n```\n%s\n```\n\n", e)
fmt.Fprintf(&b, "## Evidence\n\n%s\n", fencedBlock(e))
}
b.WriteString(qualityNarrative(q))
b.WriteString(detailedReportFull(f.Report, "## Detailed Report"))
Expand Down Expand Up @@ -270,3 +270,23 @@ func findingTrafficMarkdown(f *db.DBFinding, attachments bool) string {
out.WriteString("\n")
return out.String()
}

// fencedBlock wraps s in a Markdown code fence that is longer than any run of
// backticks inside s, so evidence that itself contains a ``` line (a captured
// response body, a README, a prompt) cannot close the block early and turn the
// rest of the text into live Markdown. The result ends with a newline.
func fencedBlock(s string) string {
longest, run := 0, 0
for _, r := range s {
if r == '`' {
run++
if run > longest {
longest = run
}
} else {
run = 0
}
}
fence := strings.Repeat("`", max(3, longest+1))
return fence + "\n" + s + "\n" + fence + "\n"
}
2 changes: 1 addition & 1 deletion report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Markdown(in Input) string {
fmt.Fprintf(&b, "%s\n\n", nz(f.Summary, ""))
b.WriteString(qualityBullets(f.Q, true)) // honest proof strength, including its gaps
if f.PoC != "" {
fmt.Fprintf(&b, "**PoC / Evidence:**\n\n```\n%s\n```\n\n", f.PoC)
fmt.Fprintf(&b, "**PoC / Evidence:**\n\n%s\n", fencedBlock(f.PoC))
}
b.WriteString(qualityNarrative(f.Q)) // why it holds / what failed, only when written
// The same warning, from the same helper, that the findings export prints: a
Expand Down
21 changes: 21 additions & 0 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,24 @@ func TestFindingFilenameUnicodeAndIDSuffix(t *testing.T) {
t.Fatalf("expected preserved distinct ID suffixes: f1=%q f2=%q", f1, f2)
}
}

// Evidence that contains its own ``` line must stay inside its code block in
// every export that prints it.
func TestEvidenceWithBacktickFenceStaysInBlock(t *testing.T) {
ev := "HTTP/1.1 200 OK\n\n```\n# injected heading\n[click](http://evil.example)"
f := &db.DBFinding{ID: 7, Name: "x", Severity: "high", Evidence: ev, CreatedAt: time.Unix(1, 0)}
for name, md := range map[string]string{
"summary": FindingsMarkdown([]*db.DBFinding{f}, time.Unix(2, 0)),
"single": SingleFindingMarkdown(f, time.Unix(2, 0)),
} {
i := strings.Index(md, ev)
if i < 0 {
t.Fatalf("%s: evidence missing", name)
}
before := md[:i]
after := md[i+len(ev):]
if !strings.Contains(before, "````\n") || !strings.HasPrefix(after, "\n````\n") {
t.Errorf("%s: evidence is not wrapped in a fence longer than its own backticks:\n%s", name, md)
}
}
}
Loading