Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex r3): only ENOENT means absent — other access() errors fail closed

[._.]/ Adam Eivy6855a66b3fcd
diff --git a/server/services/settings.js b/server/services/settings.js
index 44515aa97d..a603e19d84 100644
--- a/server/services/settings.js
+++ b/server/services/settings.js
@@ -104,8 +104,13 @@ export const readSettingsStrict = async (filePath = SETTINGS_FILE) => {
try {
await access(filePath);
return { present: true, corrupt: true, settings: {} }; // exists but unreadable
- } catch {
- return { present: false, corrupt: false, settings: {} }; // ENOENT — genuinely absent
+ } catch (err) {
+ // Only ENOENT proves the file is genuinely absent (fresh install → auth
+ // off). Any OTHER access() failure — EACCES because the parent directory
+ // lacks search permission, ENOTDIR, EIO — means we could NOT confirm
+ // absence, so it must fail closed (corrupt), not be mistaken for absent.
+ if (err?.code === 'ENOENT') return { present: false, corrupt: false, settings: {} };
+ return { present: true, corrupt: true, settings: {} };
}
}
// Present and read. safeJSONParse returns null for malformed/empty input; a
diff --git a/server/services/settings.test.js b/server/services/settings.test.js
index 2f0cd95257..a307bc04bf 100644
--- a/server/services/settings.test.js
+++ b/server/services/settings.test.js
@@ -545,6 +545,18 @@ describe('settings.js', () => {
expect(res).toEqual({ present: true, corrupt: true, settings: {} });
});
+ it('fails closed when access() errors for a non-ENOENT reason (only ENOENT is absent)', async () => {
+ // A path whose parent component is a FILE, not a directory, makes access()
+ // throw ENOTDIR (not ENOENT) — we cannot confirm the file is absent, so it
+ // must classify as corrupt (fail closed), never as an absent fresh install.
+ const notADir = joinPath(dir, 'iamafile');
+ writeFileSync(notADir, 'x');
+ tryReadFile.mockResolvedValue(null);
+ const res = await readSettingsStrict(joinPath(notADir, 'settings.json'));
+ expect(res.present).toBe(true);
+ expect(res.corrupt).toBe(true);
+ });
+
it('parses a clean settings file', async () => {
tryReadFile.mockResolvedValue(JSON.stringify({ secrets: { auth: { enabled: true, passwordHash: 'h', salt: 's' } } }));
const res = await readSettingsStrict(joinPath(dir, 'settings.json'));