Skip to content

Security/billframe reliability hardening - #1

Merged
LETSCOOKTECH merged 7 commits into
mainfrom
security/billframe-reliability-hardening
Nov 6, 2026
Merged

LETSCOOKTECH merged 7 commits into
mainfrom
security/billframe-reliability-hardening

Conversation

@LETSCOOKTECH

Copy link
Copy Markdown
Contributor

Description

Briefly describe the purpose of this PR and what problem it solves.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality or a statutory document archetype)
  • 🎨 UI / Styling polish (Arctic Aurora design system tokens)
  • 📝 Documentation update (README, Guides, Architectural specs)
  • ⚡ Performance optimization / local SQLite speedup

Checklist

  • My code follows the code style and guidelines of this project (npm run typecheck passes).
  • All financial and tax calculations use BigInt minor units without floating-point math.
  • I have added tests that prove my fix is effective or that my feature works (npm test passes).
  • Any UI additions comply with the Arctic Aurora Monochrome theme tokens.

LETSCOOKTECH added 3 commits November 6, 2026 15:03
…, webhooks, and PIN security

- Credential Security: Revoke and eliminate hardcoded Groq key; enforce strict client BYOK and offline heuristic execution; add automated secret scanner regression guard
- CI Portability: Eliminate machine-specific artifact paths; add portable PDF binaries in tests/fixtures/pdf/; run Jest in-band to eliminate worker IPC BigInt serialization crashes
- Cloud Synchronization: Disallow anonymous token bearer authentication and mock user fallbacks; enforce JWT session verification; add strict SQL column allowlists and safe timestamp-based LWW upsert; add cloud sync tables with RLS in cloud/schema.sql
- Payment Webhooks: Add atomic stored procedure process_payment_webhook with ON CONFLICT deduplication; verify HMAC-SHA256 signatures with constant-time equality and database error bubbling
- PIN & Local Data Security: Replace Math.random with cryptographically secure PRNG salt generation (32 bytes / 64 hex chars); implement constant-time comparison and 30-second brute-force lockout after 5 consecutive failures
- Documentation: Update README.md and SECURITY.md with security trust boundaries and BYOK instructions
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T10:30:16.311830Z 5823e0f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5823e0f6b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cloud/schema.sql

RETURN jsonb_build_object('success', TRUE, 'status', 'processed', 'event_id', p_event_id);
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict webhook RPC execution to the service role

On a standard Supabase deployment, PostgreSQL grants new functions EXECUTE privileges to PUBLIC by default. This SECURITY DEFINER function has no caller authorization or signature validation, and repository-wide inspection found no corresponding privilege revocation. A client can therefore call /rest/v1/rpc/process_payment_webhook directly with an arbitrary signature and payment-link ID, insert an event marked verified, and mark another tenant's payment request paid while bypassing RLS and the edge function's HMAC check. Revoke execution from PUBLIC and client roles and grant it only to the service role used by the webhook.

Useful? React with 👍 / 👎.

Comment on lines +47 to +51
documents: new Set([
'id', 'business_id', 'customer_id', 'doc_type', 'document_number', 'issue_date',
'due_date', 'status', 'currency', 'subtotal_minor', 'tax_total_minor',
'discount_total_minor', 'grand_total_minor', 'balance_due_minor', 'notes',
'terms', 'payment_details', 'created_at', 'updated_at'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Match synchronization allowlists to the actual SQLite schema

When pulling records produced by another Billframe device, these allowlists strip real persisted columns instead of just unknown fields. For example, documents requires business_profile_id, but this list permits business_id instead, so inserting a new remote document fails with NOT NULL constraint failed: documents.business_profile_id (reproduced against src/data/database/schema.ts). The payments list likewise drops required invoice_id, while profile, customer, and catalog lists silently discard addresses, banking details, tax rates, and other real fields. Align all allowlists with the local schema so authenticated synchronization can restore complete records.

Useful? React with 👍 / 👎.

Comment on lines +92 to +93
if (!config.authToken || !config.userId) {
return {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Provide an authentication flow before requiring a session token

For users configuring cloud sync through the app, this guard now rejects every synchronization attempt: src/app/settings/cloud-sync.tsx only saves the project URL, anon key, and optional user ID, never authToken. Repository-wide searches for token writes and authentication handlers found no production sign-in flow or other caller that populates the newly introduced token key. Keep the authenticated-session requirement, but wire up a way to obtain and persist that session; otherwise the error asks users to log in through a flow that does not exist.

Useful? React with 👍 / 👎.

Comment on lines +200 to +203
const existingRow: any = await db.getFirstAsync(
`SELECT ${mapping.pk}, updated_at FROM ${mapping.local} WHERE ${mapping.pk} = ?;`,
[pkVal]
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle document items without an updated_at column

Whenever the pull contains a document item, this unconditional lookup fails before either insertion or update because document_items has no updated_at column in the SQLite schema or migrations. Executing the query against the repository schema produces no such column: updated_at. The surrounding table-level catch then abandons the remaining item rows, so line items cannot be downloaded even after the allowlists are corrected. Use a table-specific conflict strategy or add and populate the timestamp through a migration.

Useful? React with 👍 / 👎.

Comment on lines +231 to +233
} else {
await this.recordFailedAttempt();
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Count complete PIN submissions rather than partial prefixes

For a six-digit PIN, LockChallengeScreen.handleKeyPress calls verification after digits four, five, and six, so this new counter records three failures for one incorrect entry. After one wrong six-digit entry, typing the correct PIN reaches the five-failure lockout at its fifth digit and clears the input before the sixth digit can be entered. Since expiration does not reset the failure counter, subsequent attempts lock out again at the fourth digit, preventing the owner from unlocking even with the correct PIN. Count only completed submissions, or make automatic verification aware of the configured PIN length.

Useful? React with 👍 / 👎.

@LETSCOOKTECH
LETSCOOKTECH merged commit e2b95fa into main Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant