Fix(trust) - Disable commands from untrusted directories when useFolderTrust is enabled (#7341)

Co-authored-by: Richie Foreman <richie.foreman@gmail.com>
Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-08-28 17:45:47 -04:00
committed by GitHub
parent fe5bb6694e
commit 10c6af7e49
3 changed files with 68 additions and 0 deletions
@@ -63,8 +63,12 @@ const TomlCommandDefSchema = z.object({
*/
export class FileCommandLoader implements ICommandLoader {
private readonly projectRoot: string;
private readonly folderTrustEnabled: boolean;
private readonly folderTrust: boolean;
constructor(private readonly config: Config | null) {
this.folderTrustEnabled = !!config?.getFolderTrustFeature();
this.folderTrust = !!config?.getFolderTrust();
this.projectRoot = config?.getProjectRoot() || process.cwd();
}
@@ -97,6 +101,10 @@ export class FileCommandLoader implements ICommandLoader {
cwd: dirInfo.path,
});
if (this.folderTrustEnabled && !this.folderTrust) {
return [];
}
const commandPromises = files.map((file) =>
this.parseAndAdaptFile(
path.join(dirInfo.path, file),