-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTTPS-Only Mode: Make HTTP allowlist per-profile instead of per-tab
HTTPS-Only Mode has an allowlist that stores the user decisions when the user clicks through an HTTPS-Only Mode interstitial. If the user navigates to the same domain later, this allowlist is checked to decide whether to allow the navigation over HTTP or to upgrade it to HTTPS. The allowlist is currently per-tab, meaning it doesn't carry over to other tabs. To fix this, this CL introduces a new KeyedService called HttpsUpgradeService which replaces the current allowlist. The service keeps track of allowlist decisions per-profile. Future CLs will also make the following changes: - Allowlist entries will be saved to content settings when not in incognito mode (same as desktop). - Allowlist entries will have a timeout (same as desktop) - Test methods like SetHttpPortForTesting() will be moved from the tab helper to the service so that different tabs can read the same values at once. This will allow us to test the feature with multiple tabs. Bug: 1302509 Change-Id: Ia6e11991400de50a6136d579c7fc90ed8833a468 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3633920 Reviewed-by: Ali Juma <ajuma@chromium.org> Reviewed-by: Rohit Rao <rohitrao@chromium.org> Commit-Queue: Mustafa Emre Acer <meacer@chromium.org> Cr-Commit-Position: refs/heads/main@{#1001777}
- Loading branch information
Showing
21 changed files
with
318 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ios/chrome/browser/https_upgrades/https_upgrade_service_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_FACTORY_H_ | ||
#define IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_FACTORY_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/no_destructor.h" | ||
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h" | ||
#include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" | ||
#import "ios/chrome/browser/https_upgrades/https_upgrade_service_impl.h" | ||
|
||
// Singleton that owns all HttpsUpgradeService and associates them with | ||
// ChromeBrowserState. | ||
class HttpsUpgradeServiceFactory : public BrowserStateKeyedServiceFactory { | ||
public: | ||
static HttpsUpgradeService* GetForBrowserState( | ||
web::BrowserState* browser_state); | ||
static HttpsUpgradeServiceFactory* GetInstance(); | ||
|
||
HttpsUpgradeServiceFactory(const HttpsUpgradeServiceFactory&) = delete; | ||
HttpsUpgradeServiceFactory& operator=(const HttpsUpgradeServiceFactory&) = | ||
delete; | ||
|
||
private: | ||
friend class base::NoDestructor<HttpsUpgradeServiceFactory>; | ||
|
||
HttpsUpgradeServiceFactory(); | ||
~HttpsUpgradeServiceFactory() override; | ||
|
||
// BrowserStateKeyedServiceFactory implementation. | ||
std::unique_ptr<KeyedService> BuildServiceInstanceFor( | ||
web::BrowserState* context) const override; | ||
web::BrowserState* GetBrowserStateToUse( | ||
web::BrowserState* context) const override; | ||
|
||
bool ServiceIsNULLWhileTesting() const override; | ||
}; | ||
|
||
#endif // IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_FACTORY_H_ |
48 changes: 48 additions & 0 deletions
48
ios/chrome/browser/https_upgrades/https_upgrade_service_factory.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/https_upgrades/https_upgrade_service_factory.h" | ||
|
||
#include "base/no_destructor.h" | ||
#include "components/keyed_service/ios/browser_state_dependency_manager.h" | ||
#include "ios/web/public/browser_state.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
// static | ||
HttpsUpgradeService* HttpsUpgradeServiceFactory::GetForBrowserState( | ||
web::BrowserState* browser_state) { | ||
return static_cast<HttpsUpgradeService*>( | ||
GetInstance()->GetServiceForBrowserState(browser_state, true)); | ||
} | ||
|
||
// static | ||
HttpsUpgradeServiceFactory* HttpsUpgradeServiceFactory::GetInstance() { | ||
static base::NoDestructor<HttpsUpgradeServiceFactory> instance; | ||
return instance.get(); | ||
} | ||
|
||
HttpsUpgradeServiceFactory::HttpsUpgradeServiceFactory() | ||
: BrowserStateKeyedServiceFactory( | ||
"HttpsUpgradeService", | ||
BrowserStateDependencyManager::GetInstance()) {} | ||
|
||
HttpsUpgradeServiceFactory::~HttpsUpgradeServiceFactory() {} | ||
|
||
std::unique_ptr<KeyedService> | ||
HttpsUpgradeServiceFactory::BuildServiceInstanceFor( | ||
web::BrowserState* context) const { | ||
return std::make_unique<HttpsUpgradeServiceImpl>(context); | ||
} | ||
|
||
web::BrowserState* HttpsUpgradeServiceFactory::GetBrowserStateToUse( | ||
web::BrowserState* context) const { | ||
return GetBrowserStateOwnInstanceInIncognito(context); | ||
} | ||
|
||
bool HttpsUpgradeServiceFactory::ServiceIsNULLWhileTesting() const { | ||
return false; | ||
} |
40 changes: 40 additions & 0 deletions
40
ios/chrome/browser/https_upgrades/https_upgrade_service_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_IMPL_H_ | ||
#define IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_IMPL_H_ | ||
|
||
#include <set> | ||
#include <string> | ||
|
||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "ios/components/security_interstitials/https_only_mode/https_upgrade_service.h" | ||
|
||
namespace web { | ||
class BrowserState; | ||
} | ||
|
||
// HttpsUpgradeServiceImpl tracks the allowlist decisions for HTTPS-Only mode. | ||
// Decisions are scoped to the host. | ||
class HttpsUpgradeServiceImpl : public HttpsUpgradeService { | ||
public: | ||
HttpsUpgradeServiceImpl(web::BrowserState* context); | ||
~HttpsUpgradeServiceImpl() override; | ||
|
||
// Returns whether |host| can be loaded over http://. | ||
bool IsHttpAllowedForHost(const std::string& host) const override; | ||
|
||
// Allows future navigations to |host| over http://. | ||
void AllowHttpForHost(const std::string& host) override; | ||
|
||
void ClearAllowlist() override; | ||
|
||
private: | ||
// Set of allowlisted hostnames. | ||
std::set<std::string> allowed_http_hosts_; | ||
|
||
web::BrowserState* context_; | ||
}; | ||
|
||
#endif // IOS_CHROME_BROWSER_HTTPS_UPGRADES_HTTPS_UPGRADE_SERVICE_IMPL_H_ |
32 changes: 32 additions & 0 deletions
32
ios/chrome/browser/https_upgrades/https_upgrade_service_impl.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/https_upgrades/https_upgrade_service_impl.h" | ||
|
||
#include "base/containers/contains.h" | ||
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
HttpsUpgradeServiceImpl::HttpsUpgradeServiceImpl(web::BrowserState* context) | ||
: context_(context) { | ||
DCHECK(context_); | ||
} | ||
|
||
HttpsUpgradeServiceImpl::~HttpsUpgradeServiceImpl() = default; | ||
|
||
bool HttpsUpgradeServiceImpl::IsHttpAllowedForHost( | ||
const std::string& host) const { | ||
return base::Contains(allowed_http_hosts_, host); | ||
} | ||
|
||
void HttpsUpgradeServiceImpl::AllowHttpForHost(const std::string& host) { | ||
allowed_http_hosts_.insert(host); | ||
} | ||
|
||
void HttpsUpgradeServiceImpl::ClearAllowlist() { | ||
allowed_http_hosts_.clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.