mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 19:29:33 +01:00
fix: keep a disabled CLI's keys in the owner env clamp (release review)
ownerClampedEnvKeys() read enabledClis(), so disabling a CLI dropped its privileged keys from the clamp, and a revoked owner got a saved home back on recovery or reboot restore. getCli() still returns a disabled entry, and a session can outlive the switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
db5222c4fa
commit
4513ef6ebb
2 files changed
+38
-2
No files matched your search
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
import { canUsernameRunPrivilegedCommands } from './user-store.js';
|
||||
import { enabledClis } from './config/cli-registry/registry.js';
|
||||
import { listClis } from './config/cli-registry/registry.js';
|
||||
|
||||
/**
|
||||
* Env-var keys a non-granted owner must not be able to set, because each one
|
||||
@@ -68,7 +68,8 @@ import { enabledClis } from './config/cli-registry/registry.js';
|
||||
* already allowlisted for pi and not addressed here — see resolveOmpHome()).
|
||||
*/
|
||||
export function ownerClampedEnvKeys(): string[] {
|
||||
return enabledClis().flatMap((entry) => entry.capabilities.privilegedEnvKeys);
|
||||
// Every CLI, enabled or not: a session can outlive the switch that disabled its CLI.
|
||||
return listClis().flatMap((entry) => entry.capabilities.privilegedEnvKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @fileoverview The env clamp's key list, read from the registry. A key stays clamped while
|
||||
* its CLI is disabled: a session can outlive the switch (the reboot-restore route and the
|
||||
* custom-model recovery both clamp for one that already exists), and neither the clear
|
||||
* branch of the custom-model route nor `restartCli()` checks `enabled`.
|
||||
*
|
||||
* Port: N/A (the on-disk `clis.json` uses the per-file temp HOME from test/setup.ts).
|
||||
*/
|
||||
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { dirname } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { reloadCliRegistry, registryFilePath } from '../src/config/cli-registry/registry.js';
|
||||
import { clampEnvOverridesForOwner } from '../src/session-env-clamp.js';
|
||||
|
||||
describe('clampEnvOverridesForOwner: a disabled CLI', () => {
|
||||
const ORIGINAL = process.env.CODEMAN_MULTIUSER;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.CODEMAN_MULTIUSER = '1';
|
||||
mkdirSync(dirname(registryFilePath()), { recursive: true });
|
||||
writeFileSync(registryFilePath(), JSON.stringify({ clis: { deepseek: { enabled: false } } }), { mode: 0o600 });
|
||||
reloadCliRegistry();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (ORIGINAL === undefined) delete process.env.CODEMAN_MULTIUSER;
|
||||
else process.env.CODEMAN_MULTIUSER = ORIGINAL;
|
||||
rmSync(registryFilePath(), { force: true });
|
||||
reloadCliRegistry();
|
||||
});
|
||||
|
||||
it('still strips its privileged keys for a non-granted owner', async () => {
|
||||
expect(await clampEnvOverridesForOwner('nobody', { DSH_HOME: '/own' })).toEqual({});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user