Security
How Numeralens protects financial data, what was tested, and what stays your responsibility once you connect your own backend. Last full audit: 1.3.1, 2026-10-13.
What is enforced
| Area | How | Where |
|---|---|---|
| Sessions | HS256-signed JWT (algorithm pinned) in an httpOnly, Secure, SameSite=Lax cookie, 8-hour expiry. In production with demo mode off, the app refuses to start without AUTH_SECRET. |
src/lib/auth/session.ts |
| Permissions | Every API route names a permission and is checked on the server; every page is checked in proxy.ts. Search and notifications drop items the role can't open. |
src/lib/auth/dal.ts, src/proxy.ts, canOpen in src/config/navigation.ts |
| Sign-in | Constant-time password checks; one error message for unknown email and wrong password; 10 attempts per 5 minutes per address and per account, so rotating X-Forwarded-For doesn't help a guesser. |
src/app/login/actions.ts, src/lib/auth/rate-limit.ts |
| Server actions | Next.js origin check (cross-site calls refused); every argument validated (isRole); the demo role switcher refuses outside demo mode. |
src/app/login/* |
| Input limits | Dates validated (400 on a malformed one) and clamped to 1900–2100; at most 400 chart buckets (a long daily range coarsens); page size 1–500; AI inputs bounded by Zod, dataset size limited to the offered tiers. | src/lib/dates.ts, src/lib/api-route.ts, src/lib/ai/schemas.ts |
| Money | Integer-cent arithmetic; totals exact to the cent; the trial balance is "balanced" only when debits equal credits exactly; overflow throws instead of losing cents. | src/lib/calculations/money.ts, src/mock/engine.ts |
| AI | No generated SQL and no write path; data sent in delimited blocks the data itself can't close; every figure in the model's text must be one Numeralens supplied or derived, or the answer is rejected and the deterministic engine answers instead. Rate limits key on the signed-in user. | src/lib/ai/ (AI architecture) |
| Browser | Security headers on every response; no framing by other sites; no X-Powered-By. A new sign-in or role gets a fresh data cache, so the previous session's figures are never shown. |
next.config.ts, src/providers/query-provider.tsx |
| Errors | Unexpected errors are logged on the server and answered with a generic message; internals never reach the caller. | src/lib/api-route.ts |
| Dependencies | npm audit --omit=dev: 0 known vulnerabilities at release. |
package.json |
How it was tested
The audit treated every route, action and model reply as hostile. The checks
live in the repo, so they run on every npm test and fail if a protection is
removed:
| Suite | What it attacks |
|---|---|
tests/route-matrix.test.ts |
Every API route × every role and signed out (174 checks), forged, expired and edited tokens, every page × every role |
tests/hardening.test.ts |
Resource exhaustion (huge ranges, page sizes, dataset sizes), brute force with rotating addresses, rate-limiter memory, role validation |
tests/ledger-integrity.test.ts |
Every journal balances; trial balance exact; assets = liabilities + equity; P&L → equity; cash flow → cash accounts; AR and AP ageing → control accounts; parent lines = sum of children; no float noise in any report; money edge cases |
tests/ai-redteam.test.ts |
Prompt injection through the question and through ledger data, a simulated model that invents figures, figure grounding |
tests/session-cache.test.tsx |
Cached data crossing a sign-out or role switch |
tests/auth.test.ts |
Session tokens, permission matrix, security headers |
It was also attacked live, against a running production build: cross-site replay of the sign-in action, tampered server-action arguments, brute force with a new spoofed address on every attempt, and a scan of the HTML and React Server Component payloads for secrets and refused data. All were refused.
Your responsibilities
Numeralens is the reporting layer. Once you connect your own backend:
- Set
AUTH_SECRETand replace the demo user directory (authentication). - Authorise in your API too. The browser calls your API directly; check the role on every endpoint, including search and exports.
- Isolate tenants by the authenticated principal, never by ids the browser sends. Run the contract test in authentication.
- Share the rate limits across instances if you run more than one (Redis, Upstash, Vercel KV). The built-in limiter is per instance.
- Keep dependencies current. Run
npm audit --omit=devbefore each deploy. - Add a script CSP if your policy requires one (deployment).
Reporting a vulnerability
Email hello@numeralens.com with the details and steps to reproduce. You'll get a reply within 2–3 business days, and a fix ships as a patch release with a changelog entry.