Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1.1 --- a/netwerk/cookie/CookieServiceParent.cpp Wed Dec 31 06:55:50 2014 +0100 1.2 +++ b/netwerk/cookie/CookieServiceParent.cpp Wed Dec 31 07:22:50 2014 +0100 1.3 @@ -89,8 +89,11 @@ 1.4 return false; 1.5 } 1.6 1.7 + // Method is called nowhere 1.8 + nsAutoCString origDomain; 1.9 mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId, 1.10 - isInBrowserElement, isPrivate, *aResult); 1.11 + isInBrowserElement, isPrivate, 1.12 + origDomain, *aResult); 1.13 return true; 1.14 } 1.15
2.1 --- a/netwerk/cookie/nsCookie.cpp Wed Dec 31 06:55:50 2014 +0100 2.2 +++ b/netwerk/cookie/nsCookie.cpp Wed Dec 31 07:22:50 2014 +0100 2.3 @@ -19,10 +19,12 @@ 2.4 const nsACString &aSource2, 2.5 const nsACString &aSource3, 2.6 const nsACString &aSource4, 2.7 + const nsACString &aSource5, 2.8 char *&aDest1, 2.9 char *&aDest2, 2.10 char *&aDest3, 2.11 char *&aDest4, 2.12 + char *&aDest5, 2.13 char *&aDestEnd) 2.14 { 2.15 char *toBegin = aDest1; 2.16 @@ -35,6 +37,8 @@ 2.17 *copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0); 2.18 aDest4 = ++toBegin; 2.19 *copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0); 2.20 + aDest5 = ++toBegin; 2.21 + *copy_string(aSource5.BeginReading(fromBegin), aSource5.EndReading(fromEnd), toBegin) = char(0); 2.22 aDestEnd = toBegin; 2.23 } 2.24 2.25 @@ -70,6 +74,7 @@ 2.26 nsCookie::Create(const nsACString &aName, 2.27 const nsACString &aValue, 2.28 const nsACString &aHost, 2.29 + const nsACString &aOrigin, 2.30 const nsACString &aPath, 2.31 int64_t aExpiry, 2.32 int64_t aLastAccessed, 2.33 @@ -84,9 +89,10 @@ 2.34 nsAutoCString aUTF8Value; 2.35 converter.ConvertStringToUTF8(aValue, "UTF-8", false, true, 1, aUTF8Value); 2.36 2.37 - // find the required string buffer size, adding 4 for the terminating nulls 2.38 + // find the required string buffer size, accommodating terminating nulls 2.39 const uint32_t stringLength = aName.Length() + aUTF8Value.Length() + 2.40 - aHost.Length() + aPath.Length() + 4; 2.41 + aHost.Length() + aOrigin.Length() + 2.42 + aPath.Length() + 5; 2.43 2.44 // allocate contiguous space for the nsCookie and its strings - 2.45 // we store the strings in-line with the nsCookie to save allocations 2.46 @@ -95,10 +101,10 @@ 2.47 return nullptr; 2.48 2.49 // assign string members 2.50 - char *name, *value, *host, *path, *end; 2.51 + char *name, *value, *host, *origin, *path, *end; 2.52 name = static_cast<char *>(place) + sizeof(nsCookie); 2.53 - StrBlockCopy(aName, aUTF8Value, aHost, aPath, 2.54 - name, value, host, path, end); 2.55 + StrBlockCopy(aName, aUTF8Value, aHost, aOrigin, aPath, 2.56 + name, value, host, origin, path, end); 2.57 2.58 // If the creationTime given to us is higher than the running maximum, update 2.59 // our maximum. 2.60 @@ -106,7 +112,7 @@ 2.61 gLastCreationTime = aCreationTime; 2.62 2.63 // construct the cookie. placement new, oh yeah! 2.64 - return new (place) nsCookie(name, value, host, path, end, 2.65 + return new (place) nsCookie(name, value, host, origin, path, end, 2.66 aExpiry, aLastAccessed, aCreationTime, 2.67 aIsSession, aIsSecure, aIsHttpOnly); 2.68 } 2.69 @@ -127,6 +133,7 @@ 2.70 // xpcom getters 2.71 NS_IMETHODIMP nsCookie::GetName(nsACString &aName) { aName = Name(); return NS_OK; } 2.72 NS_IMETHODIMP nsCookie::GetValue(nsACString &aValue) { aValue = Value(); return NS_OK; } 2.73 +NS_IMETHODIMP nsCookie::GetOrigin(nsACString &aOrigin) { aOrigin = Origin(); return NS_OK; } 2.74 NS_IMETHODIMP nsCookie::GetHost(nsACString &aHost) { aHost = Host(); return NS_OK; } 2.75 NS_IMETHODIMP nsCookie::GetRawHost(nsACString &aHost) { aHost = RawHost(); return NS_OK; } 2.76 NS_IMETHODIMP nsCookie::GetPath(nsACString &aPath) { aPath = Path(); return NS_OK; }
3.1 --- a/netwerk/cookie/nsCookie.h Wed Dec 31 06:55:50 2014 +0100 3.2 +++ b/netwerk/cookie/nsCookie.h Wed Dec 31 07:22:50 2014 +0100 3.3 @@ -36,6 +36,7 @@ 3.4 nsCookie(const char *aName, 3.5 const char *aValue, 3.6 const char *aHost, 3.7 + const char *aOrigin, 3.8 const char *aPath, 3.9 const char *aEnd, 3.10 int64_t aExpiry, 3.11 @@ -47,6 +48,7 @@ 3.12 : mName(aName) 3.13 , mValue(aValue) 3.14 , mHost(aHost) 3.15 + , mOrigin(aOrigin) 3.16 , mPath(aPath) 3.17 , mEnd(aEnd) 3.18 , mExpiry(aExpiry) 3.19 @@ -68,6 +70,7 @@ 3.20 static nsCookie * Create(const nsACString &aName, 3.21 const nsACString &aValue, 3.22 const nsACString &aHost, 3.23 + const nsACString &aOrigin, 3.24 const nsACString &aPath, 3.25 int64_t aExpiry, 3.26 int64_t aLastAccessed, 3.27 @@ -83,8 +86,9 @@ 3.28 // fast (inline, non-xpcom) getters 3.29 inline const nsDependentCString Name() const { return nsDependentCString(mName, mValue - 1); } 3.30 inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); } 3.31 - inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); } 3.32 - inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); } 3.33 + inline const nsDependentCString Host() const { return nsDependentCString(mHost, mOrigin - 1); } 3.34 + inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mOrigin - 1); } 3.35 + inline const nsDependentCString Origin() const { return nsDependentCString(mOrigin, mPath - 1); } 3.36 inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); } 3.37 inline int64_t Expiry() const { return mExpiry; } // in seconds 3.38 inline int64_t LastAccessed() const { return mLastAccessed; } // in microseconds 3.39 @@ -113,6 +117,7 @@ 3.40 const char *mName; 3.41 const char *mValue; 3.42 const char *mHost; 3.43 + const char *mOrigin; 3.44 const char *mPath; 3.45 const char *mEnd; 3.46 int64_t mExpiry;
4.1 --- a/netwerk/cookie/nsCookieService.cpp Wed Dec 31 06:55:50 2014 +0100 4.2 +++ b/netwerk/cookie/nsCookieService.cpp Wed Dec 31 07:22:50 2014 +0100 4.3 @@ -262,6 +262,7 @@ 4.4 PR_LOG(GetCookieLog(), PR_LOG_DEBUG,("name: %s\n", aCookie->Name().get())); 4.5 PR_LOG(GetCookieLog(), PR_LOG_DEBUG,("value: %s\n", aCookie->Value().get())); 4.6 PR_LOG(GetCookieLog(), PR_LOG_DEBUG,("%s: %s\n", aCookie->IsDomain() ? "domain" : "host", aCookie->Host().get())); 4.7 + PR_LOG(GetCookieLog(), PR_LOG_DEBUG,("orighost: %s\n", aCookie->Origin().get())); 4.8 PR_LOG(GetCookieLog(), PR_LOG_DEBUG,("path: %s\n", aCookie->Path().get())); 4.9 4.10 PR_ExplodeTime(aCookie->Expiry() * int64_t(PR_USEC_PER_SEC), 4.11 @@ -1634,9 +1635,19 @@ 4.12 4.13 bool isPrivate = aChannel && NS_UsePrivateBrowsing(aChannel); 4.14 4.15 + nsCOMPtr<nsIURI> firstPartyURI; 4.16 + mThirdPartyUtil->GetFirstPartyURI(aChannel, nullptr, getter_AddRefs(firstPartyURI)); 4.17 + bool requireHostMatch; 4.18 + nsAutoCString origDomain; 4.19 + nsresult rv = GetBaseDomain(firstPartyURI, origDomain, requireHostMatch); 4.20 + if (NS_FAILED(rv)) { 4.21 + COOKIE_LOGFAILURE(GET_COOKIE, aHostURI, nullptr, 4.22 + "couldn't get base domain from URI"); 4.23 + } 4.24 + 4.25 nsAutoCString result; 4.26 GetCookieStringInternal(aHostURI, isForeign, aHttpBound, appId, 4.27 - inBrowserElement, isPrivate, result); 4.28 + inBrowserElement, isPrivate, origDomain, result); 4.29 *aCookie = result.IsEmpty() ? nullptr : ToNewCString(result); 4.30 return NS_OK; 4.31 } 4.32 @@ -1716,6 +1727,10 @@ 4.33 return NS_OK; 4.34 } 4.35 4.36 +// FIXME:MSvB DEBUG DEBUG - DELETEME DELETEME - debug debug - deleteme deleteme 4.37 +// FIXME:MSvB Setting a 3rd party cookie (on third.tld) for URL bar browsed 4.38 +// FIXME:MSvB site first.tld causes aHostURI (and later the origin var) to 4.39 +// FIXME:MSvB contain 'third.tld' 4.40 void 4.41 nsCookieService::SetCookieStringInternal(nsIURI *aHostURI, 4.42 bool aIsForeign, 4.43 @@ -1792,9 +1807,20 @@ 4.44 serverTime = PR_Now() / PR_USEC_PER_SEC; 4.45 } 4.46 4.47 + // double keyed cookie boilerplate 4.48 + nsCOMPtr<nsIURI> firstPartyURI; 4.49 + mThirdPartyUtil->GetFirstPartyURI(aChannel, nullptr, getter_AddRefs(firstPartyURI)); 4.50 + nsAutoCString origDomain; 4.51 + rv = GetBaseDomain(firstPartyURI, origDomain, requireHostMatch); 4.52 + if (NS_FAILED(rv)) { 4.53 + COOKIE_LOGFAILURE(GET_COOKIE, aHostURI, nullptr, 4.54 + "couldn't get base domain from URI"); 4.55 + } 4.56 + 4.57 // process each cookie in the header 4.58 - while (SetCookieInternal(aHostURI, key, requireHostMatch, cookieStatus, 4.59 - aCookieHeader, serverTime, aFromHttp, aChannel)) { 4.60 + while (SetCookieInternal(aHostURI, key, requireHostMatch, origDomain, 4.61 + cookieStatus, aCookieHeader, serverTime, 4.62 + aFromHttp, aChannel)) { 4.63 // document.cookie can only set one cookie at a time 4.64 if (!aFromHttp) 4.65 break; 4.66 @@ -2026,7 +2052,7 @@ 4.67 int64_t currentTimeInUsec = PR_Now(); 4.68 4.69 nsRefPtr<nsCookie> cookie = 4.70 - nsCookie::Create(aName, aValue, host, aPath, 4.71 + nsCookie::Create(aName, aValue, host, baseDomain, aPath, 4.72 aExpiry, 4.73 currentTimeInUsec, 4.74 nsCookie::GenerateUniqueCreationTime(currentTimeInUsec), 4.75 @@ -2064,6 +2090,7 @@ 4.76 nsListIter matchIter; 4.77 nsRefPtr<nsCookie> cookie; 4.78 if (FindCookie(nsCookieKey(baseDomain, aAppId, aInBrowserElement), 4.79 + baseDomain, 4.80 host, 4.81 PromiseFlatCString(aName), 4.82 PromiseFlatCString(aPath), 4.83 @@ -2191,8 +2218,12 @@ 4.84 bool isSecure = 0 != aRow->AsInt32(IDX_SECURE); 4.85 bool isHttpOnly = 0 != aRow->AsInt32(IDX_HTTPONLY); 4.86 4.87 + nsAutoCString baseDomain; 4.88 + rv = GetBaseDomainFromHost(host, baseDomain); 4.89 + NS_ASSERT_SUCCESS(rv); 4.90 + 4.91 // Create a new nsCookie and assign the data. 4.92 - return nsCookie::Create(name, value, host, path, 4.93 + return nsCookie::Create(name, value, host, baseDomain, path, 4.94 expiry, 4.95 lastAccessed, 4.96 creationTime, 4.97 @@ -2579,6 +2610,7 @@ 4.98 nsCookie::Create(Substring(buffer, nameIndex, cookieIndex - nameIndex - 1), 4.99 Substring(buffer, cookieIndex, buffer.Length() - cookieIndex), 4.100 host, 4.101 + baseDomain, 4.102 Substring(buffer, pathIndex, secureIndex - pathIndex - 1), 4.103 expires, 4.104 lastAccessedCounter, 4.105 @@ -2664,6 +2696,7 @@ 4.106 uint32_t aAppId, 4.107 bool aInBrowserElement, 4.108 bool aIsPrivate, 4.109 + nsCString &aOrigDomain, 4.110 nsCString &aCookieString) 4.111 { 4.112 NS_ASSERTION(aHostURI, "null host!"); 4.113 @@ -2732,6 +2765,13 @@ 4.114 for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ++i) { 4.115 cookie = cookies[i]; 4.116 4.117 + // Check the origin key. We only continue if the 4.118 + // saved origin matches matches the origin domain. 4.119 + // FIXME:MSvB, other places iterate cookies too, handle them likewise? 4.120 + if (cookie->Origin() != aOrigDomain) { 4.121 + continue; 4.122 + } 4.123 + 4.124 // check the host, since the base domain lookup is conservative. 4.125 // first, check for an exact host or domain cookie match, e.g. "google.com" 4.126 // or ".google.com"; second a subdomain match, e.g. 4.127 @@ -2854,6 +2894,7 @@ 4.128 nsCookieService::SetCookieInternal(nsIURI *aHostURI, 4.129 const nsCookieKey &aKey, 4.130 bool aRequireHostMatch, 4.131 + const nsCString &aOrigin, 4.132 CookieStatus aStatus, 4.133 nsDependentCString &aCookieHeader, 4.134 int64_t aServerTime, 4.135 @@ -2910,10 +2951,13 @@ 4.136 } 4.137 4.138 // create a new nsCookie and copy attributes 4.139 +//FIXME:MSvB, The name and value vars are neither host nor key 4.140 +//FIXME:MSvB, host shows up in cookie inspector, as a index key 4.141 nsRefPtr<nsCookie> cookie = 4.142 nsCookie::Create(cookieAttributes.name, 4.143 cookieAttributes.value, 4.144 cookieAttributes.host, 4.145 + aOrigin, 4.146 cookieAttributes.path, 4.147 cookieAttributes.expiryTime, 4.148 currentTimeInUsec, 4.149 @@ -2975,8 +3019,8 @@ 4.150 } 4.151 4.152 nsListIter matchIter; 4.153 - bool foundCookie = FindCookie(aKey, aCookie->Host(), 4.154 - aCookie->Name(), aCookie->Path(), matchIter); 4.155 + bool foundCookie = FindCookie(aKey, aCookie->Origin(), 4.156 + aCookie->Host(), aCookie->Name(), aCookie->Path(), matchIter); 4.157 4.158 nsRefPtr<nsCookie> oldCookie; 4.159 nsCOMPtr<nsIArray> purgedList; 4.160 @@ -3885,9 +3929,11 @@ 4.161 return NS_ERROR_NOT_AVAILABLE; 4.162 } 4.163 4.164 - nsAutoCString host, name, path; 4.165 + nsAutoCString host, origin, name, path; 4.166 nsresult rv = aCookie->GetHost(host); 4.167 NS_ENSURE_SUCCESS(rv, rv); 4.168 + rv = aCookie->GetOrigin(origin); 4.169 + NS_ENSURE_SUCCESS(rv, rv); 4.170 rv = aCookie->GetName(name); 4.171 NS_ENSURE_SUCCESS(rv, rv); 4.172 rv = aCookie->GetPath(path); 4.173 @@ -3898,7 +3944,7 @@ 4.174 NS_ENSURE_SUCCESS(rv, rv); 4.175 4.176 nsListIter iter; 4.177 - *aFoundCookie = FindCookie(DEFAULT_APP_KEY(baseDomain), host, name, path, iter); 4.178 + *aFoundCookie = FindCookie(DEFAULT_APP_KEY(baseDomain), origin, host, name, path, iter); 4.179 return NS_OK; 4.180 } 4.181 4.182 @@ -4105,6 +4151,7 @@ 4.183 // find an exact cookie specified by host, name, and path that hasn't expired. 4.184 bool 4.185 nsCookieService::FindCookie(const nsCookieKey &aKey, 4.186 + const nsAFlatCString &aOrigin, 4.187 const nsAFlatCString &aHost, 4.188 const nsAFlatCString &aName, 4.189 const nsAFlatCString &aPath, 4.190 @@ -4120,7 +4167,8 @@ 4.191 for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ++i) { 4.192 nsCookie *cookie = cookies[i]; 4.193 4.194 - if (aHost.Equals(cookie->Host()) && 4.195 + if (aOrigin.Equals(cookie->Origin()) && 4.196 + aHost.Equals(cookie->Host()) && 4.197 aPath.Equals(cookie->Path()) && 4.198 aName.Equals(cookie->Name())) { 4.199 aIter = nsListIter(entry, i);
5.1 --- a/netwerk/cookie/nsCookieService.h Wed Dec 31 06:55:50 2014 +0100 5.2 +++ b/netwerk/cookie/nsCookieService.h Wed Dec 31 07:22:50 2014 +0100 5.3 @@ -289,10 +289,10 @@ 5.4 nsresult GetBaseDomain(nsIURI *aHostURI, nsCString &aBaseDomain, bool &aRequireHostMatch); 5.5 nsresult GetBaseDomainFromHost(const nsACString &aHost, nsCString &aBaseDomain); 5.6 nsresult GetCookieStringCommon(nsIURI *aHostURI, nsIChannel *aChannel, bool aHttpBound, char** aCookie); 5.7 - void GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, bool aHttpBound, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate, nsCString &aCookie); 5.8 + void GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, bool aHttpBound, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate, nsCString &aOrigin, nsCString &aCookie); 5.9 nsresult SetCookieStringCommon(nsIURI *aHostURI, const char *aCookieHeader, const char *aServerTime, nsIChannel *aChannel, bool aFromHttp); 5.10 void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, nsDependentCString &aCookieHeader, const nsCString &aServerTime, bool aFromHttp, uint32_t aAppId, bool aInBrowserElement, bool aIsPrivate, nsIChannel* aChannel); 5.11 - bool SetCookieInternal(nsIURI *aHostURI, const nsCookieKey& aKey, bool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp, nsIChannel* aChannel); 5.12 + bool SetCookieInternal(nsIURI *aHostURI, const nsCookieKey& aKey, bool aRequireHostMatch, const nsCString &aOrigin, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp, nsIChannel* aChannel); 5.13 void AddInternal(const nsCookieKey& aKey, nsCookie *aCookie, int64_t aCurrentTimeInUsec, nsIURI *aHostURI, const char *aCookieHeader, bool aFromHttp); 5.14 void RemoveCookieFromList(const nsListIter &aIter, mozIStorageBindingParamsArray *aParamsArray = nullptr); 5.15 void AddCookieToList(const nsCookieKey& aKey, nsCookie *aCookie, DBState *aDBState, mozIStorageBindingParamsArray *aParamsArray, bool aWriteToDB = true); 5.16 @@ -306,7 +306,7 @@ 5.17 static bool GetExpiry(nsCookieAttributes &aCookie, int64_t aServerTime, int64_t aCurrentTime); 5.18 void RemoveAllFromMemory(); 5.19 already_AddRefed<nsIArray> PurgeCookies(int64_t aCurrentTimeInUsec); 5.20 - bool FindCookie(const nsCookieKey& aKey, const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter); 5.21 + bool FindCookie(const nsCookieKey& aKey, const nsAFlatCString &aOrigin, const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter); 5.22 static void FindStaleCookie(nsCookieEntry *aEntry, int64_t aCurrentTime, nsListIter &aIter); 5.23 void NotifyRejected(nsIURI *aHostURI); 5.24 void NotifyThirdParty(nsIURI *aHostURI, bool aAccepted, nsIChannel *aChannel);
6.1 --- a/netwerk/cookie/nsICookie2.idl Wed Dec 31 06:55:50 2014 +0100 6.2 +++ b/netwerk/cookie/nsICookie2.idl Wed Dec 31 07:22:50 2014 +0100 6.3 @@ -11,12 +11,17 @@ 6.4 * access of cookie objects 6.5 */ 6.6 6.7 -[scriptable, uuid(05c420e5-03d0-4c7b-a605-df7ebe5ca326)] 6.8 +[scriptable, uuid(9468A7E6-37B3-43CE-A081-377BC12C5BB7)] 6.9 6.10 interface nsICookie2 : nsICookie 6.11 { 6.12 6.13 /** 6.14 + * the origin key of the cookie. 6.15 + */ 6.16 + readonly attribute ACString origin; 6.17 + 6.18 + /** 6.19 * the host (possibly fully qualified) of the cookie, 6.20 * without a leading dot to represent if it is a 6.21 * domain cookie.