ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.
Python active-directorycloud-securitydefensive-validationfastapigood-first-issuemitre-attackopsecreactred-teamreportingsecurity
fix(web): harden host CSV export against spreadsheet formula injection (#77)
kraii_8cae6f1f1e5b
diff --git a/frontend/src/features/graph/GraphPage.tsx b/frontend/src/features/graph/GraphPage.tsxindex 8328653..d4f33b4 100644--- a/frontend/src/features/graph/GraphPage.tsx+++ b/frontend/src/features/graph/GraphPage.tsx@@ -35,6 +35,7 @@ import {} from "./graphModel";import { PivotComputerNode, PivotFirewallNode, type PivotNodeData } from "./CobaltStrikeNodes";import { CobaltSessionDock } from "./CobaltSessionDock";+import { csvCell } from "./csvExport";import { TacticalInspectorDrawer } from "./TacticalInspectorDrawer";type CanvasNode = Node<PivotNodeData, string>;@@ -681,7 +682,10 @@ export default function GraphPage({.map((node) => {const inf = inferCobaltNodeData(node);const isCompromised = inf.status === "active" || inf.privilege !== "uncompromised" || Boolean(node.metadata?.owned);- return `"${node.id}","${node.label}","${node.type}","${inf.ip || ""}","${inf.os}","${inf.privilege}","${isCompromised ? "Compromised" : "Target"}"`;+ return [+ node.id, node.label, node.type, inf.ip || "", inf.os, inf.privilege,+ isCompromised ? "Compromised" : "Target",+ ].map(csvCell).join(",");}).join("\n");const blob = new Blob([headers + rows], { type: "text/csv;charset=utf-8;" });diff --git a/frontend/src/features/graph/csvExport.test.ts b/frontend/src/features/graph/csvExport.test.tsnew file mode 100644index 0000000..35074f3--- /dev/null+++ b/frontend/src/features/graph/csvExport.test.ts@@ -0,0 +1,25 @@+import { describe, expect, it } from "vitest";++import { csvCell } from "./csvExport";++// AUDIT run-1 M11: CSV export must neutralize spreadsheet formula injection.+describe("csvCell", () => {+ it("prefixes formula-triggering cells with a single quote", () => {+ expect(csvCell("=SUM(A1:A2)")).toBe(`"'=SUM(A1:A2)"`);+ expect(csvCell("+1")).toBe(`"'+1"`);+ expect(csvCell("-2")).toBe(`"'-2"`);+ expect(csvCell("@cmd")).toBe(`"'@cmd"`);+ expect(csvCell("=cmd|'/c calc'!A1")).toBe(`"'=cmd|'/c calc'!A1"`);+ });++ it("escapes embedded double quotes", () => {+ expect(csvCell('a"b')).toBe(`"a""b"`);+ });++ it("leaves ordinary values untouched and handles null/empty", () => {+ expect(csvCell("dc01.corp.local")).toBe(`"dc01.corp.local"`);+ expect(csvCell("")).toBe(`""`);+ expect(csvCell(null)).toBe(`""`);+ expect(csvCell(undefined)).toBe(`""`);+ });+});diff --git a/frontend/src/features/graph/csvExport.ts b/frontend/src/features/graph/csvExport.tsnew file mode 100644index 0000000..0314f00--- /dev/null+++ b/frontend/src/features/graph/csvExport.ts@@ -0,0 +1,12 @@+// CSV cell encoding with spreadsheet-formula-injection hardening.+// AUDIT run-1 M11: a cell beginning with =,+,-,@ (or a control character) is+// treated as an executable formula by Excel / Google Sheets when the exported+// file is opened, so a hostname like "=cmd|'/c calc'!A1" would run. Prefix such+// cells with a single quote and escape embedded double-quotes before wrapping.+export function csvCell(value: unknown): string {+ let s = value == null ? "" : String(value);+ if (/^[=+\-@\t\r]/.test(s)) {+ s = `'${s}`;+ }+ return `"${s.replace(/"/g, '""')}"`;+}