From 29b0c0b8da0f4af04b11997d35ff51daafd9ccce Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:42:35 +0530 Subject: [PATCH] fix(rln-relay): regex pattern match for extended domains (#2444) * fix(rln-relay): regex pattern match for extended domains * fix: enable localhost too --- apps/chat2/config_chat2.nim | 4 ++-- apps/networkmonitor/networkmonitor_config.nim | 4 ++-- apps/wakunode2/external_config.nim | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/chat2/config_chat2.nim b/apps/chat2/config_chat2.nim index a23683e930..c847ed406a 100644 --- a/apps/chat2/config_chat2.nim +++ b/apps/chat2/config_chat2.nim @@ -322,8 +322,8 @@ proc parseCmdArg*(T: type EthRpcUrl, s: string): T = ## https://url:port/path?query ## disallowed patterns: ## any valid/invalid ws or wss url - var httpPattern = re2"^(https?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" - var wsPattern = re2"^(wss?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" + var httpPattern = re2"^(https?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" + var wsPattern = re2"^(wss?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" if regex.match(s, wsPattern): raise newException(ValueError, "Websocket RPC URL is not supported, Please use an HTTP URL") if not regex.match(s, httpPattern): diff --git a/apps/networkmonitor/networkmonitor_config.nim b/apps/networkmonitor/networkmonitor_config.nim index cb06418210..a1c83ba948 100644 --- a/apps/networkmonitor/networkmonitor_config.nim +++ b/apps/networkmonitor/networkmonitor_config.nim @@ -133,8 +133,8 @@ proc parseCmdArg*(T: type EthRpcUrl, s: string): T = ## https://url:port/path?query ## disallowed patterns: ## any valid/invalid ws or wss url - var httpPattern = re2"^(https?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" - var wsPattern = re2"^(wss?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" + var httpPattern = re2"^(https?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" + var wsPattern = re2"^(wss?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" if regex.match(s, wsPattern): echo "here" raise newException(ValueError, "Websocket RPC URL is not supported, Please use an HTTP URL") diff --git a/apps/wakunode2/external_config.nim b/apps/wakunode2/external_config.nim index 82ed60bc81..72bd64a170 100644 --- a/apps/wakunode2/external_config.nim +++ b/apps/wakunode2/external_config.nim @@ -619,8 +619,8 @@ proc parseCmdArg*(T: type EthRpcUrl, s: string): T = ## https://url:port/path?query ## disallowed patterns: ## any valid/invalid ws or wss url - var httpPattern = re2"^(https?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" - var wsPattern = re2"^(wss?:\/\/)(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))" + var httpPattern = re2"^(https?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" + var wsPattern = re2"^(wss?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" if regex.match(s, wsPattern): raise newException(ValueError, "Websocket RPC URL is not supported, Please use an HTTP URL") if not regex.match(s, httpPattern):