Commit 700f378a authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add persistent filesystem type support to incognito.

Blocking 'Persistent' filesystem type in incognito mode had resulted in
a backdoor to detect users being incognito. Since all stored data in
incognito mode are ephemeral and they only last until the session is
open, we can enable persistent filesystem type in incognito mode as
well and treat it similar to a temporary one (which is in-memory).

This feature is still DISABLED by default, behind
"EnablePersistentFilesystemInIncognito" flag.

third_party/blink/tools/run_blink_wptserve.py
out/Default/chrome --incognito --enable-features="EnablePersistentFilesystemInIncognito" http://localhost:8001/wpt_internal/file-system-api/temporary_vs_persistent.window.html

Bug: 990592
Change-Id: Ie49bc204f500c8f07e265adb0a5fe46371862d1e
Tested: 
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875252
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712963}
parent a91b2e23
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "storage/browser/file_system/file_stream_reader.h" #include "storage/browser/file_system/file_stream_reader.h"
#include "storage/browser/file_system/file_stream_writer.h" #include "storage/browser/file_system/file_stream_writer.h"
#include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_features.h"
#include "storage/browser/file_system/file_system_operation.h" #include "storage/browser/file_system/file_system_operation.h"
#include "storage/browser/file_system/file_system_operation_context.h" #include "storage/browser/file_system/file_system_operation_context.h"
#include "storage/browser/file_system/file_system_options.h" #include "storage/browser/file_system/file_system_options.h"
...@@ -64,7 +65,9 @@ void SandboxFileSystemBackend::ResolveURL(const FileSystemURL& url, ...@@ -64,7 +65,9 @@ void SandboxFileSystemBackend::ResolveURL(const FileSystemURL& url,
DCHECK(CanHandleType(url.type())); DCHECK(CanHandleType(url.type()));
DCHECK(delegate_); DCHECK(delegate_);
if (delegate_->file_system_options().is_incognito() && if (delegate_->file_system_options().is_incognito() &&
url.type() != kFileSystemTypeTemporary) { url.type() != kFileSystemTypeTemporary &&
!base::FeatureList::IsEnabled(
features::kEnablePersistentFilesystemInIncognito)) {
// TODO(kinuko): return an isolated temporary directory. // TODO(kinuko): return an isolated temporary directory.
std::move(callback).Run(GURL(), std::string(), std::move(callback).Run(GURL(), std::string(),
base::File::FILE_ERROR_SECURITY); base::File::FILE_ERROR_SECURITY);
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "storage/browser/file_system/file_system_backend.h" #include "storage/browser/file_system/file_system_backend.h"
#include "storage/browser/file_system/file_system_features.h"
#include "storage/browser/file_system/file_system_url.h" #include "storage/browser/file_system/file_system_url.h"
#include "storage/browser/file_system/sandbox_file_system_backend_delegate.h" #include "storage/browser/file_system/sandbox_file_system_backend_delegate.h"
#include "storage/browser/test/test_file_system_options.h" #include "storage/browser/test/test_file_system_options.h"
...@@ -73,11 +75,20 @@ void DidOpenFileSystem(base::File::Error* error_out, ...@@ -73,11 +75,20 @@ void DidOpenFileSystem(base::File::Error* error_out,
} // namespace } // namespace
class SandboxFileSystemBackendTest : public testing::Test { class SandboxFileSystemBackendTest
: public testing::Test,
public ::testing::WithParamInterface<bool> {
protected: protected:
void SetUp() override { void SetUp() override {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
SetUpNewDelegate(CreateAllowFileAccessOptions()); SetUpNewDelegate(CreateAllowFileAccessOptions());
if (IsPersistentFileSystemEnabledIncognito()) {
feature_list_.InitAndEnableFeature(
storage::features::kEnablePersistentFilesystemInIncognito);
} else {
feature_list_.InitAndDisableFeature(
storage::features::kEnablePersistentFilesystemInIncognito);
}
} }
void SetUpNewDelegate(const storage::FileSystemOptions& options) { void SetUpNewDelegate(const storage::FileSystemOptions& options) {
...@@ -132,21 +143,26 @@ class SandboxFileSystemBackendTest : public testing::Test { ...@@ -132,21 +143,26 @@ class SandboxFileSystemBackendTest : public testing::Test {
SandboxFileSystemBackendDelegate::kFileSystemDirectory); SandboxFileSystemBackendDelegate::kFileSystemDirectory);
} }
bool IsPersistentFileSystemEnabledIncognito() const { return GetParam(); }
std::unique_ptr<leveldb::Env> incognito_env_override_; std::unique_ptr<leveldb::Env> incognito_env_override_;
base::ScopedTempDir data_dir_; base::ScopedTempDir data_dir_;
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
std::unique_ptr<storage::SandboxFileSystemBackendDelegate> delegate_; std::unique_ptr<storage::SandboxFileSystemBackendDelegate> delegate_;
std::unique_ptr<storage::SandboxFileSystemBackend> backend_; std::unique_ptr<storage::SandboxFileSystemBackend> backend_;
base::test::ScopedFeatureList feature_list_;
}; };
TEST_F(SandboxFileSystemBackendTest, Empty) { INSTANTIATE_TEST_SUITE_P(, SandboxFileSystemBackendTest, ::testing::Bool());
TEST_P(SandboxFileSystemBackendTest, Empty) {
SetUpNewBackend(CreateAllowFileAccessOptions()); SetUpNewBackend(CreateAllowFileAccessOptions());
std::unique_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> std::unique_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator>
enumerator(CreateOriginEnumerator()); enumerator(CreateOriginEnumerator());
ASSERT_TRUE(enumerator->Next().is_empty()); ASSERT_TRUE(enumerator->Next().is_empty());
} }
TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) { TEST_P(SandboxFileSystemBackendTest, EnumerateOrigins) {
SetUpNewBackend(CreateAllowFileAccessOptions()); SetUpNewBackend(CreateAllowFileAccessOptions());
const char* temporary_origins[] = { const char* temporary_origins[] = {
"http://www.bar.com/", "http://www.foo.com/", "http://www.bar.com/", "http://www.foo.com/",
...@@ -193,7 +209,7 @@ TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) { ...@@ -193,7 +209,7 @@ TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) {
EXPECT_EQ(persistent_size, persistent_actual_size); EXPECT_EQ(persistent_size, persistent_actual_size);
} }
TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { TEST_P(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) {
std::vector<base::FilePath> returned_root_path( std::vector<base::FilePath> returned_root_path(
base::size(kRootPathTestCases)); base::size(kRootPathTestCases));
SetUpNewBackend(CreateAllowFileAccessOptions()); SetUpNewBackend(CreateAllowFileAccessOptions());
...@@ -231,7 +247,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { ...@@ -231,7 +247,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) {
} }
} }
TEST_F(SandboxFileSystemBackendTest, TEST_P(SandboxFileSystemBackendTest,
GetRootPathCreateAndExamineWithNewBackend) { GetRootPathCreateAndExamineWithNewBackend) {
std::vector<base::FilePath> returned_root_path( std::vector<base::FilePath> returned_root_path(
base::size(kRootPathTestCases)); base::size(kRootPathTestCases));
...@@ -253,7 +269,7 @@ TEST_F(SandboxFileSystemBackendTest, ...@@ -253,7 +269,7 @@ TEST_F(SandboxFileSystemBackendTest,
EXPECT_EQ(root_path1.value(), root_path2.value()); EXPECT_EQ(root_path1.value(), root_path2.value());
} }
TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { TEST_P(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) {
SetUpNewBackend(CreateDisallowFileAccessOptions()); SetUpNewBackend(CreateDisallowFileAccessOptions());
// Try to get a root directory without creating. // Try to get a root directory without creating.
...@@ -266,7 +282,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { ...@@ -266,7 +282,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) {
} }
} }
TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { TEST_P(SandboxFileSystemBackendTest, GetRootPathInIncognito) {
SetUpNewBackend(CreateIncognitoFileSystemOptions()); SetUpNewBackend(CreateIncognitoFileSystemOptions());
// Try to get a root directory. // Try to get a root directory.
...@@ -274,14 +290,15 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { ...@@ -274,14 +290,15 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) {
SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " "
<< kRootPathTestCases[i].expected_path); << kRootPathTestCases[i].expected_path);
EXPECT_EQ( EXPECT_EQ(
kRootPathTestCases[i].type == storage::kFileSystemTypeTemporary, IsPersistentFileSystemEnabledIncognito() ||
kRootPathTestCases[i].type == storage::kFileSystemTypeTemporary,
GetRootPath(GURL(kRootPathTestCases[i].origin_url), GetRootPath(GURL(kRootPathTestCases[i].origin_url),
kRootPathTestCases[i].type, kRootPathTestCases[i].type,
storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, nullptr)); storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, nullptr));
} }
} }
TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { TEST_P(SandboxFileSystemBackendTest, GetRootPathFileURI) {
SetUpNewBackend(CreateDisallowFileAccessOptions()); SetUpNewBackend(CreateDisallowFileAccessOptions());
for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) { for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) {
SCOPED_TRACE(testing::Message() SCOPED_TRACE(testing::Message()
...@@ -294,7 +311,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { ...@@ -294,7 +311,7 @@ TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) {
} }
} }
TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { TEST_P(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) {
SetUpNewBackend(CreateAllowFileAccessOptions()); SetUpNewBackend(CreateAllowFileAccessOptions());
for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) { for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) {
SCOPED_TRACE(testing::Message() SCOPED_TRACE(testing::Message()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment