Skip to content

Commit 4eeab66

Browse files
committed
Land rapid7#3497, comma-separated get_cookies
2 parents e5b5439 + 14b1ed5 commit 4eeab66

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/rex/proto/http/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_cookies
6767
cookies = ""
6868
if (self.headers.include?('Set-Cookie'))
6969
set_cookies = self.headers['Set-Cookie']
70-
key_vals = set_cookies.scan(/\s?([^, ;]+?)=([^, ;]*?);/)
70+
key_vals = set_cookies.scan(/\s?([^, ;]+?)=([^, ;]*?)[;,]/)
7171
key_vals.each do |k, v|
7272
# Dont downcase actual cookie name as may be case sensitive
7373
name = k.downcase

spec/lib/rex/proto/http/response_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ def get_cookies_test_one_set_cookie_header
116116
HEREDOC
117117
end
118118

119+
def get_cookies_comma_separated
120+
<<-HEREDOC.gsub(/^ {6}/, '')
121+
HTTP/1.1 200 OK
122+
Expires: Thu, 26 Oct 1978 00:00:00 GMT
123+
Content-Length: 8556
124+
Server: CherryPy/3.1.2
125+
Date: Sun, 06 Jul 2014 20:09:28 GMT
126+
Cache-Control: no-store, max-age=0, no-cache, must-revalidate
127+
Content-Type: text/html;charset=utf-8
128+
Set-Cookie: cval=880350187, session_id_8000=83466b1a1a7a27ce13d35f78155d40ca3a1e7a28; expires=Mon, 07 Jul 2014 20:09:28 GMT; httponly; Path=/, uid=348637C4-9B10-485A-BFA9-5E892432FCFD; expires=Fri, 05-Jul-2019 20:09:28 GMT
129+
130+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
131+
<!--[if lt IE 7]> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.splunk.com/xhtml-extensions/1.0" xml:lang="en" lang="en" class="no-js lt-ie9 lt-ie8 lt-
132+
HEREDOC
133+
end
134+
119135
def cookie_sanity_check(meth)
120136
resp = described_class.new()
121137
resp.parse(self.send meth)
@@ -185,6 +201,18 @@ def cookie_sanity_check(meth)
185201
cookies_array.should include(*expected_cookies)
186202
end
187203

204+
it 'parses comma separated cookies' do
205+
cookies_array = cookie_sanity_check(:get_cookies_comma_separated)
206+
cookies_array.count.should eq(3)
207+
expected_cookies = %w{
208+
cval=880350187
209+
session_id_8000=83466b1a1a7a27ce13d35f78155d40ca3a1e7a28
210+
uid=348637C4-9B10-485A-BFA9-5E892432FCFD
211+
}
212+
expected_cookies.shuffle!
213+
cookies_array.should include(*expected_cookies)
214+
end
215+
188216
end
189217

190218
end

0 commit comments

Comments
 (0)