From f7f1cba66a33ec996c75485edfe5cf1e9d666ef4 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 24 May 2015 14:49:59 -0700 Subject: [PATCH] Store only cookies having names beginning with X-APPLE-WEB-KB; cache copied request cookies as _cookies rather than mutable reference. --- pyicloud/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyicloud/base.py b/pyicloud/base.py index ba9eae8..5830f0a 100644 --- a/pyicloud/base.py +++ b/pyicloud/base.py @@ -1,3 +1,4 @@ +import copy import uuid import hashlib import json @@ -163,11 +164,17 @@ class PyiCloudService(object): def _update_cookie(self, request): cookiefile = self._get_cookie_path() + # We really only want to keep the cookies having names + # starting with 'X-APPLE-WEB-KB' + for cookie_name, value in request.cookies.items(): + if not cookie_name.startswith('X-APPLE-WEB-KB'): + del request.cookies[cookie_name] + # Save the cookie in a pickle file with open(cookiefile, 'wb') as f: pickle.dump(request.cookies, f) - self._cookies = request.cookies + self._cookies = copy.deepcopy(request.cookies) @property def devices(self):