From 138adcf33fad0eb02cc4684c6eed42ee4b2cb3e2 Mon Sep 17 00:00:00 2001 From: Agent Workbench Dev Date: Sat, 31 Oct 2026 15:11:38 +0800 Subject: [PATCH] fix(storage): retain explicit junction rejection when binding physical data roots --- src/server/store.mjs | 8 +++++++- tests/credential-vault.test.mjs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/server/store.mjs b/src/server/store.mjs index b7897389..23e63061 100644 --- a/src/server/store.mjs +++ b/src/server/store.mjs @@ -97,7 +97,13 @@ export class Store extends EventEmitter { // A retained pre-desktop Store may still name an MSIX-virtualized LocalAppData // directory. Bind new path-scoped services to that same physical directory, // including when SQLite is already open; do not reopen or move its data. - this.directory = fs.realpathSync.native(this.directory); + const resolved = path.resolve(this.directory), parsed = path.parse(resolved); + let current = parsed.root; + for (const component of resolved.slice(parsed.root.length).split(path.sep).filter(Boolean)) { + current = path.join(current, component); + if (fs.lstatSync(current).isSymbolicLink()) throw new Error('任务数据目录不接受符号链接或目录联接。'); + } + this.directory = fs.realpathSync.native(resolved); if (this.storage?.database) { const missing = CORE_KINDS.filter(kind => !this.core?.[kind]); if (missing.length) { diff --git a/tests/credential-vault.test.mjs b/tests/credential-vault.test.mjs index 5645d571..cb5f1cd0 100644 --- a/tests/credential-vault.test.mjs +++ b/tests/credential-vault.test.mjs @@ -25,6 +25,19 @@ test('a Windows virtual data-directory name binds new storage and credentials to assert.equal(fs.existsSync(path.join(physical, 'workbench.sqlite')), true); assert.deepEqual(fs.readdirSync(logical), []); }); +test('physical data-root adoption still rejects explicit junctions at the directory or any ancestor', t => { + const f = fixture(t), direct = path.join(f.root, 'direct-data-link'), parent = path.join(f.root, 'parent-link'); + const target = path.join(f.root, 'parent-target'); fs.mkdirSync(path.join(target, 'data'), { recursive: true }); + fs.symlinkSync(f.data, direct, 'junction'); fs.symlinkSync(target, parent, 'junction'); + const database = f.store.storage.database, original = f.store.directory; + for (const alias of [direct, path.join(parent, 'data')]) { + assert.throws(() => new Store(alias), /符号链接或目录联接/); + f.store.directory = alias; assert.throws(() => f.store.ensureStorage(), /符号链接或目录联接/); + assert.equal(f.store.directory, alias); assert.equal(f.store.storage.database, database); + } + f.store.directory = original; assert.deepEqual(fs.readdirSync(path.join(target, 'data')), []); +}); + test('actual Windows CurrentUser DPAPI roundtrips owned UTF-8 and rejects damaged bytes and wrong entropy', () => { const plain = Buffer.from('自有测试凭据 owned-key-only', 'utf8'), entropy = randomBytes(32), encrypted = protectCredential(plain, entropy); assert.notDeepEqual(encrypted, plain); assert.deepEqual(unprotectCredential(encrypted, entropy), plain);