Bug 1461921 - Block storage access for third-parties on the tracking protection list - part 6 - Image cache, r=aosmond

This commit is contained in:
Andrea Marchesini 2018-06-20 13:38:22 -04:00
parent 5b9437cad2
commit c42c9f66ed
2 changed files with 20 additions and 6 deletions

View file

@ -7,6 +7,7 @@
#include "mozilla/HashFunctions.h" #include "mozilla/HashFunctions.h"
#include "mozilla/Move.h" #include "mozilla/Move.h"
#include "nsContentUtils.h"
#include "nsLayoutUtils.h" #include "nsLayoutUtils.h"
#include "nsString.h" #include "nsString.h"
#include "mozilla/dom/BlobURLProtocolHandler.h" #include "mozilla/dom/BlobURLProtocolHandler.h"
@ -42,7 +43,7 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI,
nsresult& aRv) nsresult& aRv)
: mURI(aURI) : mURI(aURI)
, mOriginAttributes(aAttrs) , mOriginAttributes(aAttrs)
, mControlledDocument(GetControlledDocumentToken(aDocument)) , mControlledDocument(GetSpecialCaseDocumentToken(aDocument, aURI))
, mHash(0) , mHash(0)
, mIsChrome(false) , mIsChrome(false)
{ {
@ -125,11 +126,10 @@ ImageCacheKey::SchemeIs(const char* aScheme)
} }
/* static */ void* /* static */ void*
ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument) ImageCacheKey::GetSpecialCaseDocumentToken(nsIDocument* aDocument, nsIURI* aURI)
{ {
// For non-controlled documents, we just return null. For controlled // For controlled documents, we cast the pointer into a void* to avoid
// documents, we cast the pointer into a void* to avoid dereferencing // dereferencing it (since we only use it for comparisons).
// it (since we only use it for comparisons), and return it.
void* pointer = nullptr; void* pointer = nullptr;
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (aDocument && swm) { if (aDocument && swm) {
@ -138,6 +138,16 @@ ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument)
pointer = aDocument; pointer = aDocument;
} }
} }
// If this document has been marked as tracker, let's use its address to make
// a unique cache key.
if (!pointer && aDocument &&
nsContentUtils::StorageDisabledByAntiTracking(nullptr,
aDocument->GetChannel(),
aURI)) {
pointer = aDocument;
}
return pointer; return pointer;
} }

View file

@ -55,7 +55,11 @@ public:
private: private:
bool SchemeIs(const char* aScheme); bool SchemeIs(const char* aScheme);
static void* GetControlledDocumentToken(nsIDocument* aDocument);
// For ServiceWorker and for anti-tracking we need to use the document as
// token for the key. All those exceptions are handled by this method.
static void* GetSpecialCaseDocumentToken(nsIDocument* aDocument,
nsIURI* aURI);
nsCOMPtr<nsIURI> mURI; nsCOMPtr<nsIURI> mURI;
Maybe<uint64_t> mBlobSerial; Maybe<uint64_t> mBlobSerial;