diff --git a/pywb/rewrite/cookie_rewriter.py b/pywb/rewrite/cookie_rewriter.py index c9c7e8b5..78e3c9c6 100644 --- a/pywb/rewrite/cookie_rewriter.py +++ b/pywb/rewrite/cookie_rewriter.py @@ -19,10 +19,14 @@ class WbUrlCookieRewriter(object): return results for name, morsel in cookie.iteritems(): + # if domain set, no choice but to expand cookie path to root if morsel.get('domain'): del morsel['domain'] - if morsel.get('path'): + morsel['path'] = self.url_rewriter.prefix + # else set cookie to rewritten path + elif morsel.get('path'): morsel['path'] = self.url_rewriter.rewrite(morsel['path']) + # remove expires as it refers to archived time if morsel.get('expires'): del morsel['expires'] diff --git a/pywb/rewrite/test/test_cookie_rewriter.py b/pywb/rewrite/test/test_cookie_rewriter.py index bba5c959..e5979fd4 100644 --- a/pywb/rewrite/test/test_cookie_rewriter.py +++ b/pywb/rewrite/test/test_cookie_rewriter.py @@ -3,12 +3,16 @@ r""" >>> rewrite_cookie('a=b; c=d;') [('Set-Cookie', 'a=b'), ('Set-Cookie', 'c=d')] ->>> rewrite_cookie('some=value; Domain=foo.com; Path=/;') +>>> rewrite_cookie('some=value; Path=/;') [('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/')] ->>> rewrite_cookie('some=value; Domain=foo.com; Path=/diff/path/;') +>>> rewrite_cookie('some=value; Path=/diff/path/;') [('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/diff/path/')] +# if domain set, set path to root +>>> rewrite_cookie('some=value; Domain=.example.com; Path=/diff/path/;') +[('Set-Cookie', 'some=value; Path=/pywb/')] + >>> rewrite_cookie('abc=def; Path=file.html; Expires=Wed, 13 Jan 2021 22:23:01 GMT') [('Set-Cookie', 'abc=def; Path=/pywb/20131226101010/http://example.com/some/path/file.html')] diff --git a/pywb/rewrite/test/test_header_rewriter.py b/pywb/rewrite/test/test_header_rewriter.py index de772244..1a2b2cea 100644 --- a/pywb/rewrite/test/test_header_rewriter.py +++ b/pywb/rewrite/test/test_header_rewriter.py @@ -21,7 +21,7 @@ HTTP Headers Rewriting 'text_type': None} # cookie, host/origin rewriting ->>> _test_headers([('Connection', 'close'), ('Set-Cookie', 'foo=bar; Path=/; Domain=.example.com, abc=def; Path=somefile.html'), ('Host', 'example.com'), ('Origin', 'https://example.com')]) +>>> _test_headers([('Connection', 'close'), ('Set-Cookie', 'foo=bar; Path=/; abc=def; Path=somefile.html'), ('Host', 'example.com'), ('Origin', 'https://example.com')]) {'charset': None, 'removed_header_dict': {}, 'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('X-Archive-Orig-Connection', 'close'), @@ -44,7 +44,7 @@ HTTP Headers Rewriting 'text_type': 'js'} # Binary -- transfer-encoding removed ->>> _test_headers([('Content-Length', '200000'), ('Content-Type', 'image/png'), ('Set-Cookie', 'foo=bar; Path=/; Domain=.example.com'), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked')]) +>>> _test_headers([('Content-Length', '200000'), ('Content-Type', 'image/png'), ('Set-Cookie', 'foo=bar; Path=/;'), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked')]) {'charset': None, 'removed_header_dict': {'transfer-encoding': 'chunked'}, 'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('Content-Length', '200000'),