Skip to content

fix: address P0 critical issues in security, stability, and correctness#116

Open
bohutang wants to merge 2 commits intomainfrom
feat/issue-115
Open

fix: address P0 critical issues in security, stability, and correctness#116
bohutang wants to merge 2 commits intomainfrom
feat/issue-115

Conversation

@bohutang
Copy link
Member

Closes #115

Summary

This PR fixes five confirmed P0 issues identified through static analysis of the codebase.

Changes

1. Missing unhandledRejection handler (index.ts)

Without this handler, unhandled promise rejections silently crash the Electron main process in Node.js 15+. Added a handler that logs the rejection reason.

2. SQLite missing foreign_keys and journal_mode pragmas (database.ts)

SQLite disables foreign key enforcement by default, allowing orphaned records and referential integrity violations. WAL mode also improves concurrent read performance and crash safety. Both pragmas are now set in the constructor.

3. Removed broken transactionAsync (database.ts)

The method wrapped an async function inside a better-sqlite3 synchronous transaction callback. Since better-sqlite3 transactions are synchronous, the transaction committed before the async work completed — making the transaction semantics completely ineffective. The method was unused, so it was removed.

4. Mutex race condition fix (mutex.ts)

The previous implementation used a polling loop (setTimeout(10ms)) to wait for lock release. This has a TOCTOU race: two concurrent callers could both observe the lock as free between the while check and the locks.set call. Replaced with a proper queue-based implementation using promise callbacks — no polling, no race condition, and waiters are notified immediately on release.

5. PID validation before shell interpolation (SessionManager.ts, AbstractExecutor.ts)

parentPid and pid values were interpolated directly into shell command strings (wmic, ps, taskkill) without validation. A non-integer value could inject arbitrary shell commands. Added integer validation (Math.floor + Number.isInteger + > 0) before any shell interpolation.

- Add unhandledRejection handler in index.ts to prevent silent crashes
- Enable SQLite foreign_keys and WAL journal mode for data integrity
- Remove broken transactionAsync that ran async code inside sync transaction
- Fix mutex race condition: replace polling loop with proper queue-based implementation
- Validate PIDs as positive integers before shell interpolation in SessionManager and AbstractExecutor
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.

P0 Improvement Analysis: Identify and prioritize critical issues

1 participant