Ensure that copied extensions are writable in the user's local directory (#23016)

This commit is contained in:
kevinjwang1
2026-03-19 15:22:08 -07:00
committed by GitHub
parent 98d1bec99f
commit 0e66f545ca
4 changed files with 170 additions and 0 deletions
@@ -1248,11 +1248,32 @@ function filterMcpConfig(original: MCPServerConfig): MCPServerConfig {
return Object.freeze(rest);
}
/**
* Recursively ensures that the owner has write permissions for all files
* and directories within the target path.
*/
async function makeWritableRecursive(targetPath: string): Promise<void> {
const stats = await fs.promises.lstat(targetPath);
if (stats.isDirectory()) {
// Ensure directory is rwx for the owner (0o700)
await fs.promises.chmod(targetPath, stats.mode | 0o700);
const children = await fs.promises.readdir(targetPath);
for (const child of children) {
await makeWritableRecursive(path.join(targetPath, child));
}
} else if (stats.isFile()) {
// Ensure file is rw for the owner (0o600)
await fs.promises.chmod(targetPath, stats.mode | 0o600);
}
}
export async function copyExtension(
source: string,
destination: string,
): Promise<void> {
await fs.promises.cp(source, destination, { recursive: true });
await makeWritableRecursive(destination);
}
function getContextFileNames(config: ExtensionConfig): string[] {