Bug 1515665 - SessionStorage should be allowed when StorageAccess is ePartitionedOrDeny, r=ehsan

This commit is contained in:
Andrea Marchesini 2019-01-23 19:19:20 +01:00
Родитель e563896a47
Коммит c433a88518
4 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@ -12,6 +12,7 @@
#include "mozilla/Preferences.h"
#include "nsContentUtils.h"
#include "nsIPrincipal.h"
#include "nsIWebProgressListener.h"
#include "nsPIDOMWindow.h"
#define DATASET \
@ -163,5 +164,11 @@ bool SessionStorage::IsForkOf(const Storage* aOther) const {
return mCache == static_cast<const SessionStorage*>(aOther)->mCache;
}
bool SessionStorage::ShouldThrowWhenStorageAccessDenied(
uint32_t aRejectedReason) {
return aRejectedReason !=
nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -65,6 +65,8 @@ class SessionStorage final : public Storage {
const nsAString& aOldValue,
const nsAString& aNewValue);
bool ShouldThrowWhenStorageAccessDenied(uint32_t aRejectedReason) override;
RefPtr<SessionStorageCache> mCache;
RefPtr<SessionStorageManager> mManager;

Просмотреть файл

@ -43,15 +43,23 @@ bool Storage::CanUseStorage(nsIPrincipal& aSubjectPrincipal) {
return false;
}
nsContentUtils::StorageAccess access =
nsContentUtils::StorageAllowedForPrincipal(Principal());
if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
mIsSessionOnly = false;
} else if (mWindow) {
uint32_t rejectedReason = 0;
nsContentUtils::StorageAccess access =
nsContentUtils::StorageAllowedForWindow(mWindow, &rejectedReason);
if (access <= nsContentUtils::StorageAccess::eDeny) {
return false;
// Note that we allow StorageAccess::ePartitionedOrDeny because we want
// tracker to have access to their sessionStorage.
if (access == nsContentUtils::StorageAccess::eDeny &&
ShouldThrowWhenStorageAccessDenied(rejectedReason)) {
return false;
}
mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
}
mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
return aSubjectPrincipal.Subsumes(mPrincipal);
}

Просмотреть файл

@ -144,6 +144,13 @@ class Storage : public nsISupports, public nsWrapperCache {
virtual void LastRelease() {}
// This method is called when StorageAccess is not granted for the owning
// window. aRejectedReason is one of the possible blocking states from
// nsIWebProgressListener.
virtual bool ShouldThrowWhenStorageAccessDenied(uint32_t aRejectedReason) {
return true;
}
private:
nsCOMPtr<nsPIDOMWindowInner> mWindow;
nsCOMPtr<nsIPrincipal> mPrincipal;