fix(storage): retain explicit junction rejection when binding physical data roots

This commit is contained in:
Agent Workbench Dev
2026-10-31 15:11:38 +08:00
parent 85e0f0e5ce
commit 138adcf33f
2 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -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) {
+13
View File
@@ -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);