1
0
Fork 0

fix: harden CSV export against formula injection and CR row corruption

Fields starting with =, +, -, @, tab, or CR are now neutralized with a
leading single quote before quoting, closing a CSV/spreadsheet formula
injection gap (CWE-1236) flagged by automated security review. Also
closes a bare-CR gap in the RFC 4180 escape trigger set.
This commit is contained in:
Jonny 2026-07-13 17:02:07 +02:00
parent 9f2b2d292e
commit 45612501df
2 changed files with 26 additions and 3 deletions

View File

@ -34,4 +34,20 @@ describe("schichtenZuCsv", () => {
]); ]);
expect(csv).toContain('"Anna ""Ann"" Fahrer;Zusatz"'); expect(csv).toContain('"Anna ""Ann"" Fahrer;Zusatz"');
}); });
it("entschaerft ein Formel-Trigger-Zeichen am Feldanfang (CSV-Injection)", () => {
const csv = schichtenZuCsv([
{
fahrerName: '=HYPERLINK("http://evil.example","click")',
datum: "2026-07-13",
kommtUm: "2026-07-13T06:00:00.000Z",
gehtUm: null,
bruttoMinuten: 0,
pauseMinuten: 0,
nettoMinuten: 0,
},
]);
expect(csv).toContain(`'=HYPERLINK`);
expect(csv).not.toMatch(/;=HYPERLINK/);
});
}); });

View File

@ -9,10 +9,17 @@ export type CsvZeile = {
}; };
function csvFeld(wert: string): string { function csvFeld(wert: string): string {
if (wert.includes(";") || wert.includes('"') || wert.includes("\n")) { const mussEntschaerft = /^[=+\-@\t\r]/.test(wert);
return `"${wert.replace(/"/g, '""')}"`; const entschaerft = mussEntschaerft ? `'${wert}` : wert;
if (
entschaerft.includes(";") ||
entschaerft.includes('"') ||
entschaerft.includes("\n") ||
entschaerft.includes("\r")
) {
return `"${entschaerft.replace(/"/g, '""')}"`;
} }
return wert; return entschaerft;
} }
function formatiereUhrzeit(iso: string): string { function formatiereUhrzeit(iso: string): string {