Why I Built a Zero-Upload Credit Card Statement Splitter with Vanilla JS and CSP default-src 'none'
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: Multi-card CSV chaos in QuickB
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:
-
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
DebitandCreditcolumns, or reversed signs (charges listed as positive numbers, which QuickBooks Online imports backward as payments/credits). - 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 (
[email protected]) 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'andconnect-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 asBlobdownloads. 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
Amountvalues are formatted strictly as numeric decimals (-42.50or120.00). - Every text cell (
Date,Description, cardholder name) and filename is checked againstFORMULA_PREFIXandCONTROL_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, max20pages, a30ssoft timeout, max35,000extracted text items, and max2,097,152UTF-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&Creditcolumns, 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:
- Which bank CSV or PDF format breaks your bookkeeping imports most often?
- 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!
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.