From 8515e83671adda522959807e785ce415cfad54b5 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 4 Feb 2020 18:54:20 +0000 Subject: [PATCH] Handle redirect URLs without a host, e.g. https:///path --- nselib/httpspider.lua | 6 ++++-- nselib/url.lua | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nselib/httpspider.lua b/nselib/httpspider.lua index 3dee86f56..000d4d56b 100644 --- a/nselib/httpspider.lua +++ b/nselib/httpspider.lua @@ -445,8 +445,10 @@ URL = { self.file = url.absolute("", self.file) self.path = url.absolute("", self.path) self.dir = self.path:match("^(.+%/)") or "/" - -- TODO: Use public suffix list to extract domain - self.domain= self.host:match("^[^%.]-%.(.*)") + if self.host then + -- TODO: Use public suffix list to extract domain + self.domain= self.host:match("^[^%.]-%.(.*)") + end return true end return false diff --git a/nselib/url.lua b/nselib/url.lua index ea982d298..d915f5ef7 100644 --- a/nselib/url.lua +++ b/nselib/url.lua @@ -222,8 +222,10 @@ function parse(url, default) authority = string.gsub(authority, ":(%d+)$", function(p) parsed.port = tonumber(p); return "" end) if authority ~= "" then parsed.host = authority end - -- TODO: Allow other Unicode encodings - parsed.ascii_host = idna.toASCII(unicode.decode(parsed.host, unicode.utf8_dec)) + if parsed.host then + -- TODO: Allow other Unicode encodings + parsed.ascii_host = idna.toASCII(unicode.decode(parsed.host, unicode.utf8_dec)) + end local userinfo = parsed.userinfo if not userinfo then return parsed end userinfo = string.gsub(userinfo, ":([^:]*)$",