Why I Built a Zero-Upload Credit Card Statement Splitter with Vanilla JS and CSP default-src 'none'

2026-11-24来源 dev.toEnglish

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:

  1. Multi-card CSV chaos in QuickBooks Online: Banks like Amex Business, Chase Ink, Capital One Spark, and Bank of America export either one combined CSV containing every employee card, separate Debit and Credit columns, or reversed signs (charges listed as positive numbers, which QuickBooks Online imports backward as payments/credits).
  2. The privacy trap: When people look for a quick statement splitter or PDF-to-CSV tool, almost every top search result asks them to upload raw client financial statements—account numbers, vendor names, dollar amounts—to a third-party cloud server or a general-purpose LLM chat.

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.

The result is StatementUnpack—and along the way, I ran into several surprisingly subtle engineering and security details worth sharing.

1. Enforcing "Zero Uploads" at the Browser Level (Not Just in Marketing Copy)

Saying "we don't upload your files" on a landing page is easy. Making it verifiable in DevTools is much better.

StatementUnpack ships as pure static files with a strict Content-Security-Policy header on every route:

Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; worker-src 'self'; connect-src 'self'; img-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none' 

What this enforces in practice:

  • No third-party scripts, CDNs, or external API calls: Even PDF.js (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.
  • No form submissions or outbound beacons: form-action 'none' and connect-src 'self' block accidental data exfiltration to external domains.
  • Local memory only: Files are read via File.arrayBuffer() / File.text(), processed in browser memory, and exported locally as Blob downloads. You can open Chrome DevTools → Network, drop a sample CSV or PDF, and confirm zero file bytes leave the browser.

(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.)

2. Why BigInt Cent Math Matters for Financial Parsing

A 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.

In the PDF parser (parser.js), every dollar amount is normalized directly into integer cents as a BigInt before any arithmetic runs:

const cents = value => BigInt(value.replace(/[,.]/g, '')); const format = cents => { const parts = (cents < 0n ? -cents : cents).toString().padStart(3, '0'); return (cents < 0n ? '-' : '') + parts.slice(0, -2) + '.' + parts.slice(-2); }; 

Combined 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.

3. Blocking Spreadsheet Formula Injection Without Breaking Negative Amounts

Here is a security edge case that bites almost every CSV exporter: CSV / Spreadsheet Formula Injection.

If 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.

At the same time, QuickBooks credit card CSVs require legitimate negative numbers like -42.50 in the Amount column!

So 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:

const FORMULA_PREFIX = /^[=+\-@=+-@]/u; const CONTROL_CHARS = /[\x00-\x1f\x7f-\x9f]/u; export function isSafeCell(value) { const str = String(value ?? ''); return ( !CONTROL_CHARS.test(str) && !FORMULA_PREFIX.test(str.replace(/^[\s\uFEFF]+/u, '')) ); } 
  • Validated Amount values are formatted strictly as numeric decimals (-42.50 or 120.00).
  • Every text cell (Date, Description, cardholder name) and filename is checked against FORMULA_PREFIX and CONTROL_CHARS.
  • If a dangerous prefix or control character appears in untrusted text, the UI renders everything safely via DOM text nodes (never innerHTML) and locks standard CSV export into review-only mode rather than letting a weaponized spreadsheet silently download.

4. Putting Hard Budgets on Untrusted Browser PDFs

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.

To keep browser parsing predictable:

  • PDF JavaScript evaluation and XFA are disabled in the PDF.js configuration.
  • Explicit resource limits: Max 10 MiB, max 20 pages, a 30s soft timeout, max 35,000 extracted text items, and max 2,097,152 UTF-16 code units.
  • Worker lifecycle cleanup: Workers are terminated immediately on completion, error, or user cancellation.
  • Zero raw-content console logging: PDF.js warnings that can echo raw PDF command fragments into DevTools are suppressed, keeping error reporting strictly categorized.

5. What Works Today (and Honest Scope Limits)

I want to be completely transparent about what is validated today versus what isn't:

  • Works with any bank today — Universal Credit Card CSV Splitter & QuickBooks Sign Flipper:
    • Pure RFC 4180 client-side CSV parser (zero dependencies, up to 50,000 rows).
    • Auto-detects Card Member / Cardholder / Card No. columns and splits combined corporate card CSVs into one 3-column CSV per card.
    • Merges separate Debit & Credit columns, strips $/commas/parentheses/CR/DR, and flips reversed QuickBooks Online signs in one click.
    • Includes quick checklists for Chase Ink, Amex Business, Capital One Spark, and Bank of America.
  • Multi-Account PDF Splitter (statementunpack.com):
    • Currently validated on the CUAnswers Business Credit Card Summary text-PDF format (includes a 1-click fictional demo with 2 accounts and row-level PDF page provenance).
    • Live QuickBooks Online test-company imports have not yet been independently audited—always verify the QBO preview screen before confirming an import.

Looking for Honest Feedback from Developers & Bookkeepers

If you want to poke at the CSP headers, inspect the Network tab, or test the CSV splitter with a dummy/redacted business card export:

👉 Try the CSV Splitter (any bank): https://statementunpack.com/tools/csv-splitter/

👉 Try the PDF Splitter Demo: https://statementunpack.com/

Before I build PDF parsers for additional banks, I'm trying to learn from real-world workflows:

  1. Which bank CSV or PDF format breaks your bookkeeping imports most often?
  2. Did you spot any edge case in the CSV parser, sign flipper, or CSP setup?

Drop a comment below—blunt technical or UX feedback is super welcome!

原文:https://www.a8q9.cn/en/article/why-i-built-a-zero-upload-credit-card-statement-splitter-with-vanilla-js-and-csp-defdb6.html

相关文章