From cd2a82b6c0e814da581f846f11b4db8f8247efbc Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 17 Jul 2026 21:56:31 +0000 Subject: [PATCH] Categorize but don't fetch off-host URLs. Fixes #2238 --- scripts/http-referer-checker.nse | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/http-referer-checker.nse b/scripts/http-referer-checker.nse index 048fdd6b2..6a56423b7 100644 --- a/scripts/http-referer-checker.nse +++ b/scripts/http-referer-checker.nse @@ -33,28 +33,32 @@ portrule = shortport.port_or_service( {80, 443}, {"http", "https"}, "tcp", "open action = function(host, port) + local scripts = {} + local crawler = httpspider.Crawler:new(host, port, '/', { scriptname = SCRIPT_NAME, maxpagecount = 30, maxdepth = -1, - withinhost = 0, - withindomain = 0 + withinhost = true }) - - crawler.options.doscraping = function(url) - if crawler:iswithinhost(url) - and not crawler:isresource(url, "js") - and not crawler:isresource(url, "css") then - return true - end - end - - crawler:set_timeout(10000) - - if (not(crawler)) then + if not crawler then return end - local scripts = {} + crawler.options.withinhost = function(url) + -- Check for cross-domain javascript + if not crawler:iswithindomain(url) and crawler:isresource(url, "js") then + scripts[tostring(url)] = true + end + -- But don't actually fetch it if it's not on the same host + return crawler:iswithinhost(url) + end + + crawler.options.doscraping = function(url) + return (not crawler:isresource(url, "js") + and not crawler:isresource(url, "css")) + end + + crawler:set_timeout(10000) while(true) do @@ -67,10 +71,6 @@ action = function(host, port) end end - if crawler:isresource(r.url, "js") and not crawler:iswithinhost(r.url) then - scripts[tostring(r.url)] = true - end - end if next(scripts) == nil then