Skip to content

Commit 484e42a

Browse files
committed
fix: Add stricter URL validation to openURLMiddleware
1 parent 3c4df9d commit 484e42a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/cli-server-api/src/openURLMiddleware.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ async function openURLMiddleware(
3131

3232
const {url} = req.body as {url: string};
3333

34-
await open(url);
34+
try {
35+
const parsedUrl = new URL(url);
36+
if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
37+
res.writeHead(400);
38+
res.end('Invalid URL protocol');
39+
return;
40+
}
41+
} catch (error) {
42+
res.writeHead(400);
43+
res.end('Invalid URL format');
44+
return;
45+
}
46+
47+
await open(url, {app: 'browser'});
3548

3649
res.writeHead(200);
3750
res.end();

0 commit comments

Comments
 (0)