From c9168d4e28e83d7fb6ee58e2481d74cdba506e86 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Fri, 22 Jul 2022 20:35:58 +0300 Subject: [PATCH] fix potential url parser crash --- package.json | 2 +- src/common/http.ts | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bd671dc..62620d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@squeebot/core", - "version": "3.3.6", + "version": "3.3.7", "description": "Squeebot v3 core for the execution environment", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/common/http.ts b/src/common/http.ts index 7a7b5bb..4a30f7f 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -18,7 +18,13 @@ export function httpGET( saveTo?: string, lback?: number ): Promise { - const parsed = new URL(link); + let parsed: URL; + try { + parsed = new URL(link); + } catch (e: any) { + return Promise.reject(e); + } + const opts = { headers: { Accept: '*/*', @@ -113,8 +119,15 @@ export function httpPOST( headers: any = {}, data: any ): Promise { - const parsed = new URL(link); - let postData: string | URLSearchParams = new URLSearchParams(data); + let parsed: URL; + let postData: string | URLSearchParams; + + try { + parsed = new URL(link); + postData = new URLSearchParams(data); + } catch(e: any) { + return Promise.reject(e); + } const opts: RequestOptions = { headers: {