fix: return 400 for invalid protocols and unresolvable hostnames (was 500)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m41s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 9m41s
This commit is contained in:
parent
5ec8c92413
commit
b07b9cfd25
3 changed files with 3 additions and 3 deletions
|
|
@ -136,7 +136,7 @@ playgroundRouter.post("/", playgroundLimiter, async (req, res) => {
|
|||
res.status(504).json({ error: "Screenshot timed out." });
|
||||
return;
|
||||
}
|
||||
if (err.message.includes("blocked") || err.message.includes("not allowed") || err.message.includes("Invalid URL")) {
|
||||
if (err.message.includes("blocked") || err.message.includes("not allowed") || err.message.includes("Invalid URL") || err.message.includes("Could not resolve")) {
|
||||
res.status(400).json({ error: err.message });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ async function handleScreenshotRequest(req: any, res: any) {
|
|||
res.status(504).json({ error: "Screenshot timed out. The page may be too slow to load." });
|
||||
return;
|
||||
}
|
||||
if (err.message.includes("blocked") || err.message.includes("not allowed") || err.message.includes("Invalid URL")) {
|
||||
if (err.message.includes("blocked") || err.message.includes("not allowed") || err.message.includes("Invalid URL") || err.message.includes("Could not resolve")) {
|
||||
res.status(400).json({ error: err.message });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export async function validateUrl(urlStr: string): Promise<{ hostname: string; r
|
|||
}
|
||||
|
||||
if (!["http:", "https:"].includes(parsed.protocol)) {
|
||||
throw new Error("Only HTTP and HTTPS URLs are allowed");
|
||||
throw new Error("URL protocol not allowed: only HTTP and HTTPS are supported");
|
||||
}
|
||||
|
||||
const hostname = parsed.hostname;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue