From 14df205195c1c552938cdcfd2c9b5c3c43b6f316 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Wed, 23 Oct 2024 17:31:47 +0200 Subject: [PATCH] fix(http): separate hostname and port before host checks --- src/lua/zencode_http.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lua/zencode_http.lua b/src/lua/zencode_http.lua index 9df0d90ef..6df98eca7 100644 --- a/src/lua/zencode_http.lua +++ b/src/lua/zencode_http.lua @@ -140,7 +140,12 @@ function is_valid_uri(uri) error("invalid uri, missing scheme in '" .. uri .. "'", 2) end if parsed.authority ~= "" then - local host_error = _is_valid_host(parsed.authority) + local authority_pattern = "^([^:]+):?(%d*)$" + parsed.hostname, parsed.port = parsed.authority:match(authority_pattern) + if parsed.port ~= "" and not tonumber(parsed.port) then + error("invalid port in '" .. parsed.authority .. "'", 2) + end + local host_error = _is_valid_host(parsed.hostname) if host_error then error(host_error, 2) end