Skip to content

fix(db): keep a read-only database read-only - #547

Open
kevintseng wants to merge 2 commits into
mainfrom
fix/readonly-db-stays-readonly
Open

kevintseng wants to merge 2 commits into
mainfrom
fix/readonly-db-stays-readonly

Conversation

@kevintseng

@kevintseng kevintseng commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Refs #520.

Opening a database you made read-only (for example chmod 444 on a snapshot or backup) no longer makes it writable. memesh set the database file, its -wal/-shm files and its folder to fixed modes (600/700) on every open, which gave the owner back the write permission, so every later hook, CLI or MCP process wrote into it. It now only removes access for other users and leaves the owner's permissions as they are. A world-readable database is still tightened to owner-only.

A database whose folder is also read-only cannot be opened (a WAL database needs to create its -shm file), so it is now refused with an error instead of being made writable.

Tests

New tests/db-readonly-mode.test.ts: a 444 database stays non-writable across two opens, a 644 database is still tightened to 600, and a read-only database in a read-only folder is refused with nothing made writable. The first two fail on the previous code. npm run verify: green.

Opening the database set its file mode to 600, which gave the owner
back the write permission on a database made read-only, so every later
process wrote into it. Only access for other users is removed now; the
owner's permissions are left as they are.

Closes #520
A WAL database cannot be read without creating its -shm file, so a
database in a folder the owner made read-only is refused with an error;
opening it used to work only by making the folder writable again.

This branch has not been deployed

No deployments
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