Bug 1554377 - Cleanup nsCookie implementation - network_cookie_thirdparty_nonsecureSessionOnly to StaticPrefs, r=Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D32615

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-31 09:32:33 +00:00
parent 1040f3de6a
commit fd927a96aa
6 changed files with 30 additions and 46 deletions

View File

@ -5725,6 +5725,13 @@ VARCACHE_PREF(
bool, false bool, false
) )
VARCACHE_PREF(
Live,
"network.cookie.thirdparty.nonsecureSessionOnly",
network_cookie_thirdparty_nonsecureSessionOnly,
bool, false
)
// Enables the predictive service. // Enables the predictive service.
VARCACHE_PREF( VARCACHE_PREF(
Live, Live,

View File

@ -2327,7 +2327,6 @@ pref("network.proxy.no_proxies_on", "");
pref("network.proxy.allow_hijacking_localhost", false); pref("network.proxy.allow_hijacking_localhost", false);
pref("network.proxy.failover_timeout", 1800); // 30 minutes pref("network.proxy.failover_timeout", 1800); // 30 minutes
pref("network.online", true); //online/offline pref("network.online", true); //online/offline
pref("network.cookie.thirdparty.nonsecureSessionOnly", false);
// The interval in seconds to move the cookies in the child process. // The interval in seconds to move the cookies in the child process.
// Set to 0 to disable moving the cookies. // Set to 0 to disable moving the cookies.

View File

@ -37,8 +37,6 @@ namespace mozilla {
namespace net { namespace net {
// Pref string constants // Pref string constants
static const char kPrefThirdPartyNonsecureSession[] =
"network.cookie.thirdparty.nonsecureSessionOnly";
static const char kCookieMoveIntervalSecs[] = static const char kCookieMoveIntervalSecs[] =
"network.cookie.move.interval_sec"; "network.cookie.move.interval_sec";
@ -57,8 +55,7 @@ already_AddRefed<CookieServiceChild> CookieServiceChild::GetSingleton() {
NS_IMPL_ISUPPORTS(CookieServiceChild, nsICookieService, nsIObserver, NS_IMPL_ISUPPORTS(CookieServiceChild, nsICookieService, nsIObserver,
nsITimerCallback, nsISupportsWeakReference) nsITimerCallback, nsISupportsWeakReference)
CookieServiceChild::CookieServiceChild() CookieServiceChild::CookieServiceChild() : mIPCOpen(false) {
: mThirdPartyNonsecureSession(false), mIPCOpen(false) {
NS_ASSERTION(IsNeckoChild(), "not a child process"); NS_ASSERTION(IsNeckoChild(), "not a child process");
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild* cc =
@ -87,7 +84,6 @@ CookieServiceChild::CookieServiceChild()
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_WARNING_ASSERTION(prefBranch, "no prefservice"); NS_WARNING_ASSERTION(prefBranch, "no prefservice");
if (prefBranch) { if (prefBranch) {
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
prefBranch->AddObserver(kCookieMoveIntervalSecs, this, true); prefBranch->AddObserver(kCookieMoveIntervalSecs, this, true);
PrefChanged(prefBranch); PrefChanged(prefBranch);
} }
@ -250,11 +246,6 @@ mozilla::ipc::IPCResult CookieServiceChild::RecvTrackCookiesLoad(
} }
void CookieServiceChild::PrefChanged(nsIPrefBranch* aPrefBranch) { void CookieServiceChild::PrefChanged(nsIPrefBranch* aPrefBranch) {
bool boolval;
if (NS_SUCCEEDED(
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
mThirdPartyNonsecureSession = boolval;
int32_t val; int32_t val;
if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookieMoveIntervalSecs, &val))) { if (NS_SUCCEEDED(aPrefBranch->GetIntPref(kCookieMoveIntervalSecs, &val))) {
gMoveCookiesIntervalSeconds = clamped<uint32_t>(val, 0, 3600); gMoveCookiesIntervalSeconds = clamped<uint32_t>(val, 0, 3600);
@ -314,8 +305,8 @@ void CookieServiceChild::GetCookieStringFromCookieHashTable(
nsCookieService::GetCookieSettings(aChannel); nsCookieService::GetCookieSettings(aChannel);
CookieStatus cookieStatus = nsCookieService::CheckPrefs( CookieStatus cookieStatus = nsCookieService::CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign, cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aIsTrackingResource, aFirstPartyStorageAccessGranted, nullptr, aFirstPartyStorageAccessGranted, nullptr,
CountCookiesFromHashTable(baseDomain, attrs), attrs, &aRejectedReason); CountCookiesFromHashTable(baseDomain, attrs), attrs, &aRejectedReason);
if (cookieStatus != STATUS_ACCEPTED && if (cookieStatus != STATUS_ACCEPTED &&
@ -419,7 +410,7 @@ bool CookieServiceChild::RequireThirdPartyCheck(nsILoadInfo* aLoadInfo) {
cookieBehavior == cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN || nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ||
StaticPrefs::network_cookie_thirdparty_sessionOnly() || StaticPrefs::network_cookie_thirdparty_sessionOnly() ||
mThirdPartyNonsecureSession; StaticPrefs::network_cookie_thirdparty_nonsecureSessionOnly();
} }
void CookieServiceChild::RecordDocumentCookie(nsCookie* aCookie, void CookieServiceChild::RecordDocumentCookie(nsCookie* aCookie,
@ -588,8 +579,8 @@ nsresult CookieServiceChild::SetCookieStringInternal(nsIURI* aHostURI,
nsCookieService::GetCookieSettings(aChannel); nsCookieService::GetCookieSettings(aChannel);
CookieStatus cookieStatus = nsCookieService::CheckPrefs( CookieStatus cookieStatus = nsCookieService::CheckPrefs(
cookieSettings, mThirdPartyNonsecureSession, aHostURI, isForeign, cookieSettings, aHostURI, isForeign, isTrackingResource,
isTrackingResource, firstPartyStorageAccessGranted, aCookieString, firstPartyStorageAccessGranted, aCookieString,
CountCookiesFromHashTable(baseDomain, attrs), attrs, &rejectedReason); CountCookiesFromHashTable(baseDomain, attrs), attrs, &rejectedReason);
if (cookieStatus != STATUS_ACCEPTED && if (cookieStatus != STATUS_ACCEPTED &&

View File

@ -104,7 +104,6 @@ class CookieServiceChild : public PCookieServiceChild,
nsCOMPtr<nsITimer> mCookieTimer; nsCOMPtr<nsITimer> mCookieTimer;
nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil; nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
nsCOMPtr<nsIEffectiveTLDService> mTLDService; nsCOMPtr<nsIEffectiveTLDService> mTLDService;
bool mThirdPartyNonsecureSession;
bool mIPCOpen; bool mIPCOpen;
}; };

View File

@ -130,8 +130,6 @@ static const char kPrefMaxNumberOfCookies[] = "network.cookie.maxNumber";
static const char kPrefMaxCookiesPerHost[] = "network.cookie.maxPerHost"; static const char kPrefMaxCookiesPerHost[] = "network.cookie.maxPerHost";
static const char kPrefCookieQuotaPerHost[] = "network.cookie.quotaPerHost"; static const char kPrefCookieQuotaPerHost[] = "network.cookie.quotaPerHost";
static const char kPrefCookiePurgeAge[] = "network.cookie.purgeAge"; static const char kPrefCookiePurgeAge[] = "network.cookie.purgeAge";
static const char kPrefThirdPartyNonsecureSession[] =
"network.cookie.thirdparty.nonsecureSessionOnly";
static void bindCookieParameters(mozIStorageBindingParamsArray* aParamsArray, static void bindCookieParameters(mozIStorageBindingParamsArray* aParamsArray,
const nsCookieKey& aKey, const nsCookieKey& aKey,
@ -584,7 +582,6 @@ NS_IMPL_ISUPPORTS(nsCookieService, nsICookieService, nsICookieManager,
nsCookieService::nsCookieService() nsCookieService::nsCookieService()
: mDBState(nullptr), : mDBState(nullptr),
mThirdPartyNonsecureSession(false),
mMaxNumberOfCookies(kMaxNumberOfCookies), mMaxNumberOfCookies(kMaxNumberOfCookies),
mMaxCookiesPerHost(kMaxCookiesPerHost), mMaxCookiesPerHost(kMaxCookiesPerHost),
mCookieQuotaPerHost(kCookieQuotaPerHost), mCookieQuotaPerHost(kCookieQuotaPerHost),
@ -611,7 +608,6 @@ nsresult nsCookieService::Init() {
prefBranch->AddObserver(kPrefMaxNumberOfCookies, this, true); prefBranch->AddObserver(kPrefMaxNumberOfCookies, this, true);
prefBranch->AddObserver(kPrefMaxCookiesPerHost, this, true); prefBranch->AddObserver(kPrefMaxCookiesPerHost, this, true);
prefBranch->AddObserver(kPrefCookiePurgeAge, this, true); prefBranch->AddObserver(kPrefCookiePurgeAge, this, true);
prefBranch->AddObserver(kPrefThirdPartyNonsecureSession, this, true);
PrefChanged(prefBranch); PrefChanged(prefBranch);
} }
@ -2172,10 +2168,10 @@ void nsCookieService::SetCookieStringInternal(
nsAutoCString hostFromURI; nsAutoCString hostFromURI;
aHostURI->GetHost(hostFromURI); aHostURI->GetHost(hostFromURI);
CountCookiesFromHost(hostFromURI, &priorCookieCount); CountCookiesFromHost(hostFromURI, &priorCookieCount);
CookieStatus cookieStatus = CheckPrefs( CookieStatus cookieStatus =
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign, CheckPrefs(cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aIsTrackingResource, aFirstPartyStorageAccessGranted, aCookieHeader.get(), aFirstPartyStorageAccessGranted, aCookieHeader.get(),
priorCookieCount, aOriginAttrs, &rejectedReason); priorCookieCount, aOriginAttrs, &rejectedReason);
MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED); MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED);
@ -2344,11 +2340,6 @@ void nsCookieService::PrefChanged(nsIPrefBranch* aPrefBranch) {
mCookiePurgeAge = mCookiePurgeAge =
int64_t(LIMIT(val, 0, INT32_MAX, INT32_MAX)) * PR_USEC_PER_SEC; int64_t(LIMIT(val, 0, INT32_MAX, INT32_MAX)) * PR_USEC_PER_SEC;
} }
bool boolval;
if (NS_SUCCEEDED(
aPrefBranch->GetBoolPref(kPrefThirdPartyNonsecureSession, &boolval)))
mThirdPartyNonsecureSession = boolval;
} }
/****************************************************************************** /******************************************************************************
@ -2996,10 +2987,10 @@ void nsCookieService::GetCookiesForURI(
uint32_t rejectedReason = aRejectedReason; uint32_t rejectedReason = aRejectedReason;
uint32_t priorCookieCount = 0; uint32_t priorCookieCount = 0;
CountCookiesFromHost(hostFromURI, &priorCookieCount); CountCookiesFromHost(hostFromURI, &priorCookieCount);
CookieStatus cookieStatus = CheckPrefs( CookieStatus cookieStatus =
cookieSettings, mThirdPartyNonsecureSession, aHostURI, aIsForeign, CheckPrefs(cookieSettings, aHostURI, aIsForeign, aIsTrackingResource,
aIsTrackingResource, aFirstPartyStorageAccessGranted, nullptr, aFirstPartyStorageAccessGranted, nullptr, priorCookieCount,
priorCookieCount, aOriginAttrs, &rejectedReason); aOriginAttrs, &rejectedReason);
MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED); MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED);
@ -3931,11 +3922,10 @@ static inline bool IsSubdomainOf(const nsCString& a, const nsCString& b) {
} }
CookieStatus nsCookieService::CheckPrefs( CookieStatus nsCookieService::CheckPrefs(
nsICookieSettings* aCookieSettings, bool aThirdPartyNonsecureSession, nsICookieSettings* aCookieSettings, nsIURI* aHostURI, bool aIsForeign,
nsIURI* aHostURI, bool aIsForeign, bool aIsTrackingResource, bool aIsTrackingResource, bool aFirstPartyStorageAccessGranted,
bool aFirstPartyStorageAccessGranted, const char* aCookieHeader, const char* aCookieHeader, const int aNumOfCookies,
const int aNumOfCookies, const OriginAttributes& aOriginAttrs, const OriginAttributes& aOriginAttrs, uint32_t* aRejectedReason) {
uint32_t* aRejectedReason) {
nsresult rv; nsresult rv;
MOZ_ASSERT(aRejectedReason); MOZ_ASSERT(aRejectedReason);
@ -4034,7 +4024,7 @@ CookieStatus nsCookieService::CheckPrefs(
return STATUS_ACCEPT_SESSION; return STATUS_ACCEPT_SESSION;
} }
if (aThirdPartyNonsecureSession) { if (StaticPrefs::network_cookie_thirdparty_nonsecureSessionOnly()) {
bool isHTTPS = false; bool isHTTPS = false;
aHostURI->SchemeIs("https", &isHTTPS); aHostURI->SchemeIs("https", &isHTTPS);
if (!isHTTPS) return STATUS_ACCEPT_SESSION; if (!isHTTPS) return STATUS_ACCEPT_SESSION;

View File

@ -213,11 +213,10 @@ class nsCookieService final : public nsICookieService,
nsIChannel* aChannel, bool& aSetCookie, nsIChannel* aChannel, bool& aSetCookie,
mozIThirdPartyUtil* aThirdPartyUtil); mozIThirdPartyUtil* aThirdPartyUtil);
static CookieStatus CheckPrefs( static CookieStatus CheckPrefs(
nsICookieSettings* aCookieSettings, bool aThirdPartyNonsecureSession, nsICookieSettings* aCookieSettings, nsIURI* aHostURI, bool aIsForeign,
nsIURI* aHostURI, bool aIsForeign, bool aIsTrackingResource, bool aIsTrackingResource, bool aIsFirstPartyStorageAccessGranted,
bool aIsFirstPartyStorageAccessGranted, const char* aCookieHeader, const char* aCookieHeader, const int aNumOfCookies,
const int aNumOfCookies, const OriginAttributes& aOriginAttrs, const OriginAttributes& aOriginAttrs, uint32_t* aRejectedReason);
uint32_t* aRejectedReason);
static int64_t ParseServerTime(const nsCString& aServerTime); static int64_t ParseServerTime(const nsCString& aServerTime);
static already_AddRefed<nsICookieSettings> GetCookieSettings( static already_AddRefed<nsICookieSettings> GetCookieSettings(
@ -368,7 +367,6 @@ class nsCookieService final : public nsICookieService,
RefPtr<DBState> mDefaultDBState; RefPtr<DBState> mDefaultDBState;
RefPtr<DBState> mPrivateDBState; RefPtr<DBState> mPrivateDBState;
bool mThirdPartyNonsecureSession;
uint16_t mMaxNumberOfCookies; uint16_t mMaxNumberOfCookies;
uint16_t mMaxCookiesPerHost; uint16_t mMaxCookiesPerHost;
uint16_t mCookieQuotaPerHost; uint16_t mCookieQuotaPerHost;