Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid CNAME uncloaking if a proxy is configured #8957

Merged
merged 5 commits into from
Jun 11, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions browser/net/brave_ad_block_tp_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/net/proxy_service_factory.h"
#include "chrome/browser/net/secure_dns_config.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/pref_proxy_config_tracker.h"
antonok-edm marked this conversation as resolved.
Show resolved Hide resolved
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
Expand All @@ -32,6 +36,9 @@
#include "content/public/common/url_constants.h"
#include "extensions/common/url_pattern.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/proxy_resolution/proxy_config.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
#include "services/network/host_resolver.h"
#include "services/network/network_context.h"
#include "ui/base/resource/resource_bundle.h"
Expand Down Expand Up @@ -245,6 +252,41 @@ void OnBeforeURLRequestAdBlockTP(const ResponseCallback& next_callback,
brave_shields::features::kBraveAdblockCnameUncloaking) &&
ctx->browser_context && !ctx->browser_context->IsTor();

// Also, skip CNAME uncloaking if there is currently a configured proxy.
if (ctx->browser_context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this block to a separate function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

Profile* profile = Profile::FromBrowserContext(ctx->browser_context);

std::unique_ptr<PrefProxyConfigTracker> config_tracker =
ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(
profile->GetPrefs(), nullptr);
std::unique_ptr<net::ProxyConfigService> proxy_config_service =
ProxyServiceFactory::CreateProxyConfigService(config_tracker.get());

net::ProxyConfigWithAnnotation config;
net::ProxyConfigService::ConfigAvailability availability =
proxy_config_service->GetLatestProxyConfig(&config);

if (availability ==
net::ProxyConfigService::ConfigAvailability::CONFIG_VALID) {
// If only particular types of network traffic are being proxied, or if no
// proxy is configured, it should be safe to continue making unproxied DNS
// queries. However, in SingleProxy mode all types of network traffic
// should go through the proxy, so additional DNS queries should be
// avoided.
if (config.value().proxy_rules().type ==
net::ProxyConfig::ProxyRules::Type::PROXY_LIST) {
should_check_uncloaked = false;
}
} else if (availability ==
net::ProxyConfigService::ConfigAvailability::CONFIG_PENDING) {
// Fallback to not CNAME uncloaking if the proxy configuration cannot be
// determined.
should_check_uncloaked = false;
}

config_tracker->DetachFromPrefService();
}

task_runner->PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&ShouldBlockRequestOnTaskRunner, ctx, EngineFlags(),
Expand Down