From fde809dd0ca5cd6eca452a7a0a1e9b929bac7f4b Mon Sep 17 00:00:00 2001 From: Coff0xc <184964491+Coff0xc@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:06:00 +0000 Subject: [PATCH] fix(report): neutralize formula cells in findings CSV export FindingsCSV wrote name, class, summary, and task text as-is. A value starting with =, +, -, @, tab, or CR is evaluated as a formula when the file is opened in Excel or LibreOffice. Those cells are now prefixed with a single quote. --- CHANGELOG.md | 1 + report/findings.go | 33 ++++++++++++++++++++++++--------- report/report_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b32bc8..99167e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ All notable changes to this project are documented in this file. The format is b ### Fixed +- **Findings CSV formula cells**: `FindingsCSV` prefixes name, class, summary, task, and other text fields that start with `=`, `+`, `-`, `@`, tab, or CR so Excel/LibreOffice do not evaluate them as formulas when the export is opened. - **ask_operator image_path**: the screenshot path must resolve inside the task working directory (`/tasks/`). Absolute paths, `..` segments, and symlinks that leave that directory are refused, so the tool cannot copy an arbitrary server image into the operator transcript. - **insert_assets fail-closed**: when intercept or task allow/block rules cannot be loaded, `insert_assets` refuses the whole call instead of evaluating an empty rule set (which allowed every asset). The tool result does not include the underlying database error. - **BlobRange length no longer wraps int64**: `offset+length > size` overflowed when length was near MaxInt64, so the cap was skipped and `make([]byte, length)` could exhaust memory. The bound is now `length > size-offset`. diff --git a/report/findings.go b/report/findings.go index 1ac268d..7c3aa86 100644 --- a/report/findings.go +++ b/report/findings.go @@ -154,21 +154,36 @@ func FindingsCSV(fs []*db.DBFinding) []byte { for _, f := range items { _ = w.Write([]string{ fmt.Sprintf("%d", f.ID), - findingTitle(f), - f.VulnClass, - nz(f.Severity, "info"), - nz(f.Status, "pending"), - nz(f.ReportState, "none"), - f.TaskDescription, - f.CreatedAt.Format("2006-01-02 15:04:05"), - strings.TrimSpace(f.Summary), - fmt.Sprint(len(f.TrafficBindings)), findingTrafficIDs(f), + csvCell(findingTitle(f)), + csvCell(f.VulnClass), + csvCell(nz(f.Severity, "info")), + csvCell(nz(f.Status, "pending")), + csvCell(nz(f.ReportState, "none")), + csvCell(f.TaskDescription), + csvCell(f.CreatedAt.Format("2006-01-02 15:04:05")), + csvCell(strings.TrimSpace(f.Summary)), + fmt.Sprint(len(f.TrafficBindings)), + csvCell(findingTrafficIDs(f)), }) } w.Flush() return buf.Bytes() } +// csvCell prefixes cells that spreadsheet apps treat as formulas. encoding/csv +// only quotes delimiters; Excel/LibreOffice still evaluate a leading +// '=', '+', '-', '@', tab, or CR when the file is opened. +func csvCell(s string) string { + if s == "" { + return s + } + switch s[0] { + case '=', '+', '-', '@', '\t', '\r': + return "'" + s + } + return s +} + func findingTrafficIDs(f *db.DBFinding) string { ids := make([]string, 0, len(f.TrafficBindings)) for _, b := range f.TrafficBindings { diff --git a/report/report_test.go b/report/report_test.go index 6b5750e..88069b1 100644 --- a/report/report_test.go +++ b/report/report_test.go @@ -1,6 +1,8 @@ package report import ( + "bytes" + "encoding/csv" "fmt" "strings" "testing" @@ -314,3 +316,42 @@ func TestFindingsExportsCarryQuality(t *testing.T) { t.Errorf("export lost the binding count entirely\n%s", md) } } + +func TestFindingsCSVNeutralizesFormulas(t *testing.T) { + out := FindingsCSV([]*db.DBFinding{{ + ID: 7, + Name: `=HYPERLINK("http://evil.example/x","x")`, + VulnClass: "+cmd", + Severity: "high", + Status: "pending", + ReportState: "none", + TaskDescription: "@SUM(1+1)", + CreatedAt: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC), + Summary: "-2+3", + }}) + if !bytes.HasPrefix(out, []byte("\xEF\xBB\xBF")) { + t.Fatal("CSV lost the UTF-8 BOM") + } + records, err := csv.NewReader(bytes.NewReader(out[3:])).ReadAll() + if err != nil { + t.Fatal(err) + } + if len(records) != 2 { + t.Fatalf("rows=%d, want header+1", len(records)) + } + row := records[1] + want := map[int]string{ + 1: `'=HYPERLINK("http://evil.example/x","x")`, + 2: `'+cmd`, + 6: `'@SUM(1+1)`, + 8: `'-2+3`, + } + for i, prefix := range want { + if row[i] != prefix { + t.Errorf("col %d = %q, want %q", i, row[i], prefix) + } + } + if strings.HasPrefix(row[3], "'") { + t.Errorf("plain severity %q should not be prefixed", row[3]) + } +}