Skip to content

Commit 1508990

Browse files
authored
fix: Add stricter URL validation to openURLMiddleware (#2697)
1 parent 0262296 commit 1508990

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ async function openURLMiddleware(
3131

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

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+
3447
await open(url);
3548

3649
res.writeHead(200);

0 commit comments

Comments
 (0)