Bug 1785125: Disable OriginPrivateFileSystem (OPFS) in Private Browsing r=asuth,dom-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D154823
This commit is contained in:
Randell Jesup 2022-11-23 02:07:32 +00:00
Родитель 6219c6dbcb
Коммит 89f63f7a7d
7 изменённых файлов: 86 добавлений и 2 удалений

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

@ -56,13 +56,19 @@ void FileSystemManager::BeginRequest(
std::function<void(nsresult)>&& aFailure) {
MOZ_ASSERT(!mShutdown);
MOZ_ASSERT(mGlobal);
// Check if we're allowed to use storage
if (mGlobal->GetStorageAccess() < StorageAccess::eSessionScoped) {
aFailure(NS_ERROR_DOM_SECURITY_ERR);
return;
}
if (mBackgroundRequestHandler->FileSystemManagerChildStrongRef()) {
aSuccess(mBackgroundRequestHandler->FileSystemManagerChildStrongRef());
return;
}
MOZ_ASSERT(mGlobal);
QM_TRY_INSPECT(const auto& principalInfo, mGlobal->GetStorageKey(), QM_VOID,
[&aFailure](nsresult rv) { aFailure(rv); });

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

@ -6,6 +6,7 @@
#include "FileSystemManagerParentFactory.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/FileSystemDataManager.h"
#include "mozilla/dom/FileSystemLog.h"
@ -36,6 +37,11 @@ mozilla::ipc::IPCResult CreateFileSystemManagerParent(
quota::QuotaManager::GetInfoFromValidatedPrincipalInfo(aPrincipalInfo),
quota::PERSISTENCE_TYPE_DEFAULT);
// Block use for now in PrivateBrowsing
QM_TRY(OkIf(!OriginAttributes::IsPrivateBrowsing(originMetadata.mOrigin)),
IPC_OK(),
[aResolver](const auto&) { aResolver(NS_ERROR_DOM_NOT_ALLOWED_ERR); });
LOG(("CreateFileSystemManagerParent, origin: %s",
originMetadata.mOrigin.get()));

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

@ -3,9 +3,11 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
[DEFAULT]
skip-if = xorigin
support-files =
head.js
# Skip all tests if xorigin since we'll fail GetStorage() with ePartitionForeignOrDeny
[test_basics.html]
scheme=https
[test_basics_worker.html]

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

@ -0,0 +1,5 @@
[DEFAULT]
support-files =
page_blank.html
[test_privateWin.html]

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

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
This is a test
</body>
</html>

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

@ -0,0 +1,58 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OPFS private window test</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<script type="text/javascript">
var mainWindow;
function startTest() {
mainWindow = window.browsingContext.topChromeWindow;
doTest();
}
var contentPage = "http://mochi.test:8888/chrome/dom/fs/test/mochitest/page_blank.html";
function testOnWindow(aIsPrivate, aCallback) {
var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
win.addEventListener("load", function() {
win.addEventListener("DOMContentLoaded", function onInnerLoad() {
if (win.content.location.href == "about:privatebrowsing") {
win.gBrowser.loadURI(contentPage, {
triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
});
return;
}
win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
SimpleTest.executeSoon(function() { aCallback(win); });
}, true);
}, {capture: true, once: true});
}
function doTest() {
testOnWindow(true, function(privateWin) {
try {
let root = privateWin.navigator.storage.getDirectory();
ok(false, "Didn't block storage.getDirectory() in private browsing");
} catch(e) {
ok(true, "blocked storage.getDirectory() in private browsing");
}
privateWin.close();
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="startTest();">
</body>
</html>

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

@ -176,6 +176,7 @@ MOCHITEST_MANIFESTS += [
MOCHITEST_CHROME_MANIFESTS += [
"mochitest/beacon/chrome.ini",
"mochitest/chrome/chrome.ini",
"mochitest/fs/chrome.ini",
"mochitest/general/chrome.ini",
"mochitest/geolocation/chrome.ini",
"mochitest/keyhandling/chrome.ini",