Skip to content

fix: restrict renderer-initiated database restores to Flo-managed backup files - #316

Merged
khaira777 merged 3 commits into
mainfrom
fix/restore-managed-backup-boundary
Aug 15, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fix/restore-managed-backup-boundary

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Close GHSA-wrhr-pjr7-wpj8 by restricting renderer-initiated database restores to Flo-managed backup files so a compromised renderer cannot import an arbitrary database path

What Changed

  • Added isManagedBackupFile in main/db.ts to verify that database restore paths resolve to regular flo-backup-*.db files inside the application's managed backup directory.
  • Updated the restore-backup IPC handler in main/ipc.ts to reject renderer-provided database paths that fail managed backup file validation.
  • Added tests in tests/restore-managed-path.test.ts covering path validation, traversal, and IPC rejection, and added the test suite to package.json under test:backup.

Risk Assessment

✅ Low: The change adds a well-bounded path and filename validation boundary for renderer-provided backup restore paths without altering normal native dialog workflows.

Testing

Exercised isManagedBackupFile and the main process 'restore-backup' IPC handler against external database paths, traversal attempts, symlink escapes, invalid backup filenames, missing paths, and valid Flo-managed backups; all security boundary checks passed and verified that unmanaged paths are rejected with 'Restore source must be a Flo-managed backup file' while valid managed backups proceed to restore. No UI or visual layout changes were involved in this backend/IPC security boundary fix, so evidence is captured via structured execution logs and JSON verification reports.

Evidence: GHSA-wrhr-pjr7-wpj8 restore boundary verification log

=== FLO-POS SECURITY VALIDATION: GHSA-wrhr-pjr7-wpj8 DATABASE RESTORE BOUNDARY === [SETUP] Initialized database and created legitimate backup: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T22-45-49-922Z-5ad5d382.db --- Running Scenario SEC-RESTORE-001: Renderer attempts to restore arbitrary database file outside backups/ directory --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-unauthorized-jSvW7I/injected_rogue_db.db isManagedBackupFile result: false (expected: false) IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"} Status: PASS ✅ --- Running Scenario SEC-RESTORE-002: Renderer attempts path traversal outside backups directory --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/unauthorized.db isManagedBackupFile result: false (expected: false) IPC 'restore-backup' response: {"success":false,"error":"Backup file no longer exists"} Status: PASS ✅ --- Running Scenario SEC-RESTORE-003: Renderer attempts to restore file inside backups/ with unmanaged filename scheme --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/unmanaged_filename.db isManagedBackupFile result: false (expected: false) IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"} Status: PASS ✅ --- Running Scenario SEC-RESTORE-004: Renderer attempts symlink escape pointing from inside backups/ to external path --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-symlink-escape.db isManagedBackupFile result: false (expected: false) IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"} Status: PASS ✅ --- Running Scenario SEC-RESTORE-005: Renderer references non-existent backup file --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T00-00-00-000Z-nonexistent.db isManagedBackupFile result: false (expected: false) IPC 'restore-backup' response: {"success":false,"error":"Backup file no longer exists"} Status: PASS ✅ --- Running Scenario SEC-RESTORE-006: Renderer restores legitimate Flo-managed backup from Backup History --- Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T22-45-49-922Z-5ad5d382.db isManagedBackupFile result: true (expected: true) IPC 'restore-backup' response: {"success":true,"mode":"direct","backupVersion":68,"currentVersion":68,"tablesRestored":40,"message":"Database restored successfully"} Status: PASS ✅ === SUMMARY: All 6 security boundary test scenarios passed successfully. ===

================================================================================
FLO-POS SECURITY VALIDATION: GHSA-wrhr-pjr7-wpj8 DATABASE RESTORE BOUNDARY
================================================================================

[SETUP] Initialized database and created legitimate backup: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T22-45-49-922Z-5ad5d382.db
--- Running Scenario SEC-RESTORE-001: Renderer attempts to restore arbitrary database file outside backups/ directory ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-unauthorized-jSvW7I/injected_rogue_db.db
  isManagedBackupFile result: false (expected: false)
  IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"}
  Status: PASS ✅

--- Running Scenario SEC-RESTORE-002: Renderer attempts path traversal outside backups directory ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/unauthorized.db
  isManagedBackupFile result: false (expected: false)
  IPC 'restore-backup' response: {"success":false,"error":"Backup file no longer exists"}
  Status: PASS ✅

--- Running Scenario SEC-RESTORE-003: Renderer attempts to restore file inside backups/ with unmanaged filename scheme ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/unmanaged_filename.db
  isManagedBackupFile result: false (expected: false)
  IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"}
  Status: PASS ✅

--- Running Scenario SEC-RESTORE-004: Renderer attempts symlink escape pointing from inside backups/ to external path ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-symlink-escape.db
  isManagedBackupFile result: false (expected: false)
  IPC 'restore-backup' response: {"success":false,"error":"Restore source must be a Flo-managed backup file"}
  Status: PASS ✅

--- Running Scenario SEC-RESTORE-005: Renderer references non-existent backup file ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T00-00-00-000Z-nonexistent.db
  isManagedBackupFile result: false (expected: false)
  IPC 'restore-backup' response: {"success":false,"error":"Backup file no longer exists"}
  Status: PASS ✅

--- Running Scenario SEC-RESTORE-006: Renderer restores legitimate Flo-managed backup from Backup History ---
  Target Path: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T22-45-49-922Z-5ad5d382.db
  isManagedBackupFile result: true (expected: true)
  IPC 'restore-backup' response: {"success":true,"mode":"direct","backupVersion":68,"currentVersion":68,"tablesRestored":40,"message":"Database restored successfully"}
  Status: PASS ✅

================================================================================
SUMMARY: All 6 security boundary test scenarios passed successfully.
================================================================================
Evidence: GHSA-wrhr-pjr7-wpj8 restore boundary verification results JSON
{
  "timestamp": "2026-08-15T22:45:50.449Z",
  "results": [
    {
      "scenarioId": "SEC-RESTORE-001",
      "description": "Renderer attempts to restore arbitrary database file outside backups/ directory",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-unauthorized-jSvW7I/injected_rogue_db.db",
      "isManagedBackupFile": false,
      "ipcResponse": {
        "success": false,
        "error": "Restore source must be a Flo-managed backup file"
      },
      "verdict": "PASS"
    },
    {
      "scenarioId": "SEC-RESTORE-002",
      "description": "Renderer attempts path traversal outside backups directory",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/unauthorized.db",
      "isManagedBackupFile": false,
      "ipcResponse": {
        "success": false,
        "error": "Backup file no longer exists"
      },
      "verdict": "PASS"
    },
    {
      "scenarioId": "SEC-RESTORE-003",
      "description": "Renderer attempts to restore file inside backups/ with unmanaged filename scheme",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/unmanaged_filename.db",
      "isManagedBackupFile": false,
      "ipcResponse": {
        "success": false,
        "error": "Restore source must be a Flo-managed backup file"
      },
      "verdict": "PASS"
    },
    {
      "scenarioId": "SEC-RESTORE-004",
      "description": "Renderer attempts symlink escape pointing from inside backups/ to external path",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-symlink-escape.db",
      "isManagedBackupFile": false,
      "ipcResponse": {
        "success": false,
        "error": "Restore source must be a Flo-managed backup file"
      },
      "verdict": "PASS"
    },
    {
      "scenarioId": "SEC-RESTORE-005",
      "description": "Renderer references non-existent backup file",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T00-00-00-000Z-nonexistent.db",
      "isManagedBackupFile": false,
      "ipcResponse": {
        "success": false,
        "error": "Backup file no longer exists"
      },
      "verdict": "PASS"
    },
    {
      "scenarioId": "SEC-RESTORE-006",
      "description": "Renderer restores legitimate Flo-managed backup from Backup History",
      "targetPath": "/var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-evidence-restore-asxS9B/backups/flo-backup-2026-08-15T22-45-49-922Z-5ad5d382.db",
      "isManagedBackupFile": true,
      "ipcResponse": {
        "success": true,
        "mode": "direct",
        "backupVersion": 68,
        "currentVersion": 68,
        "tablesRestored": 40,
        "message": "Database restored successfully"
      },
      "verdict": "PASS"
    }
  ]
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • node tests/run-electron-node-test.cjs tests/restore-managed-path.test.ts
  • npm run test:backup
  • node tests/run-electron-node-test.cjs tests/database-tools-api.test.ts
  • node tests/run-electron-node-test.cjs /Users/gurkiratkhaira/.gemini/antigravity-cli/brain/f911b0fc-f1f0-4790-a0a0-e6b2b3368654/scratch/verify-restore-boundary.ts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@khaira777
khaira777 requested a review from itsbkm as a code owner August 15, 2026 22:48
@khaira777
khaira777 merged commit 0e18c5d into main Aug 15, 2026
9 checks passed
@khaira777
khaira777 deleted the fix/restore-managed-backup-boundary branch August 15, 2026 23:17
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