{"slug": "why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp", "title": "Why I Built a Zero-Upload Credit Card Statement Splitter with Vanilla JS and CSP default-src 'none'", "summary": "A developer built StatementUnpack, a fully client-side credit card statement splitter that runs on static HTML, CSS and vanilla JavaScript with no upload endpoints, enforcing a strict Content-Security-Policy (default-src 'none') and vendoring pdfjs-dist locally with pinned SHA-256 hashes. The tool parses currency into integer cents as BigInt for deterministic reconciliation, halts export with a structured review-only.json report when balances don't reconcile, and separates untrusted text cells from validated numeric fields to block CSV formula injection while preserving legitimate negative amounts for QuickBooks.", "body_md": "If you have ever helped a small business or bookkeeper do catch-up bookkeeping for a corporate credit card with multiple employee cards, you have probably seen two painful things happen:\n\n`Debit` and `Credit` columns, or I wanted to see how far you can push a **100% client-side, zero-upload bookkeeping utility** using plain static HTML, CSS, and vanilla JavaScript—with zero backend upload endpoints and deterministic verification instead of probabilistic AI guesses.\n\nThe result is **[StatementUnpack](https://statementunpack.com/tools/csv-splitter/)**—and along the way, I ran into several surprisingly subtle engineering and security details worth sharing.\n\nSaying *\"we don't upload your files\"* on a landing page is easy. Making it verifiable in DevTools is much better.\n\nStatementUnpack ships as pure static files with a strict `Content-Security-Policy` header on every route:\n\n```\nContent-Security-Policy:\n  default-src 'none';\n  script-src 'self';\n  style-src 'self';\n  worker-src 'self';\n  connect-src 'self';\n  img-src 'self';\n  base-uri 'none';\n  form-action 'none';\n  frame-ancestors 'none'\n```\n\nWhat this enforces in practice:\n\n`pdfjs-dist@5.6.205`) and its worker are vendored locally on the same origin and verified against pinned SHA-256 hashes at build time.`form-action 'none'` and `connect-src 'self'` block accidental data exfiltration to external domains.`File.arrayBuffer()` / `File.text()`, processed in browser memory, and exported locally as `Blob` downloads. You can open Chrome DevTools → *(Full disclosure: the site does load Vercel's cookie-free, same-origin Web Analytics script `/_vercel/insights/script.js` for basic anonymous pageview counts—never file names, file contents, or transaction data.)*\n\n`BigInt` Cent Math Matters for Financial Parsing\nA surprising number of quick-and-dirty statement parsers parse currency strings with `parseFloat()`. That works right up until a 40-transaction statement fails an opening/closing balance check by `$0.0000000000000284`.\n\nIn the PDF parser (`parser.js`), every dollar amount is normalized directly into integer cents as a `BigInt` before any arithmetic runs:\n\n``` js\nconst cents = value => BigInt(value.replace(/[,.]/g, ''));\n\nconst format = cents => {\n  const parts = (cents < 0n ? -cents : cents).toString().padStart(3, '0');\n  return (cents < 0n ? '-' : '') + parts.slice(0, -2) + '.' + parts.slice(-2);\n};\n```\n\nCombined with deterministic column boundaries and per-account reconciliation (`previousBalance + netTransactions === newBalance`), the PDF splitter refuses to silently drop a row or guess a missing figure. If anything doesn't reconcile—or if a file is an unsupported layout or scanned image—it halts export and produces a structured `review-only.json` report instead.\n\nHere is a security edge case that bites almost every CSV exporter: **CSV / Spreadsheet Formula Injection**.\n\nIf an untrusted merchant description or cardholder label starts with `=`, `+`, `-`, `@` (or their full-width Unicode equivalents `＝`, `＋`, `－`, `＠`, even after leading whitespace or a UTF-8 BOM), opening the exported CSV in Excel or Google Sheets can trigger formula execution.\n\nAt the same time, **QuickBooks credit card CSVs require legitimate negative numbers** like `-42.50` in the `Amount` column!\n\nSo instead of blindly prefixing every cell with an apostrophe (which corrupts numeric `Amount` columns in QuickBooks), StatementUnpack separates **untrusted text cells** from **validated numeric fields**:\n\n``` js\nconst FORMULA_PREFIX = /^[=+\\-@＝＋－＠]/u;\nconst CONTROL_CHARS = /[\\x00-\\x1f\\x7f-\\x9f]/u;\n\nexport function isSafeCell(value) {\n  const str = String(value ?? '');\n  return (\n    !CONTROL_CHARS.test(str) &&\n    !FORMULA_PREFIX.test(str.replace(/^[\\s\\uFEFF]+/u, ''))\n  );\n}\n```\n\n`Amount` values are formatted strictly as numeric decimals (`-42.50` or `120.00`).` Date`, `Description`, cardholder name) and filename is checked against `FORMULA_PREFIX` and `CONTROL_CHARS`.` innerHTML`) and Parsing untrusted PDFs inside a user's browser carries its own DoS/security risks: PDF JavaScript actions (`OpenAction`), XFA forms, huge page counts, or console-log leakage of raw PDF tokens.\n\nTo keep browser parsing predictable:\n\n`10 MiB`, max `20` pages, a `30s` soft timeout, max `35,000` extracted text items, and max `2,097,152` UTF-16 code units.\nI want to be completely transparent about what is validated today versus what isn't:\n\n`Card Member` / `Cardholder` / `Card No.` columns and splits combined corporate card CSVs into one 3-column CSV per card.`$`/commas/parentheses/` CR`/` DR`, and flips reversed QuickBooks Online signs in one click.\nIf you want to poke at the CSP headers, inspect the Network tab, or test the CSV splitter with a dummy/redacted business card export:\n\n👉 **Try the CSV Splitter (any bank):** [https://statementunpack.com/tools/csv-splitter/](https://statementunpack.com/tools/csv-splitter/)\n\n👉 **Try the PDF Splitter Demo:** [https://statementunpack.com/](https://statementunpack.com/)\n\nBefore I build PDF parsers for additional banks, I'm trying to learn from real-world workflows:\n\nDrop a comment below—blunt technical or UX feedback is super welcome!", "url": "https://wpnews.pro/news/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp", "canonical_source": "https://dev.to/cicadaca/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp-default-src-none-17lk", "published_at": "2026-11-24 11:39:17+00:00", "updated_at": "2026-11-24 11:43:38.012916+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools"], "entities": ["StatementUnpack", "pdfjs-dist", "QuickBooks", "Vercel", "Google Sheets", "Excel"], "also_reported_by": [], "takeaway": "Parse currency into integer cents with BigInt and reconcile per account before export, and sanitize only untrusted text cells for formula-injection prefixes while keeping validated numeric Amount fields as plain decimals.", "recommendation": {"advice": "Reconcile every parsed statement against opening and closing balances and halt export with a structured review report rather than guessing, and sanitize text cells for formula prefixes while leaving validated numeric fields untouched.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp", "markdown": "https://wpnews.pro/news/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp.md", "text": "https://wpnews.pro/news/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp.txt", "jsonld": "https://wpnews.pro/news/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp.jsonld"}}