| File: | var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp |
| Warning: | line 825, column 5 Value stored to 'rv' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
| 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | #include "StorageAccess.h" |
| 8 | |
| 9 | #include "mozilla/BasePrincipal.h" |
| 10 | #include "mozilla/Components.h" |
| 11 | #include "mozilla/dom/Document.h" |
| 12 | #include "mozilla/net/CookieJarSettings.h" |
| 13 | #include "mozilla/PermissionManager.h" |
| 14 | #include "mozilla/StaticPrefs_browser.h" |
| 15 | #include "mozilla/StaticPrefs_network.h" |
| 16 | #include "mozilla/StaticPrefs_privacy.h" |
| 17 | #include "mozilla/StorageAccess.h" |
| 18 | #include "nsAboutProtocolUtils.h" |
| 19 | #include "nsContentUtils.h" |
| 20 | #include "nsGlobalWindowInner.h" |
| 21 | #include "nsICookiePermission.h" |
| 22 | #include "nsICookieService.h" |
| 23 | #include "nsICookieJarSettings.h" |
| 24 | #include "nsIHttpChannel.h" |
| 25 | #include "nsIPermission.h" |
| 26 | #include "nsIWebProgressListener.h" |
| 27 | #include "nsIClassifiedChannel.h" |
| 28 | #include "nsNetUtil.h" |
| 29 | #include "nsScriptSecurityManager.h" |
| 30 | #include "nsSandboxFlags.h" |
| 31 | #include "AntiTrackingUtils.h" |
| 32 | #include "AntiTrackingLog.h" |
| 33 | #include "ContentBlockingAllowList.h" |
| 34 | #include "mozIThirdPartyUtil.h" |
| 35 | |
| 36 | using namespace mozilla; |
| 37 | using namespace mozilla::dom; |
| 38 | using mozilla::net::CookieJarSettings; |
| 39 | |
| 40 | // This internal method returns ACCESS_DENY if the access is denied, |
| 41 | // ACCESS_DEFAULT if unknown, some other access code if granted. |
| 42 | uint32_t mozilla::detail::CheckCookiePermissionForPrincipal( |
| 43 | nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal) { |
| 44 | MOZ_ASSERT(aCookieJarSettings)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aCookieJarSettings)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aCookieJarSettings))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aCookieJarSettings" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 44); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCookieJarSettings" ")"); do { *((volatile int*)__null) = 44; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 45 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 45); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 45; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 46 | |
| 47 | uint32_t cookiePermission = nsICookiePermission::ACCESS_DEFAULT; |
| 48 | if (!aPrincipal->GetIsContentPrincipal()) { |
| 49 | return cookiePermission; |
| 50 | } |
| 51 | |
| 52 | nsresult rv = |
| 53 | aCookieJarSettings->CookiePermission(aPrincipal, &cookiePermission); |
| 54 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 54)) { |
| 55 | return nsICookiePermission::ACCESS_DEFAULT; |
| 56 | } |
| 57 | |
| 58 | // If we have a custom cookie permission, let's use it. |
| 59 | return cookiePermission; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Checks if storage for a given principal is permitted by the user's |
| 64 | * preferences. |
| 65 | * |
| 66 | * Ways this function is used: |
| 67 | * - aPrincipal, aWindow, optional aURI, others don't care: does this principal |
| 68 | * have storage access, testing this window's sandboxing and if it is |
| 69 | * third-party. If aURI is provided, we use that for the window's third party |
| 70 | * comparisons. |
| 71 | * - aPrincipal, aChannel, aWindow=nullptr, others don't care: does this |
| 72 | * principal have storage access, testing if this channel is third-party. Note |
| 73 | * that this ignores aURI. |
| 74 | * - aPrincipal, optional aCookieJarSettings, aWindow=nullptr, aChannel=nullptr, |
| 75 | * aURI don't care: does this principal have storage access (assuming it is in a |
| 76 | * first-party context and not sandboxed). If we aren't given a |
| 77 | * cookieJarSettings, we build one with the principal. |
| 78 | * |
| 79 | * In all of these cases, we test: |
| 80 | * - if aPrincipal is a NullPrincipal, denying |
| 81 | * - if this is for an about URI, allowing (maybe with private browsing |
| 82 | * constraints) We test the aWindow's extant doc's URI's, aURI's, and |
| 83 | * aPrincipal's scheme to be "about". |
| 84 | * |
| 85 | * We also send a decision to the ContentBlockingNotifier if we have aWindow or |
| 86 | * aChannel and didn't stop at the NullPrincipal or about: checks. |
| 87 | * |
| 88 | * Used in the implementation of StorageAllowedForWindow, |
| 89 | * StorageAllowedForDocument, StorageAllowedForChannel and |
| 90 | * StorageAllowedForServiceWorker. |
| 91 | */ |
| 92 | static StorageAccess InternalStorageAllowedCheck( |
| 93 | nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aWindow, nsIURI* aURI, |
| 94 | nsIChannel* aChannel, nsICookieJarSettings* aCookieJarSettings, |
| 95 | uint32_t& aRejectedReason) { |
| 96 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 96; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 97 | |
| 98 | aRejectedReason = 0; |
| 99 | |
| 100 | StorageAccess access = StorageAccess::eAllow; |
| 101 | |
| 102 | // We don't allow storage on the null principal, in general. Even if the |
| 103 | // calling context is chrome. |
| 104 | if (aPrincipal->GetIsNullPrincipal()) { |
| 105 | return StorageAccess::eDeny; |
| 106 | } |
| 107 | |
| 108 | nsCOMPtr<nsIURI> documentURI; |
| 109 | if (aWindow) { |
| 110 | // If the document is sandboxed, then it is not permitted to use storage |
| 111 | Document* document = aWindow->GetExtantDoc(); |
| 112 | if (document && document->GetSandboxFlags() & SANDBOXED_ORIGIN) { |
| 113 | return StorageAccess::eDeny; |
| 114 | } |
| 115 | |
| 116 | // Check if we are in private browsing, and record that fact |
| 117 | if (document && document->IsInPrivateBrowsing()) { |
| 118 | access = StorageAccess::ePrivateBrowsing; |
| 119 | } |
| 120 | |
| 121 | // Get the document URI for the below about: URI check. |
| 122 | documentURI = document ? document->GetDocumentURI() : nullptr; |
| 123 | } |
| 124 | |
| 125 | // About URIs are allowed to access storage, even if they don't have chrome |
| 126 | // privileges. If this is not desired, than the consumer will have to |
| 127 | // implement their own restriction functionality. |
| 128 | // |
| 129 | // This is due to backwards-compatibility and the state of storage access |
| 130 | // before the introducton of InternalStorageAllowedCheck: |
| 131 | // |
| 132 | // BEFORE: |
| 133 | // localStorage, caches: allowed in 3rd-party iframes always |
| 134 | // IndexedDB: allowed in 3rd-party iframes only if 3rd party URI is an about: |
| 135 | // URI within a specific allowlist |
| 136 | // |
| 137 | // AFTER: |
| 138 | // localStorage, caches: allowed in 3rd-party iframes by default. Preference |
| 139 | // can be set to disable in 3rd-party, which will not disallow in about: |
| 140 | // URIs. |
| 141 | // IndexedDB: allowed in 3rd-party iframes by default. Preference can be set |
| 142 | // to disable in 3rd-party, which will disallow in about: URIs, unless they |
| 143 | // are within a specific allowlist. |
| 144 | // |
| 145 | // This means that behavior for storage with internal about: URIs should not |
| 146 | // be affected, which is desireable due to the lack of automated testing for |
| 147 | // about: URIs with these preferences set, and the importance of the correct |
| 148 | // functioning of these URIs even with custom preferences. |
| 149 | // |
| 150 | // We need to check the aURI or the document URI here instead of only checking |
| 151 | // the URI from the principal. Because the principal might not have a URI if |
| 152 | // it is a system principal. |
| 153 | if ((aURI && aURI->SchemeIs("about") && |
| 154 | !NS_IsContentAccessibleAboutURI(aURI)) || |
| 155 | (documentURI && documentURI->SchemeIs("about") && |
| 156 | !NS_IsContentAccessibleAboutURI(documentURI)) || |
| 157 | aPrincipal->SchemeIs("about")) { |
| 158 | return access; |
| 159 | } |
| 160 | |
| 161 | bool disabled = true; |
| 162 | if (aWindow) { |
| 163 | nsIURI* documentURI = aURI ? aURI : aWindow->GetDocumentURI(); |
| 164 | disabled = !documentURI || !ShouldAllowAccessFor(aWindow, documentURI, true, |
| 165 | &aRejectedReason); |
| 166 | |
| 167 | // If the window is a third-party tracker, we should set the rejected reason |
| 168 | // to partitioned tracker. |
| 169 | uint32_t rejectedReason = aRejectedReason; |
| 170 | if (aRejectedReason == |
| 171 | static_cast<uint32_t>( |
| 172 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) && |
| 173 | nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow)) { |
| 174 | rejectedReason = |
| 175 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_TRACKER; |
| 176 | } |
| 177 | |
| 178 | ContentBlockingNotifier::OnDecision( |
| 179 | aWindow, |
| 180 | disabled ? ContentBlockingNotifier::BlockingDecision::eBlock |
| 181 | : ContentBlockingNotifier::BlockingDecision::eAllow, |
| 182 | rejectedReason); |
| 183 | } else if (aChannel) { |
| 184 | disabled = false; |
| 185 | nsCOMPtr<nsIURI> uri; |
| 186 | nsresult rv = aChannel->GetURI(getter_AddRefs(uri)); |
| 187 | if (!NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 187)) { |
| 188 | disabled = !ShouldAllowAccessFor(aChannel, uri, &aRejectedReason); |
| 189 | } |
| 190 | |
| 191 | // If the channel is a third-party tracker, we should set the rejected |
| 192 | // reason to partitioned tracker. |
| 193 | uint32_t rejectedReason = aRejectedReason; |
| 194 | nsCOMPtr<nsIClassifiedChannel> classifiedChannel = |
| 195 | do_QueryInterface(aChannel); |
| 196 | |
| 197 | if (classifiedChannel && |
| 198 | classifiedChannel->IsThirdPartyTrackingResource() && |
| 199 | aRejectedReason == |
| 200 | static_cast<uint32_t>( |
| 201 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN)) { |
| 202 | rejectedReason = |
| 203 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_TRACKER; |
| 204 | } |
| 205 | |
| 206 | ContentBlockingNotifier::OnDecision( |
| 207 | aChannel, |
| 208 | disabled ? ContentBlockingNotifier::BlockingDecision::eBlock |
| 209 | : ContentBlockingNotifier::BlockingDecision::eAllow, |
| 210 | rejectedReason); |
| 211 | } else { |
| 212 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 212); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 212; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 213 | nsCOMPtr<nsICookieJarSettings> cookieJarSettings = aCookieJarSettings; |
| 214 | if (!cookieJarSettings) { |
| 215 | cookieJarSettings = net::CookieJarSettings::Create(aPrincipal); |
| 216 | } |
| 217 | disabled = !ShouldAllowAccessFor(aPrincipal, aCookieJarSettings); |
| 218 | } |
| 219 | |
| 220 | if (!disabled) { |
| 221 | return access; |
| 222 | } |
| 223 | |
| 224 | // We want to have a partitioned storage only for trackers. |
| 225 | // XXX: We should probably remove the check here because this was added for |
| 226 | // partitioned tracker only. This was never shipped. |
| 227 | if (aRejectedReason == |
| 228 | static_cast<uint32_t>( |
| 229 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || |
| 230 | aRejectedReason == |
| 231 | static_cast<uint32_t>( |
| 232 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER)) { |
| 233 | return StorageAccess::ePartitionTrackersOrDeny; |
| 234 | } |
| 235 | |
| 236 | // We want to have a partitioned storage for all third parties. |
| 237 | if (aRejectedReason == |
| 238 | static_cast<uint32_t>( |
| 239 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN)) { |
| 240 | return StorageAccess::ePartitionForeignOrDeny; |
| 241 | } |
| 242 | |
| 243 | return StorageAccess::eDeny; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Wrapper around InternalStorageAllowedCheck which caches the check result on |
| 248 | * the inner window to improve performance. nsGlobalWindowInner is responsible |
| 249 | * for invalidating the cache state if storage access changes during window |
| 250 | * lifetime. |
| 251 | */ |
| 252 | static StorageAccess InternalStorageAllowedCheckCached( |
| 253 | nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aWindow, nsIURI* aURI, |
| 254 | nsIChannel* aChannel, nsICookieJarSettings* aCookieJarSettings, |
| 255 | uint32_t& aRejectedReason) { |
| 256 | // If enabled, check if we have already computed the storage access field |
| 257 | // for this window. This avoids repeated calls to |
| 258 | // InternalStorageAllowedCheck. |
| 259 | nsGlobalWindowInner* win = nullptr; |
| 260 | if (aWindow) { |
| 261 | win = nsGlobalWindowInner::Cast(aWindow); |
| 262 | |
| 263 | Maybe<StorageAccess> storageAccess = |
| 264 | win->GetStorageAllowedCache(aRejectedReason); |
| 265 | if (storageAccess.isSome()) { |
| 266 | return storageAccess.value(); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | StorageAccess result = InternalStorageAllowedCheck( |
| 271 | aPrincipal, aWindow, aURI, aChannel, aCookieJarSettings, aRejectedReason); |
| 272 | if (win) { |
| 273 | // Remember check result for the lifetime of the window. It's the windows |
| 274 | // responsibility to invalidate this field if storage access changes |
| 275 | // because a storage access permission is granted. |
| 276 | win->SetStorageAllowedCache(result, aRejectedReason); |
| 277 | } |
| 278 | |
| 279 | return result; |
| 280 | } |
| 281 | |
| 282 | namespace mozilla { |
| 283 | |
| 284 | StorageAccess StorageAllowedForWindow(nsPIDOMWindowInner* aWindow, |
| 285 | uint32_t* aRejectedReason) { |
| 286 | uint32_t rejectedReason; |
| 287 | if (!aRejectedReason) { |
| 288 | aRejectedReason = &rejectedReason; |
| 289 | } |
| 290 | |
| 291 | *aRejectedReason = 0; |
| 292 | |
| 293 | if (Document* document = aWindow->GetExtantDoc()) { |
| 294 | nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal(); |
| 295 | // Note that GetChannel() below may return null, but that's OK, since the |
| 296 | // callee is able to deal with a null channel argument, and if passed |
| 297 | // null, will only fail to notify the UI in case storage gets blocked. |
| 298 | nsIChannel* channel = document->GetChannel(); |
| 299 | return InternalStorageAllowedCheckCached( |
| 300 | principal, aWindow, nullptr, channel, document->CookieJarSettings(), |
| 301 | *aRejectedReason); |
| 302 | } |
| 303 | |
| 304 | // No document? Try checking Private Browsing Mode without document |
| 305 | if (const nsCOMPtr<nsIGlobalObject> global = aWindow->AsGlobal()) { |
| 306 | if (const nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull()) { |
| 307 | if (principal->GetIsInPrivateBrowsing()) { |
| 308 | return StorageAccess::ePrivateBrowsing; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | // Everything failed? Let's return a generic rejected reason. |
| 314 | return StorageAccess::eDeny; |
| 315 | } |
| 316 | |
| 317 | StorageAccess StorageAllowedForDocument(const Document* aDoc) { |
| 318 | StorageAccess cookieAllowed = CookieAllowedForDocument(aDoc); |
| 319 | if (StaticPrefs:: |
| 320 | privacy_partition_always_partition_third_party_non_cookie_storage() && |
| 321 | cookieAllowed > StorageAccess::eDeny) { |
| 322 | return StorageAccess::ePartitionForeignOrDeny; |
| 323 | } |
| 324 | return cookieAllowed; |
| 325 | } |
| 326 | |
| 327 | StorageAccess CookieAllowedForDocument(const Document* aDoc) { |
| 328 | MOZ_ASSERT(aDoc)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aDoc)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aDoc))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("aDoc", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 328); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDoc" ")"); do { *((volatile int*)__null) = 328; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 329 | |
| 330 | if (nsPIDOMWindowInner* inner = aDoc->GetInnerWindow()) { |
| 331 | nsCOMPtr<nsIPrincipal> principal = aDoc->NodePrincipal(); |
| 332 | // Note that GetChannel() below may return null, but that's OK, since the |
| 333 | // callee is able to deal with a null channel argument, and if passed |
| 334 | // null, will only fail to notify the UI in case storage gets blocked. |
| 335 | nsIChannel* channel = aDoc->GetChannel(); |
| 336 | |
| 337 | uint32_t rejectedReason = 0; |
| 338 | return InternalStorageAllowedCheckCached( |
| 339 | principal, inner, nullptr, channel, |
| 340 | const_cast<Document*>(aDoc)->CookieJarSettings(), rejectedReason); |
| 341 | } |
| 342 | |
| 343 | return StorageAccess::eDeny; |
| 344 | } |
| 345 | |
| 346 | StorageAccess StorageAllowedForNewWindow(nsIPrincipal* aPrincipal, nsIURI* aURI, |
| 347 | nsPIDOMWindowInner* aParent) { |
| 348 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 348); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 348; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 349 | MOZ_ASSERT(aURI)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aURI)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aURI))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("aURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 349); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do { *((volatile int*)__null) = 349; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 350 | // parent may be nullptr |
| 351 | |
| 352 | uint32_t rejectedReason = 0; |
| 353 | nsCOMPtr<nsICookieJarSettings> cjs; |
| 354 | if (aParent && aParent->GetExtantDoc()) { |
| 355 | cjs = aParent->GetExtantDoc()->CookieJarSettings(); |
| 356 | } else { |
| 357 | cjs = net::CookieJarSettings::Create(aPrincipal); |
| 358 | } |
| 359 | return InternalStorageAllowedCheck(aPrincipal, aParent, aURI, nullptr, cjs, |
| 360 | rejectedReason); |
| 361 | } |
| 362 | |
| 363 | StorageAccess StorageAllowedForChannel(nsIChannel* aChannel) { |
| 364 | MOZ_DIAGNOSTIC_ASSERT(nsContentUtils::GetSecurityManager())do { static_assert( mozilla::detail::AssertionConditionType< decltype(nsContentUtils::GetSecurityManager())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(nsContentUtils::GetSecurityManager ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("nsContentUtils::GetSecurityManager()", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 364); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "nsContentUtils::GetSecurityManager()" ")"); do { *((volatile int*)__null) = 364; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 365 | MOZ_DIAGNOSTIC_ASSERT(aChannel)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aChannel", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 365); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "aChannel" ")"); do { *((volatile int*)__null) = 365; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 366 | |
| 367 | nsCOMPtr<nsIPrincipal> principal; |
| 368 | Unused << nsContentUtils::GetSecurityManager()->GetChannelResultPrincipal( |
| 369 | aChannel, getter_AddRefs(principal)); |
| 370 | NS_ENSURE_TRUE(principal, StorageAccess::eDeny)do { if ((__builtin_expect(!!(!(principal)), 0))) { NS_DebugBreak (NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "principal" ") failed", nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 370); return StorageAccess::eDeny; } } while (false); |
| 371 | |
| 372 | nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo(); |
| 373 | nsCOMPtr<nsICookieJarSettings> cookieJarSettings; |
| 374 | nsresult rv = |
| 375 | loadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)); |
| 376 | NS_ENSURE_SUCCESS(rv, StorageAccess::eDeny)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "StorageAccess::eDeny", static_cast <uint32_t>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 376); return StorageAccess::eDeny; } } while (false); |
| 377 | |
| 378 | uint32_t rejectedReason = 0; |
| 379 | StorageAccess result = InternalStorageAllowedCheck( |
| 380 | principal, nullptr, nullptr, aChannel, cookieJarSettings, rejectedReason); |
| 381 | |
| 382 | return result; |
| 383 | } |
| 384 | |
| 385 | StorageAccess StorageAllowedForServiceWorker( |
| 386 | nsIPrincipal* aPrincipal, nsICookieJarSettings* aCookieJarSettings) { |
| 387 | uint32_t rejectedReason = 0; |
| 388 | return InternalStorageAllowedCheck(aPrincipal, nullptr, nullptr, nullptr, |
| 389 | aCookieJarSettings, rejectedReason); |
| 390 | } |
| 391 | |
| 392 | bool ShouldPartitionStorage(StorageAccess aAccess) { |
| 393 | return aAccess == StorageAccess::ePartitionTrackersOrDeny || |
| 394 | aAccess == StorageAccess::ePartitionForeignOrDeny; |
| 395 | } |
| 396 | |
| 397 | bool ShouldPartitionStorage(uint32_t aRejectedReason) { |
| 398 | return aRejectedReason == |
| 399 | static_cast<uint32_t>( |
| 400 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || |
| 401 | aRejectedReason == |
| 402 | static_cast<uint32_t>( |
| 403 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) || |
| 404 | aRejectedReason == |
| 405 | static_cast<uint32_t>( |
| 406 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN); |
| 407 | } |
| 408 | |
| 409 | bool StoragePartitioningEnabled(StorageAccess aAccess, |
| 410 | nsICookieJarSettings* aCookieJarSettings) { |
| 411 | return aAccess == StorageAccess::ePartitionForeignOrDeny && |
| 412 | aCookieJarSettings->GetCookieBehavior() == |
| 413 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN; |
| 414 | } |
| 415 | |
| 416 | bool StoragePartitioningEnabled(uint32_t aRejectedReason, |
| 417 | nsICookieJarSettings* aCookieJarSettings) { |
| 418 | return aRejectedReason == |
| 419 | static_cast<uint32_t>( |
| 420 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) && |
| 421 | aCookieJarSettings->GetCookieBehavior() == |
| 422 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN; |
| 423 | } |
| 424 | |
| 425 | int32_t CookiesBehavior(Document* a3rdPartyDocument) { |
| 426 | MOZ_ASSERT(a3rdPartyDocument)do { static_assert( mozilla::detail::AssertionConditionType< decltype(a3rdPartyDocument)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(a3rdPartyDocument))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("a3rdPartyDocument" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 426); AnnotateMozCrashReason("MOZ_ASSERT" "(" "a3rdPartyDocument" ")"); do { *((volatile int*)__null) = 426; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 427 | |
| 428 | // WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior |
| 429 | // (See Bug 1406675 and Bug 1525917 for rationale). |
| 430 | if (BasePrincipal::Cast(a3rdPartyDocument->NodePrincipal())->AddonPolicy()) { |
| 431 | return nsICookieService::BEHAVIOR_ACCEPT; |
| 432 | } |
| 433 | |
| 434 | return a3rdPartyDocument->CookieJarSettings()->GetCookieBehavior(); |
| 435 | } |
| 436 | |
| 437 | bool CookiesBehaviorRejectsThirdPartyContexts(Document* aDocument) { |
| 438 | MOZ_ASSERT(aDocument)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aDocument)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aDocument))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aDocument", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 438); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDocument" ")" ); do { *((volatile int*)__null) = 438; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 439 | |
| 440 | // WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior |
| 441 | // (See Bug 1406675 and Bug 1525917 for rationale). |
| 442 | if (BasePrincipal::Cast(aDocument->NodePrincipal())->AddonPolicy()) { |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | return aDocument->CookieJarSettings()->GetRejectThirdPartyContexts(); |
| 447 | } |
| 448 | |
| 449 | int32_t CookiesBehavior(nsILoadInfo* aLoadInfo, nsIURI* a3rdPartyURI) { |
| 450 | MOZ_ASSERT(aLoadInfo)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aLoadInfo)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aLoadInfo))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aLoadInfo", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 450); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aLoadInfo" ")" ); do { *((volatile int*)__null) = 450; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 451 | MOZ_ASSERT(a3rdPartyURI)do { static_assert( mozilla::detail::AssertionConditionType< decltype(a3rdPartyURI)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(a3rdPartyURI))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("a3rdPartyURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 451); AnnotateMozCrashReason("MOZ_ASSERT" "(" "a3rdPartyURI" ")"); do { *((volatile int*)__null) = 451; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 452 | |
| 453 | // WebExtensions 3rd party URI always get BEHAVIOR_ACCEPT as cookieBehavior, |
| 454 | // this is semantically equivalent to the principal having a AddonPolicy(). |
| 455 | if (a3rdPartyURI->SchemeIs("moz-extension")) { |
| 456 | return nsICookieService::BEHAVIOR_ACCEPT; |
| 457 | } |
| 458 | |
| 459 | nsCOMPtr<nsICookieJarSettings> cookieJarSettings; |
| 460 | nsresult rv = |
| 461 | aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)); |
| 462 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 462)) { |
| 463 | return nsICookieService::BEHAVIOR_REJECT; |
| 464 | } |
| 465 | |
| 466 | return cookieJarSettings->GetCookieBehavior(); |
| 467 | } |
| 468 | |
| 469 | int32_t CookiesBehavior(nsIPrincipal* aPrincipal, |
| 470 | nsICookieJarSettings* aCookieJarSettings) { |
| 471 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 471); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 471; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 472 | MOZ_ASSERT(aCookieJarSettings)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aCookieJarSettings)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aCookieJarSettings))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aCookieJarSettings" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 472); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCookieJarSettings" ")"); do { *((volatile int*)__null) = 472; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 473 | |
| 474 | // WebExtensions principals always get BEHAVIOR_ACCEPT as cookieBehavior |
| 475 | // (See Bug 1406675 for rationale). |
| 476 | if (BasePrincipal::Cast(aPrincipal)->AddonPolicy()) { |
| 477 | return nsICookieService::BEHAVIOR_ACCEPT; |
| 478 | } |
| 479 | |
| 480 | return aCookieJarSettings->GetCookieBehavior(); |
| 481 | } |
| 482 | |
| 483 | bool ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, nsIURI* aURI, |
| 484 | bool aCookies, uint32_t* aRejectedReason) { |
| 485 | MOZ_ASSERT(aWindow)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aWindow)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aWindow))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aWindow", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 485); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aWindow" ")" ); do { *((volatile int*)__null) = 485; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 486 | MOZ_ASSERT(aURI)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aURI)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aURI))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("aURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 486); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do { *((volatile int*)__null) = 486; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 487 | |
| 488 | // Let's avoid a null check on aRejectedReason everywhere else. |
| 489 | uint32_t rejectedReason = 0; |
| 490 | if (!aRejectedReason) { |
| 491 | aRejectedReason = &rejectedReason; |
| 492 | } |
| 493 | |
| 494 | LOG_SPEC(("Computing whether window %p has access to URI %s", aWindow, _spec),do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing whether window %p has access to URI %s" , aWindow, _spec); } } while (0); } } while (0) |
| 495 | aURI)do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing whether window %p has access to URI %s" , aWindow, _spec); } } while (0); } } while (0); |
| 496 | |
| 497 | nsGlobalWindowInner* innerWindow = nsGlobalWindowInner::Cast(aWindow); |
| 498 | Document* document = innerWindow->GetExtantDoc(); |
| 499 | if (!document) { |
| 500 | LOG(("Our window has no document"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our window has no document" ); } } while (0); |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal( |
| 505 | document->CookieJarSettings(), document->NodePrincipal()); |
| 506 | if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { |
| 507 | LOG(do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 508 | ("CheckCookiePermissionForPrincipal() returned a non-default access "do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 509 | "code (%d) for window's principal, returning %s",do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 510 | int(cookiePermission),do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 511 | cookiePermission != nsICookiePermission::ACCESS_DENY ? "success"do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 512 | : "failure"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for window's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0); |
| 513 | if (cookiePermission != nsICookiePermission::ACCESS_DENY) { |
| 514 | return true; |
| 515 | } |
| 516 | |
| 517 | *aRejectedReason = |
| 518 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION; |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | int32_t behavior = CookiesBehavior(document); |
| 523 | if (behavior == nsICookieService::BEHAVIOR_ACCEPT) { |
| 524 | LOG(("The cookie behavior pref mandates accepting all cookies!"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "The cookie behavior pref mandates accepting all cookies!" ); } } while (0); |
| 525 | return true; |
| 526 | } |
| 527 | |
| 528 | if (ContentBlockingAllowList::Check(aWindow)) { |
| 529 | return true; |
| 530 | } |
| 531 | |
| 532 | if (behavior == nsICookieService::BEHAVIOR_REJECT) { |
| 533 | LOG(("The cookie behavior pref mandates rejecting all cookies!"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "The cookie behavior pref mandates rejecting all cookies!" ); } } while (0); |
| 534 | *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL; |
| 535 | return false; |
| 536 | } |
| 537 | |
| 538 | // As a performance optimization, we only perform this check for |
| 539 | // BEHAVIOR_REJECT_FOREIGN and BEHAVIOR_LIMIT_FOREIGN. For |
| 540 | // BEHAVIOR_REJECT_TRACKER and |
| 541 | // BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, third-partiness is |
| 542 | // implicily checked later below. |
| 543 | if (behavior != nsICookieService::BEHAVIOR_REJECT_TRACKER && |
| 544 | behavior != |
| 545 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) { |
| 546 | // Let's check if this is a 3rd party context. |
| 547 | if (!AntiTrackingUtils::IsThirdPartyWindow(aWindow, aURI)) { |
| 548 | LOG(("Our window isn't a third-party window"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our window isn't a third-party window" ); } } while (0); |
| 549 | return true; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | if (behavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN || |
| 554 | behavior == nsICookieService::BEHAVIOR_LIMIT_FOREIGN) { |
| 555 | // XXX For non-cookie forms of storage, we handle BEHAVIOR_LIMIT_FOREIGN |
| 556 | // by simply rejecting the request to use the storage. In the future, if |
| 557 | // we change the meaning of BEHAVIOR_LIMIT_FOREIGN to be one which makes |
| 558 | // sense for non-cookie storage types, this may change. |
| 559 | LOG(("Nothing more to do due to the behavior code %d", int(behavior)))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Nothing more to do due to the behavior code %d" , int(behavior)); } } while (0); |
| 560 | *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN; |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | // The document has been allowlisted. We can return from here directly. |
| 565 | if (document->HasStorageAccessPermissionGrantedByAllowList()) { |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 572; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 570 | behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 572; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 571 | behavior ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 572; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 572 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN)do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 572; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 573 | |
| 574 | uint32_t blockedReason = |
| 575 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER; |
| 576 | |
| 577 | if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) { |
| 578 | if (!nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow)) { |
| 579 | LOG(("Our window isn't a third-party tracking window"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our window isn't a third-party tracking window" ); } } while (0); |
| 580 | return true; |
| 581 | } |
| 582 | |
| 583 | nsCOMPtr<nsIClassifiedChannel> classifiedChannel = |
| 584 | do_QueryInterface(document->GetChannel()); |
| 585 | if (classifiedChannel) { |
| 586 | uint32_t classificationFlags = |
| 587 | classifiedChannel->GetThirdPartyClassificationFlags(); |
| 588 | if (classificationFlags & nsIClassifiedChannel::ClassificationFlags:: |
| 589 | CLASSIFIED_SOCIALTRACKING) { |
| 590 | blockedReason = |
| 591 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER; |
| 592 | } |
| 593 | } |
| 594 | } else if (behavior == |
| 595 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) { |
| 596 | if (nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow)) { |
| 597 | // fall through, but remember that we're partitioned for trackers if |
| 598 | // it's instructed by the pref. |
| 599 | if (!StaticPrefs::network_cookie_cookieBehavior_trackerCookieBlocking()) { |
| 600 | blockedReason = |
| 601 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; |
| 602 | } |
| 603 | } else if (AntiTrackingUtils::IsThirdPartyWindow(aWindow, aURI)) { |
| 604 | LOG(("We're in the third-party context, storage should be partitioned"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "We're in the third-party context, storage should be partitioned" ); } } while (0); |
| 605 | // fall through, but remember that we're partitioning. |
| 606 | blockedReason = nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; |
| 607 | } else { |
| 608 | LOG(("Our window isn't a third-party window, storage is allowed"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our window isn't a third-party window, storage is allowed" ); } } while (0); |
| 609 | return true; |
| 610 | } |
| 611 | } else { |
| 612 | MOZ_ASSERT_UNREACHABLE(do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 614); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 614; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) |
| 613 | "This should be an exhaustive list of cookie behaviors possible "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 614); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 614; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) |
| 614 | "here.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 614); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 614; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); |
| 615 | } |
| 616 | |
| 617 | Document* doc = aWindow->GetExtantDoc(); |
| 618 | // Make sure storage access isn't disabled |
| 619 | if (doc && (doc->StorageAccessSandboxed())) { |
| 620 | LOG(("Our document is sandboxed"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our document is sandboxed" ); } } while (0); |
| 621 | *aRejectedReason = blockedReason; |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | // "Storage access granted" only affects cookie access for third party |
| 626 | // documents. So if we are looking if we should allow access for cookies, |
| 627 | // then test if that permission is enabled on this document. |
| 628 | // Document::UsingStorageAccess first checks if storage access granted is |
| 629 | // cached in the inner window, if no, it then checks the storage permission |
| 630 | // flag in the channel's loadinfo |
| 631 | bool allowed = aCookies && document->UsingStorageAccess(); |
| 632 | |
| 633 | if (!allowed) { |
| 634 | *aRejectedReason = blockedReason; |
| 635 | } else { |
| 636 | if (MOZ_LOG_TEST(gAntiTrackingLog, mozilla::LogLevel::Debug)(__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0)) && |
| 637 | aWindow->UsingStorageAccess()) { |
| 638 | LOG(("Permission stored in the window. All good."))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Permission stored in the window. All good." ); } } while (0); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | return allowed; |
| 643 | } |
| 644 | |
| 645 | bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, |
| 646 | uint32_t* aRejectedReason) { |
| 647 | MOZ_ASSERT(aURI)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aURI)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aURI))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("aURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 647); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do { *((volatile int*)__null) = 647; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 648 | MOZ_ASSERT(aChannel)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aChannel)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aChannel))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aChannel", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 648); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aChannel" ")" ); do { *((volatile int*)__null) = 648; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 649 | |
| 650 | // Let's avoid a null check on aRejectedReason everywhere else. |
| 651 | uint32_t rejectedReason = 0; |
| 652 | if (!aRejectedReason) { |
| 653 | aRejectedReason = &rejectedReason; |
| 654 | } |
| 655 | |
| 656 | nsIScriptSecurityManager* ssm = |
| 657 | nsScriptSecurityManager::GetScriptSecurityManager(); |
| 658 | MOZ_ASSERT(ssm)do { static_assert( mozilla::detail::AssertionConditionType< decltype(ssm)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(ssm))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("ssm", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 658); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ssm" ")"); do { *((volatile int*)__null) = 658; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 659 | |
| 660 | nsCOMPtr<nsIURI> channelURI; |
| 661 | nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI)); |
| 662 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 663 | LOG(("Failed to get the channel final URI, bail out early"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the channel final URI, bail out early" ); } } while (0); |
| 664 | return true; |
| 665 | } |
| 666 | LOG_SPEC(do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (channelURI) { _specStr = (channelURI)->GetSpecOrDefault (); } _specStr.Truncate(std::min(_specStr.Length(), sMaxSpecLength )); const char* _spec = _specStr.get(); do { const ::mozilla:: LogModule* moz_real_module = gAntiTrackingLog; if ((__builtin_expect (!!(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing whether channel %p has access to URI %s" , aChannel, _spec); } } while (0); } } while (0) |
| 667 | ("Computing whether channel %p has access to URI %s", aChannel, _spec),do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (channelURI) { _specStr = (channelURI)->GetSpecOrDefault (); } _specStr.Truncate(std::min(_specStr.Length(), sMaxSpecLength )); const char* _spec = _specStr.get(); do { const ::mozilla:: LogModule* moz_real_module = gAntiTrackingLog; if ((__builtin_expect (!!(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing whether channel %p has access to URI %s" , aChannel, _spec); } } while (0); } } while (0) |
| 668 | channelURI)do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (channelURI) { _specStr = (channelURI)->GetSpecOrDefault (); } _specStr.Truncate(std::min(_specStr.Length(), sMaxSpecLength )); const char* _spec = _specStr.get(); do { const ::mozilla:: LogModule* moz_real_module = gAntiTrackingLog; if ((__builtin_expect (!!(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing whether channel %p has access to URI %s" , aChannel, _spec); } } while (0); } } while (0); |
| 669 | |
| 670 | nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo(); |
| 671 | nsCOMPtr<nsICookieJarSettings> cookieJarSettings; |
| 672 | rv = loadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)); |
| 673 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 673)) { |
| 674 | LOG(do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the cookie jar settings from the loadinfo, bail out " "early"); } } while (0) |
| 675 | ("Failed to get the cookie jar settings from the loadinfo, bail out "do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the cookie jar settings from the loadinfo, bail out " "early"); } } while (0) |
| 676 | "early"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the cookie jar settings from the loadinfo, bail out " "early"); } } while (0); |
| 677 | return true; |
| 678 | } |
| 679 | |
| 680 | nsCOMPtr<nsIPrincipal> channelPrincipal; |
| 681 | rv = ssm->GetChannelURIPrincipal(aChannel, getter_AddRefs(channelPrincipal)); |
| 682 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 682)) { |
| 683 | LOG(("No channel principal, bail out early"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "No channel principal, bail out early" ); } } while (0); |
| 684 | return false; |
| 685 | } |
| 686 | |
| 687 | uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal( |
| 688 | cookieJarSettings, channelPrincipal); |
| 689 | if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { |
| 690 | LOG(do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 691 | ("CheckCookiePermissionForPrincipal() returned a non-default access "do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 692 | "code (%d) for channel's principal, returning %s",do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 693 | int(cookiePermission),do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 694 | cookiePermission != nsICookiePermission::ACCESS_DENY ? "success"do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0) |
| 695 | : "failure"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d) for channel's principal, returning %s", int(cookiePermission ), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure"); } } while (0); |
| 696 | if (cookiePermission != nsICookiePermission::ACCESS_DENY) { |
| 697 | return true; |
| 698 | } |
| 699 | |
| 700 | *aRejectedReason = |
| 701 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION; |
| 702 | return false; |
| 703 | } |
| 704 | |
| 705 | if (!channelURI) { |
| 706 | LOG(("No channel uri, bail out early"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "No channel uri, bail out early" ); } } while (0); |
| 707 | return false; |
| 708 | } |
| 709 | |
| 710 | int32_t behavior = CookiesBehavior(loadInfo, channelURI); |
| 711 | if (behavior == nsICookieService::BEHAVIOR_ACCEPT) { |
| 712 | LOG(("The cookie behavior pref mandates accepting all cookies!"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "The cookie behavior pref mandates accepting all cookies!" ); } } while (0); |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel); |
| 717 | |
| 718 | if (httpChannel && ContentBlockingAllowList::Check(httpChannel)) { |
| 719 | return true; |
| 720 | } |
| 721 | |
| 722 | if (behavior == nsICookieService::BEHAVIOR_REJECT) { |
| 723 | LOG(("The cookie behavior pref mandates rejecting all cookies!"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "The cookie behavior pref mandates rejecting all cookies!" ); } } while (0); |
| 724 | *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL; |
| 725 | return false; |
| 726 | } |
| 727 | |
| 728 | nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = |
| 729 | components::ThirdPartyUtil::Service(); |
| 730 | if (!thirdPartyUtil) { |
| 731 | LOG(("No thirdPartyUtil, bail out early"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "No thirdPartyUtil, bail out early" ); } } while (0); |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | bool thirdParty = false; |
| 736 | rv = thirdPartyUtil->IsThirdPartyChannel(aChannel, aURI, &thirdParty); |
| 737 | // Grant if it's not a 3rd party. |
| 738 | // Be careful to check the return value of IsThirdPartyChannel, since |
| 739 | // IsThirdPartyChannel() will fail if the channel's loading principal is the |
| 740 | // system principal... |
| 741 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && !thirdParty) { |
| 742 | LOG(("Our channel isn't a third-party channel"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our channel isn't a third-party channel" ); } } while (0); |
| 743 | return true; |
| 744 | } |
| 745 | |
| 746 | if (behavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN || |
| 747 | behavior == nsICookieService::BEHAVIOR_LIMIT_FOREIGN) { |
| 748 | // XXX For non-cookie forms of storage, we handle BEHAVIOR_LIMIT_FOREIGN |
| 749 | // by simply rejecting the request to use the storage. In the future, if |
| 750 | // we change the meaning of BEHAVIOR_LIMIT_FOREIGN to be one which makes |
| 751 | // sense for non-cookie storage types, this may change. |
| 752 | LOG(("Nothing more to do due to the behavior code %d", int(behavior)))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Nothing more to do due to the behavior code %d" , int(behavior)); } } while (0); |
| 753 | *aRejectedReason = nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN; |
| 754 | return false; |
| 755 | } |
| 756 | |
| 757 | // The channel has been allowlisted. We can return from here. |
| 758 | if (loadInfo->GetStoragePermission() == |
| 759 | nsILoadInfo::StoragePermissionAllowListed) { |
| 760 | return true; |
| 761 | } |
| 762 | |
| 763 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 766); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 766; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 764 | behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 766); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 766; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 765 | behavior ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 766); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 766; __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 766 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN)do { static_assert( mozilla::detail::AssertionConditionType< decltype(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 766); AnnotateMozCrashReason("MOZ_ASSERT" "(" "behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN" ")"); do { *((volatile int*)__null) = 766; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 767 | |
| 768 | uint32_t blockedReason = |
| 769 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER; |
| 770 | |
| 771 | // Not a tracker. |
| 772 | nsCOMPtr<nsIClassifiedChannel> classifiedChannel = |
| 773 | do_QueryInterface(aChannel); |
| 774 | if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) { |
| 775 | if (classifiedChannel) { |
| 776 | if (!classifiedChannel->IsThirdPartyTrackingResource()) { |
| 777 | LOG(("Our channel isn't a third-party tracking channel"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our channel isn't a third-party tracking channel" ); } } while (0); |
| 778 | return true; |
| 779 | } |
| 780 | |
| 781 | uint32_t classificationFlags = |
| 782 | classifiedChannel->GetThirdPartyClassificationFlags(); |
| 783 | if (classificationFlags & nsIClassifiedChannel::ClassificationFlags:: |
| 784 | CLASSIFIED_SOCIALTRACKING) { |
| 785 | blockedReason = |
| 786 | nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER; |
| 787 | } |
| 788 | } |
| 789 | } else if (behavior == |
| 790 | nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) { |
| 791 | if (classifiedChannel && |
| 792 | classifiedChannel->IsThirdPartyTrackingResource()) { |
| 793 | // fall through, but remember that we're partitioned for trackers if |
| 794 | // it's instructed by the pref. |
| 795 | if (!StaticPrefs::network_cookie_cookieBehavior_trackerCookieBlocking()) { |
| 796 | blockedReason = |
| 797 | nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; |
| 798 | } |
| 799 | } else if (AntiTrackingUtils::IsThirdPartyChannel(aChannel)) { |
| 800 | LOG(("We're in the third-party context, storage should be partitioned"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "We're in the third-party context, storage should be partitioned" ); } } while (0); |
| 801 | // fall through but remember that we're partitioning. |
| 802 | blockedReason = nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; |
| 803 | } else { |
| 804 | LOG(("Our channel isn't a third-party channel, storage is allowed"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our channel isn't a third-party channel, storage is allowed" ); } } while (0); |
| 805 | return true; |
| 806 | } |
| 807 | } else { |
| 808 | MOZ_ASSERT_UNREACHABLE(do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 810); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 810; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) |
| 809 | "This should be an exhaustive list of cookie behaviors possible "do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 810); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 810; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) |
| 810 | "here.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 810); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "This should be an exhaustive list of cookie behaviors possible " "here." ")"); do { *((volatile int*)__null) = 810; __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); |
| 811 | } |
| 812 | |
| 813 | RefPtr<BrowsingContext> targetBC; |
| 814 | rv = loadInfo->GetTargetBrowsingContext(getter_AddRefs(targetBC)); |
| 815 | if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv )), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 815)) { |
| 816 | LOG(("Failed to get the channel's target browsing context"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the channel's target browsing context" ); } } while (0); |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | // If we cannot get the target browsing context from the loadInfo, the |
| 821 | // channel could be a fetch request from a worker scope. In this case, we |
| 822 | // get the target browsing context from the worker associated browsing |
| 823 | // context instead. |
| 824 | if (!targetBC) { |
| 825 | rv = loadInfo->GetWorkerAssociatedBrowsingContext(getter_AddRefs(targetBC)); |
Value stored to 'rv' is never read | |
| 826 | } |
| 827 | |
| 828 | // We could have no target BC for the channel if it's for loading the script |
| 829 | // for remote workers, i.e. shared workers and service workers. In this |
| 830 | // case, we also don't have document, so we can skip the sandbox and the |
| 831 | // document check. |
| 832 | if (!targetBC) { |
| 833 | LOG(("No browsing context is available for the channel."))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "No browsing context is available for the channel." ); } } while (0); |
| 834 | } |
| 835 | |
| 836 | if (targetBC && |
| 837 | Document::StorageAccessSandboxed(targetBC->GetSandboxFlags())) { |
| 838 | LOG(("Our document is sandboxed"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our document is sandboxed" ); } } while (0); |
| 839 | *aRejectedReason = blockedReason; |
| 840 | return false; |
| 841 | } |
| 842 | |
| 843 | // Let's see if we have to grant the access for this particular channel. |
| 844 | |
| 845 | // UsingStorageAccess only applies to channels that load |
| 846 | // documents, for sub-resources loads, just returns the result from |
| 847 | // loadInfo. |
| 848 | bool isDocument = false; |
| 849 | aChannel->GetIsDocument(&isDocument); |
| 850 | |
| 851 | if (targetBC && isDocument) { |
| 852 | nsCOMPtr<nsPIDOMWindowInner> inner = |
| 853 | AntiTrackingUtils::GetInnerWindow(targetBC); |
| 854 | if (inner && inner->UsingStorageAccess()) { |
| 855 | LOG(("Permission stored in the window. All good."))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Permission stored in the window. All good." ); } } while (0); |
| 856 | return true; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | bool allowed = |
| 861 | loadInfo->GetStoragePermission() != nsILoadInfo::NoStoragePermission; |
| 862 | if (!allowed) { |
| 863 | *aRejectedReason = blockedReason; |
| 864 | } |
| 865 | |
| 866 | return allowed; |
| 867 | } |
| 868 | |
| 869 | bool ShouldAllowAccessFor(nsIPrincipal* aPrincipal, |
| 870 | nsICookieJarSettings* aCookieJarSettings) { |
| 871 | MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 871); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")" ); do { *((volatile int*)__null) = 871; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 872 | MOZ_ASSERT(aCookieJarSettings)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aCookieJarSettings)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aCookieJarSettings))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aCookieJarSettings" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 872); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCookieJarSettings" ")"); do { *((volatile int*)__null) = 872; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 873 | |
| 874 | uint32_t access = |
| 875 | detail::CheckCookiePermissionForPrincipal(aCookieJarSettings, aPrincipal); |
| 876 | |
| 877 | if (access != nsICookiePermission::ACCESS_DEFAULT) { |
| 878 | return access != nsICookiePermission::ACCESS_DENY; |
| 879 | } |
| 880 | |
| 881 | int32_t behavior = CookiesBehavior(aPrincipal, aCookieJarSettings); |
| 882 | return behavior != nsICookieService::BEHAVIOR_REJECT; |
| 883 | } |
| 884 | |
| 885 | /* static */ |
| 886 | bool ApproximateAllowAccessForWithoutChannel( |
| 887 | nsPIDOMWindowInner* aFirstPartyWindow, nsIURI* aURI) { |
| 888 | MOZ_ASSERT(aFirstPartyWindow)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aFirstPartyWindow)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aFirstPartyWindow))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aFirstPartyWindow" , "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 888); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aFirstPartyWindow" ")"); do { *((volatile int*)__null) = 888; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 889 | MOZ_ASSERT(aURI)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aURI)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aURI))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("aURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 889); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do { *((volatile int*)__null) = 889; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 890 | |
| 891 | LOG_SPEC(do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing a best guess as to whether window %p has access to URI %s" , aFirstPartyWindow, _spec); } } while (0); } } while (0) |
| 892 | ("Computing a best guess as to whether window %p has access to URI %s",do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing a best guess as to whether window %p has access to URI %s" , aFirstPartyWindow, _spec); } } while (0); } } while (0) |
| 893 | aFirstPartyWindow, _spec),do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing a best guess as to whether window %p has access to URI %s" , aFirstPartyWindow, _spec); } } while (0); } } while (0) |
| 894 | aURI)do { if ((__builtin_expect(!!(mozilla::detail::log_test(gAntiTrackingLog , mozilla::LogLevel::Debug)), 0))) { nsAutoCString _specStr("(null)"_ns ); if (aURI) { _specStr = (aURI)->GetSpecOrDefault(); } _specStr .Truncate(std::min(_specStr.Length(), sMaxSpecLength)); const char* _spec = _specStr.get(); do { const ::mozilla::LogModule * moz_real_module = gAntiTrackingLog; if ((__builtin_expect(! !(mozilla::detail::log_test(moz_real_module, mozilla::LogLevel ::Debug)), 0))) { mozilla::detail::log_print(moz_real_module, mozilla::LogLevel::Debug, "Computing a best guess as to whether window %p has access to URI %s" , aFirstPartyWindow, _spec); } } while (0); } } while (0); |
| 895 | |
| 896 | Document* parentDocument = |
| 897 | nsGlobalWindowInner::Cast(aFirstPartyWindow)->GetExtantDoc(); |
| 898 | if (NS_WARN_IF(!parentDocument)NS_warn_if_impl(!parentDocument, "!parentDocument", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/StorageAccess.cpp" , 898)) { |
| 899 | LOG(("Failed to get the first party window's document"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Failed to get the first party window's document" ); } } while (0); |
| 900 | return false; |
| 901 | } |
| 902 | |
| 903 | if (!CookiesBehaviorRejectsThirdPartyContexts(parentDocument)) { |
| 904 | LOG(("Disabled by the pref (%d), bail out early",do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Disabled by the pref (%d), bail out early" , CookiesBehavior(parentDocument)); } } while (0) |
| 905 | CookiesBehavior(parentDocument)))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Disabled by the pref (%d), bail out early" , CookiesBehavior(parentDocument)); } } while (0); |
| 906 | return true; |
| 907 | } |
| 908 | |
| 909 | if (ContentBlockingAllowList::Check(aFirstPartyWindow)) { |
| 910 | return true; |
| 911 | } |
| 912 | |
| 913 | if (!AntiTrackingUtils::IsThirdPartyWindow(aFirstPartyWindow, aURI)) { |
| 914 | LOG(("Our window isn't a third-party window"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "Our window isn't a third-party window" ); } } while (0); |
| 915 | return true; |
| 916 | } |
| 917 | |
| 918 | uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal( |
| 919 | parentDocument->CookieJarSettings(), parentDocument->NodePrincipal()); |
| 920 | if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { |
| 921 | LOG(do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0) |
| 922 | ("CheckCookiePermissionForPrincipal() returned a non-default access "do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0) |
| 923 | "code (%d), returning %s",do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0) |
| 924 | int(cookiePermission),do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0) |
| 925 | cookiePermission != nsICookiePermission::ACCESS_DENY ? "success"do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0) |
| 926 | : "failure"))do { const ::mozilla::LogModule* moz_real_module = gAntiTrackingLog ; if ((__builtin_expect(!!(mozilla::detail::log_test(moz_real_module , mozilla::LogLevel::Debug)), 0))) { mozilla::detail::log_print (moz_real_module, mozilla::LogLevel::Debug, "CheckCookiePermissionForPrincipal() returned a non-default access " "code (%d), returning %s", int(cookiePermission), cookiePermission != nsICookiePermission::ACCESS_DENY ? "success" : "failure") ; } } while (0); |
| 927 | return cookiePermission != nsICookiePermission::ACCESS_DENY; |
| 928 | } |
| 929 | |
| 930 | nsIPrincipal* parentPrincipal = parentDocument->NodePrincipal(); |
| 931 | |
| 932 | nsCOMPtr<nsIPrincipal> principal = BasePrincipal::CreateContentPrincipal( |
| 933 | aURI, parentPrincipal->OriginAttributesRef()); |
| 934 | |
| 935 | nsAutoCString type; |
| 936 | AntiTrackingUtils::CreateStoragePermissionKey(principal, type); |
| 937 | |
| 938 | return AntiTrackingUtils::CheckStoragePermission( |
| 939 | parentPrincipal, type, parentDocument->IsInPrivateBrowsing(), nullptr, 0); |
| 940 | } |
| 941 | } // namespace mozilla |