Skip to content

fix: [Timetraked] Harden SQL API, AI proxy and sign-in flow - #284

Merged
AdamJ merged 1 commit into
mainfrom
fix/security-ux-audit
Nov 14, 2026
Merged

AdamJ merged 1 commit into
mainfrom
fix/security-ux-audit

Conversation

@AdamJ

@AdamJ AdamJ commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes from a security and UX audit of the web app, the ai-proxy Edge Function, the self-hosted SQL server and the sign-in flow. Highlights: the SQL API is no longer open to the network or to other websites, ai-proxy now requires a signed-in user (accounts are invite-only), sign-out asks whether to keep data on the device, and the guest button (now "Use on device") no longer signs the user in.

Type of Change

  • New feature
  • Update to existing feature
  • Bug fix
  • Documentation update
  • Other (describe below): security hardening, dependency updates, and removal of stale bun.lock/package-lock.json (Cloudflare Pages was installing with bun from an outdated bun.lock)

Related Issue

None. Findings come from the audit report.

Changes Made

Security

  • server/app.ts, server/index.ts, server/db.ts: bind to 127.0.0.1 by default; CORS limited to SQL_ALLOWED_ORIGINS; optional bearer token SQL_API_TOKEN, required to listen on any other host; generic error responses; database TLS certificates verified, with a new DB_SSL_CA option. Client sends VITE_SQL_API_TOKEN (src/services/sqlApiService.ts).
  • supabase/functions/ai-proxy/index.ts: requires a signed-in user (token checked against /auth/v1/user, so the anon key gets 401); 10 requests a minute per user; body read in chunks and capped at 256 KB; only systemInstruction/contents/generationConfig forwarded; key sent as x-goog-api-key header; Tauri origins allowed. Already deployed.
  • vite.config.ts, clearLocalData.ts, main.tsx, AuthContext.tsx: removed the service-worker cache of Supabase responses and delete any old cache on startup and sign-out.
  • SignOutDialog.tsx (new), UserMenu.tsx, TimeTrackingContext.tsx: sign-out offers "Keep a copy" or "Remove from this device"; the choice survives a failed sign-out, which shows a toast.
  • index.html, public/_headers (new): CSP drops 'unsafe-inline' scripts and the stale Gemini host; Cloudflare Pages gets CSP with frame-ancestors 'none', HSTS (max-age=300 to start), nosniff, Referrer-Policy, Permissions-Policy and COOP.
  • package.json, pnpm-workspace.yaml: react-router-dom 6.30.6, express 5.3.0, mysql2 3.24.6; overrides for body-parser and qs. Audit goes from 10 production advisories to 3; the rest need react-router 7 and zod 4.
  • exportUtils.ts: CSV formula guard also covers a leading tab or carriage return.

UX

  • AuthDialog.tsx: guest button is type="button" and renamed "Use on device"; autofill attributes, show/hide password, readable errors linked to the fields; invite-only note removed. No in-app sign-up or password reset (passwords are managed in the Supabase dashboard); unused signUp removed from AuthContext.
  • Report.tsx, useReportSummary.ts: Generate disabled for guests with a sign-in hint; proxy errors shown as readable messages.
  • ExportDialog.tsx: native alert() replaced by an inline hint.
  • ClientSheet.tsx, NewTaskForm.tsx: section-client autofill tokens; task title autocomplete="off".
  • ClientManagement.tsx: Maps and email links URL-encoded.

Tests: server/app.test.ts, AuthDialog.test.tsx, clearLocalData.test.ts (new); new cases in useReportSummary.test.ts and exportUtils.test.ts.

Docs: CHANGELOG.md, README.md, README-EXT.md, AGENTS.md, docs/SQL_BACKEND.md, .env.example.

Checklist

Documentation

  • Any notable changes added to the README.md
  • CHANGELOG.md updated accordingly
  • N/A — no README changes

General

  • Branch is up to date with main
  • No unrelated files included in this PR
  • Tested locally by invoking the pnpm test, pnpm lint, and pnpm build

pnpm test: 43 files, 495 tests pass. pnpm build passes. pnpm lint reports no new errors in changed files, but the repo has existing lint errors, so the command doesn't pass overall. Not manually tested in the browser.

Notes for Reviewers

  • Self-hosted SQL users: with no token set the server still starts, but only on 127.0.0.1. To listen on any other host, set SQL_API_TOKEN on the server and the same value as VITE_SQL_API_TOKEN on the frontend. The frontend token is bundled into the client, so this suits personal setups only.
  • AI summaries no longer work in guest mode.
  • "Remove from this device" doesn't delete Tauri disk backups.

🤖 Generated with Claude Code

@AdamJ AdamJ added fix For general fixes or bundled fixes security For security related issues and fixes frontend supabase labels Nov 13, 2026
@github-actions github-actions Bot added automation For items related to release/documentation/workflow automations dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation labels Nov 13, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying timetrackerpro with  Cloudflare Pages  Cloudflare Pages

Latest commit: 37875ab
Status: ✅  Deploy successful!
Preview URL: https://d5de3685.timetrackerpro.pages.dev
Branch Preview URL: https://fix-security-ux-audit.timetrackerpro.pages.dev

View logs

@AdamJ AdamJ self-assigned this Nov 14, 2026
@AdamJ AdamJ added this to Timetraked Nov 14, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Timetraked Nov 14, 2026
Security
- Self-hosted SQL API binds to 127.0.0.1 by default, limits CORS to
  SQL_ALLOWED_ORIGINS, supports a SQL_API_TOKEN bearer token (required
  off loopback), returns generic errors, and verifies database TLS
  certificates (DB_SSL_CA)
- ai-proxy requires a signed-in user (anon key rejected), rate-limits
  per user, streams and caps request bodies at 256 KB, forwards only
  allowlisted fields, sends the Gemini key as a header, and allows the
  Tauri origins
- Remove the service-worker cache of Supabase responses and purge it
  on startup and sign-out
- Tighten the web CSP (no inline scripts) and add public/_headers with
  frame-ancestors, HSTS, nosniff, Referrer-Policy, Permissions-Policy
  and COOP
- Update react-router-dom, express and mysql2; override body-parser
  and qs
- URL-encode client map/email links; extend the CSV formula guard to
  tab and carriage return

Sign-out and local data
- Sign Out asks "Keep a copy" or "Remove from this device"
- Copy account data to the device before Supabase ends the session
  (it previously failed with "User not authenticated"), capped at 5 s
- "Remove" clears localStorage data, saved summaries and desktop/iOS
  disk backups (new backup_clear Tauri command); backups stay paused
  until a clean guest-mode reload, fail closed on errors, and resume if
  Supabase fails to sign out

Sign-in and UX
- Accounts are invite-only: no in-app sign-up or password reset
- "Use on device" no longer submits the sign-in form; autofill
  attributes, show/hide password and readable, linked error messages
- AI summaries require sign-in; readable proxy errors
- Inline hint replaces the invoice alert(); autofill tokens on client
  and task forms

Build and docs
- Remove stale bun.lock and package-lock.json so Cloudflare Pages
  installs with pnpm; ignore supabase/.temp
- Update CHANGELOG, README, README-EXT, AGENTS, SQL_BACKEND and CI_CD
  docs
@AdamJ
AdamJ force-pushed the fix/security-ux-audit branch from dbc968c to 37875ab Compare November 14, 2026 02:04
@AdamJ
AdamJ merged commit 734a84f into main Nov 14, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Timetraked Nov 14, 2026
@AdamJ
AdamJ deleted the fix/security-ux-audit branch November 14, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation For items related to release/documentation/workflow automations dependencies Pull requests that update a dependency file desktop documentation Improvements or additions to documentation fix For general fixes or bundled fixes frontend security For security related issues and fixes supabase

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant