forked from fahrPool/fahrPool
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:
parent
9f2b2d292e
commit
45612501df
|
|
@ -34,4 +34,20 @@ describe("schichtenZuCsv", () => {
|
|||
]);
|
||||
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/);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,10 +9,17 @@ export type CsvZeile = {
|
|||
};
|
||||
|
||||
function csvFeld(wert: string): string {
|
||||
if (wert.includes(";") || wert.includes('"') || wert.includes("\n")) {
|
||||
return `"${wert.replace(/"/g, '""')}"`;
|
||||
const mussEntschaerft = /^[=+\-@\t\r]/.test(wert);
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue