Repository navigation
security: harden database restore, authentication, and KDS boundaries - #217
Merged
Merged
Conversation
Contributor
Author
|
Follow-up review fixes are now pushed in commit Verified claims before implementing changes:
Added regression coverage for malformed/unknown deletion responses, legacy-FK recovery, read-only backup sources, maintenance-route concurrency, and WebSocket-active KDS conflict refresh. Focused build and tests pass. PR #217 remains ready for review; no merge or release action was taken. |
khaira777
marked this pull request as ready for review
August 6, 2026 04:39
…-2026 # Conflicts: # main/db.ts # main/routes/support-ticket.ts # main/services/cloud-sync.ts
Exclude lock-owning HTTP maintenance routes from the active-request counter so backup, import, download, and initialize handlers do not wait for their own responses. Keep a separate drain waiter queue so pre-existing requests still block maintenance without starving database requests queued behind an active maintenance operation. Add production-stack regression coverage for both the drain and route completion paths.
9 tasks
khaira777
added a commit
that referenced
this pull request
Aug 9, 2026
Fix Windows database durability flushing after the post-merge cross-platform matrix exposed an `EPERM` failure. Root cause: - `syncFile()` opened application-owned database, journal, and backup files with a read-only `r` handle. - Windows rejects `fsyncSync()` on that handle during the pre-migration backup path. Fix: - Open those application-owned durability targets with `r+` before calling `fsyncSync()`. - Preserve the existing fail-closed durability behavior and recovery guarantees. Verification: - `npm run build` - `npm run test:backup` - `npm run test:recovery-cloud` - Electron smoke test - All PR checks passed - Manual Full Cross-Platform Matrix run `31291071323` passed on Windows, Ubuntu, macOS x64, and macOS ARM64 This is the single targeted follow-up to merged PR #217; no unrelated changes are included.
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security hardening: restore, authentication, authorization, and targeted KDS boundaries
Review status
Ready for maintainer review. This PR is open and must not be merged or released until normal CI and maintainer review complete. No production/customer data, credentials, or private repositories were used.
maind6f71b9(chore/code-review-aug-2026)The changes in this PR are security, integrity, privacy, recovery, and compatibility hardening for the reviewed surfaces. No unrelated product behavior or new sector work is being added here.
Scope and findings addressed
Database restore, import, backup, and maintenance
Finding: Restore/import behavior had integrity, cleanup, concurrency, compatibility, and authentication-state risks. These were reproduced or proven with temporary fixtures.
Remediation:
Authentication and session lifecycle
Finding: Logout revocation was process-local, and stale REST/WebSocket work could retain or restore old session state after deactivation, revocation, password/PIN changes, restore, or maintenance.
Remediation:
/api/auth/recover-passwordwhen no owner exists remains an accepted design decision.KDS authorization, consistency, and privacy
Finding: KDS surfaces did not consistently re-check current role/category/station/session state. Restricted users could receive financial, customer, add-on-price, printer, or network metadata. Stale clients could overwrite terminal or concurrently changed statuses.
Remediation:
expected_statusand409conflicts across embedded REST, order-item REST, standalone REST, WebSocket, and frontend mutation paths.countsparity.Station routing and broadcast correctness
Finding: Tableless orders disappeared from station views. Category fallback could duplicate explicitly table-assigned orders across stations. Global broadcast suppression could drop distinct rapid updates, and periodic full snapshots were unnecessarily expensive.
Remediation:
station_assignments_configuredin migration v56 so removing the final assignment remains fail-closed instead of being interpreted as unrestricted access.Cloud Sync deletion and privacy lifecycle
Finding: Cloud deletion could race enqueue, registration, heartbeat, polling, relay, email, diagnostics, support, pairing, cancellation, settings reload, response processing, and restart recovery. Remote deletion could also be accepted before local disabled state was durable.
Remediation:
unknown,rejected, or final status), blocked unresolved deletion states from re-enabling Cloud Sync, and preserved a safe retry/cancel path.approved,completed, anddeletedoutcomes; cancellation clears stale request identifiers and tokens.Compatibility and behavior decisions
Verification evidence
Passed on the current head or isolated equivalent environment:
npm run buildnpm run lint— 0 errors; existing warnings remaingit diff --checkPORT=3011 KDS_PORT=3012 npm test— full suite passed in an isolated port environmentnpm run test:recovery-cloudThe default-port full-suite attempt encountered an already-running local Electron process; rerunning with isolated
PORT=3011 KDS_PORT=3012completed successfully. No process was terminated.Commit-by-commit audit trail
Each commit is intentionally small enough to explain and review independently:
8b46d67— Hardened database restore and maintenance locking.ccbf2ad— Added durable KDS session/logout foundations.12ecfe1— Closed early restore and logout gaps.59b3cc6— Invalidated stale KDS/import sessions.f14e625— Tightened cache/import safety.a9423c3— Closed session and migration gaps.4eaf21c— Added frontend async/session-generation guards.e38fe4a— Enforced category-scoped kitchen access.9df3e8a— Applied category authorization consistently across KDS paths.b71c33c— Hardened KDS payloads and mutations.accbda2— Added restricted item/station projections.f51369b— Closed remaining KDS session/privacy and station/category gaps.02c0bde— Propagated station assignments and protected terminal items.a024936— Preserved restore authentication state and display-only fields.6efc6bf— Reinserted current-only users and hardened fallback behavior.553fba3— Aligned station-filtered counts and REST fallback behavior.da3d7da— Added station/category routing for tableless orders.ec909e8— Reduced redundant periodic KDS refreshes.b5f0149— Closed routing, inactive-station, restore-FK, and REST 403 gaps.b5dac02— Tightened final KDS auth failures and restore/FK identity handling.8f9f4a4— Merged the latestorigin/maininto the review branch.08f03ca— Made KDS routing/broadcasts lossless and strengthened restore schema checks.139f6aa— Removed unused KDS notifier imports.9c08b50— Closed standalone terminal races and filtered station-scoped responses.22439be— Added active-request maintenance gating and exact schema-object validation.f2458a0— Coordinated KDS WebSocket activity with maintenance.6d83ff5— Closed maintenance clients immediately and normalized ownership.a820aa2— Removed the final unused WebSocket import.d68c10b— Reconnected KDS automatically after maintenance.024ee7e— Added prepared/committed journals, outbox recovery, KDS CAS, counts parity, pairing-token invalidation, backpressure protection, and broadcast coalescing.9a61a0d— Closed recovery/outbox edge cases and serialized Cloud Sync database sections.1bcee0b— Hardened journal path/schema validation, stale cleanup, reset durability, and current-outbox preservation.874fee2— Added recovery symlink, journal-name, schema, and durable-directory checks.b0cb907— Added canonical metadata/header checks, critical-table validation, and custom-target protection.3210cb2— Re-read live KDS ACLs and strengthened migration-derived recovery validation.3280927— Closed live-DB sidecar aliases, dangling-journal ordering, strict import schema parsing, and relay maintenance gating.d3677a5— Closed standalone assignment-removal fail-open and dangling-sidecar cleanup gaps.4341411— Added active event-flush waiting, migration-derived recovery schema generation, and canonical metadata/header checks.fd8c007— Closed support/diagnostics flush waiting, malformed station-category fail-open handling, migration-derived schema/FK validation, and journal cleanup gaps.f055382— Persisted station-assignment scope and preserved it through restore.5799074— Made migration v56 idempotent for upgrade-path simulations.a606d2a— Fenced Cloud Sync deletion, restore sources, standalone ACL revalidation, and durable pre-migration backups.ea56ceb— Closed Cloud Sync reload, registration, heartbeat, polling, and flush race windows.4d28bb5— Added tracked cloud-operation draining and no-follow restore-source materialization.1c90935— Added response-body lifetime fencing and transactional embedded KDS ACL revalidation.1d1d7e0— Drained cloud error responses and rechecked standalone KDS roles.8dcfa01— Closed auto-registration retry and late error-continuation races.0081a82— Revalidated restore-source identity, size, mtime, and post-read sidecars.ef2e5ad— Hardened deletion lifecycle state and token staleness checks.cbd2d62— Rechecked KDS token validity during mutation.d3b2e43— Persisted deletion intent before the remote purge.89d7ea1— Added legacy-FK recovery and Cloud deletion regression coverage.be18da7— Added exact legacy-FK baselines, unresolved-deletion blocking, deletion outcomes, settings re-enable guards, and expanded ambiguous-deletion tests.4fe186c— Validated deletion statuses and tracking details, staged restore sources in OS temp space, refreshed KDS state after every CAS conflict, rejected concurrent maintenance routes before auth/DB access, and added focused regression coverage.Sector status and follow-up work
Future sector work starts from the latest
origin/mainon a newchore/audit-sXX-<name>branch. No additional sector findings or unrelated fixes should be added to this PR.Latest focused follow-up
The latest review claims were verified before implementation. Cloud deletion now accepts only known statuses and requires effective tracking identifiers for non-final states; malformed/unknown responses become blocked, retryable local failures. Restore staging no longer requires write access beside the selected backup. KDS refreshes REST state after every
409, including active WebSocket sessions. Concurrent maintenance requests receive503before later authentication or route middleware.Focused checks passed: build, cloud/recovery regression tests, read-only-source production restore, maintenance-lock concurrency, KDS frontend conflict regression, KDS contract, and
git diff --check.Cloud deletion is explicitly included in this PR's reviewed scope because it protects restore/import privacy and deletion-state integrity. Broader integrations/data-egress work remains separate.
Merge-readiness after main drift
origin/mainwas merged into this branch in517c25d, including the latest tax-configuration, support, frontend, printer, and documentation changes from main. The three textual conflicts inmain/db.ts,main/routes/support-ticket.ts, andmain/services/cloud-sync.tswere resolved by preserving both main's current behavior and this PR's restore/KDS/Cloud deletion hardening. No unrelated main changes were reverted. Commitd6f71b9then fixed a pre-merge production deadlock in the maintenance middleware: lock-owning HTTP routes are excluded from the active-request count, and drain waiters are separate from requests queued behind maintenance.Post-merge verification passed:
npm run buildnpm run build:frontendnpm run lint— 0 errors; existing warnings remainPORT=3011 KDS_PORT=3012 npm testnpm run test:backupnpm run test:recovery-cloudgit diff --checkThe worktree is clean and the branch is conflict-free with
origin/main. Independent review also audited migrations and all 15 commits added tomainin the prior three days. Pending follow-ups are tracked in #220. PR #217 remains open and ready for review; no merge or release action has been taken.Maintainer handoff
This PR is finalized for review of the stated scope. Please review the structured remediation and verification evidence above, run CI on the current head, and merge only after normal maintainer approval. No merge, release, or production action has been taken by this change.