mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
5c5fa4f27e
Select default command-safety rules from the live session shell so legal PowerShell subexpressions are allowed and PowerShell-native dangerous commands are blocked. Untouched pre-shell-aware lists gain the new defaults on read. Closes #3256
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { migrateLegacyCommandBlocklist } from '../../domain/commandBlocklist';
|
|
import { DEFAULT_COMMAND_BLOCKLIST } from '../../infrastructure/ai/types';
|
|
import { STORAGE_KEY_AI_COMMAND_BLOCKLIST } from '../../infrastructure/config/storageKeys';
|
|
import { localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
|
|
|
|
export function persistCommandBlocklistSetting(blocklist: string[]): boolean {
|
|
return localStorageAdapter.write(STORAGE_KEY_AI_COMMAND_BLOCKLIST, blocklist);
|
|
}
|
|
|
|
export function readCommandBlocklistSetting(): string[] {
|
|
const stored = localStorageAdapter.read<string[]>(STORAGE_KEY_AI_COMMAND_BLOCKLIST);
|
|
if (stored != null && !Array.isArray(stored)) {
|
|
return [...DEFAULT_COMMAND_BLOCKLIST];
|
|
}
|
|
|
|
const current = stored ?? [...DEFAULT_COMMAND_BLOCKLIST];
|
|
const migrated = stored == null ? current : migrateLegacyCommandBlocklist(current);
|
|
if (
|
|
stored == null
|
|
|| migrated.length !== current.length
|
|
|| migrated.some((pattern, index) => pattern !== current[index])
|
|
) {
|
|
persistCommandBlocklistSetting(migrated);
|
|
}
|
|
return migrated;
|
|
}
|