From 23457a77c018f8092c0bc8c8edae6ff8e17f3d38 Mon Sep 17 00:00:00 2001 From: sophron Date: Sat, 10 Aug 2013 23:09:16 +0000 Subject: [PATCH] Modifies the cookie header assembling logic to make it more compliant with RFC 6265, Section 4.2.1, which does not allow the trailing semicolon. Patch by nnposter. --- nselib/http.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/nselib/http.lua b/nselib/http.lua index 6128f8788..d518e5d1c 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -894,18 +894,17 @@ end local function buildCookies(cookies, path) local cookie = "" if type(cookies) == 'string' then return cookies end - for i, ck in ipairs(cookies or {}) do - local ckpath = ck["path"] - if not path or not ckpath - or ckpath == path - or ckpath:sub(-1) == "/" and ckpath == path:sub(1, ckpath:len()) - or ckpath .. "/" == path:sub(1, ckpath:len()+1) - then - if i ~= 1 then cookie = cookie .. " " end - cookie = cookie .. ck["name"] .. "=" .. ck["value"] .. ";" + for _, ck in ipairs(cookies or {}) do + local ckpath = ck["path"] + if not path or not ckpath + or ckpath == path + or ckpath:sub(-1) == "/" and ckpath == path:sub(1, ckpath:len()) + or ckpath .. "/" == path:sub(1, ckpath:len()+1) + then + cookie = cookie .. ck["name"] .. "=" .. ck["value"] .. "; " + end end - end - return cookie + return cookie:gsub("; $","") end -- HTTP cache.