From dcfb76966f15ef3857f63ab458ae751d865844fb Mon Sep 17 00:00:00 2001 From: Bradley Axen Date: Fri, 24 Jan 2025 18:14:06 -0800 Subject: [PATCH] feat: allowlist commands (#767) --- ui/desktop/src/extensions.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/desktop/src/extensions.ts b/ui/desktop/src/extensions.ts index a73237b4..64757463 100644 --- a/ui/desktop/src/extensions.ts +++ b/ui/desktop/src/extensions.ts @@ -265,7 +265,17 @@ export async function addExtensionFromDeepLink(url: string, navigate: NavigateFu throw new Error("Missing required 'cmd' parameter in the URL"); } + // Validate that the command is one of the allowed commands + const allowedCommands = ['npx', 'uvx', 'goosed']; + if (!allowedCommands.includes(cmd)) { + throw new Error(`Invalid command: ${cmd}. Only ${allowedCommands.join(', ')} are allowed.`); + } + + // Check for security risk with npx -c command const args = parsedUrl.searchParams.getAll('arg'); + if (cmd === 'npx' && args.includes('-c')) { + throw new Error('Error: npx with -c argument can lead to code injection'); + } const envList = parsedUrl.searchParams.getAll('env'); const id = parsedUrl.searchParams.get('id'); const name = parsedUrl.searchParams.get('name');