From 26f2095de61103e854ef95326b6e0570b2494879 Mon Sep 17 00:00:00 2001 From: Gergo Moricz Date: Tue, 10 Sep 2024 09:24:23 +0200 Subject: [PATCH 1/2] fix(v1): proper Invalid URL handling --- apps/api/src/controllers/v1/types.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts index 63ec1dd4..f812f981 100644 --- a/apps/api/src/controllers/v1/types.ts +++ b/apps/api/src/controllers/v1/types.ts @@ -30,7 +30,14 @@ export const url = z.preprocess( "URL must have a valid top-level domain or be a valid path" ) .refine( - (x) => checkUrl(x as string), + (x) => { + try { + checkUrl(x as string) + return true; + } catch (_) { + return false; + } + }, "Invalid URL" ) .refine( From b4dbf7553750a54040ff47fea9042d2858aaa9cd Mon Sep 17 00:00:00 2001 From: Gergo Moricz Date: Tue, 10 Sep 2024 10:25:14 +0200 Subject: [PATCH 2/2] fix(v1): check if url is string in blocklistMiddleware Fixes FIRECRAWL-SCRAPER-JS-9Z --- apps/api/src/routes/v1.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/routes/v1.ts b/apps/api/src/routes/v1.ts index daa9bf43..484ab5dc 100644 --- a/apps/api/src/routes/v1.ts +++ b/apps/api/src/routes/v1.ts @@ -83,7 +83,7 @@ function idempotencyMiddleware(req: Request, res: Response, next: NextFunction) } function blocklistMiddleware(req: Request, res: Response, next: NextFunction) { - if (req.body.url && isUrlBlocked(req.body.url)) { + if (typeof req.body.url === "string" && isUrlBlocked(req.body.url)) { if (!res.headersSent) { return res.status(403).json({ success: false, error: "URL is blocked. Firecrawl currently does not support social media scraping due to policy restrictions." }); }