diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 34122c2b4..744db2f3b 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -28,3 +28,8 @@ **Vulnerability:** The Rust backend (`apps/desktop/src-tauri/src/main.rs`) did not enforce a maximum URL length limit when processing YouTube URLs via `import_youtube_url`. While the frontend enforced `MAX_YOUTUBE_URL_LENGTH = 2000` via the input element, this could be bypassed by an attacker sending requests directly to the Tauri backend API, potentially causing a Denial of Service (DoS) due to unbounded URL parsing and regex matching. **Learning:** Input validation must occur at the entry point of untrusted data on the backend, even if it is also validated on the frontend. Relying solely on frontend validation for constraints like string length can expose the backend to resource exhaustion vulnerabilities. **Prevention:** Always enforce constraints like maximum length, format validation, and sanitization at the earliest possible point on the backend, typically at the API boundary, regardless of frontend safeguards. + +## 2026-09-03 - CSV Formula Injection NUL byte bypass +**Vulnerability:** CSV formula injection mitigation was bypassed using a NUL byte (`\x00`) prefix which was not included in the sanitization regex. +**Learning:** Null bytes can be used to bypass simple character checks while still executing formulas in some spreadsheet applications. +**Prevention:** Include `\x00` in the regex for formula injection prevention (`/^[\s\uFEFF\xA0]*[=+\-@\t\r\n\x00]/`), and bypass the ESLint `no-control-regex` rule to permit the explicit control character. diff --git a/apps/desktop/src/lib/export.test.ts b/apps/desktop/src/lib/export.test.ts index 265e983d4..4b45ad9da 100644 --- a/apps/desktop/src/lib/export.test.ts +++ b/apps/desktop/src/lib/export.test.ts @@ -67,6 +67,7 @@ describe("export sanitization", () => { expect(escapeCsvField("\t+SUM(A1)")).toBe("'\t+SUM(A1)"); expect(escapeCsvField("\n-100")).toBe("\"'\n-100\""); expect(escapeCsvField("\r@cmd")).toBe("\"'\r@cmd\""); + expect(escapeCsvField("\x00some data")).toBe("'\x00some data"); }); it("handles combined scenarios: formula injection with structural characters", () => { diff --git a/apps/desktop/src/lib/export.ts b/apps/desktop/src/lib/export.ts index 3d4493b1d..52be02b8d 100644 --- a/apps/desktop/src/lib/export.ts +++ b/apps/desktop/src/lib/export.ts @@ -23,7 +23,8 @@ export function sanitizeFilename(title: string): string { export function escapeCsvField(value: string): string { let escapedValue = value; // Prevent CSV formula injection by prefixing problematic leading characters with a single quote - if (/^[\s\uFEFF\xA0]*[=+\-@\t\r\n]/.test(value)) { + // eslint-disable-next-line no-control-regex + if (/^[\s\uFEFF\xA0]*[=+\-@\t\r\n\x00]/.test(value)) { escapedValue = `'${value}`; } // Enclose in double quotes if there's a comma, newline, or double quote