Add-IsCleartextPermitted-flag.patch 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From: uazo <uazo@users.noreply.github.com>
  2. Date: Mon, 26 Apr 2021 15:04:11 +0000
  3. Subject: Add IsCleartextPermitted flag
  4. ---
  5. chrome/browser/about_flags.cc | 5 +++++
  6. chrome/browser/flag_descriptions.cc | 4 ++++
  7. chrome/browser/flag_descriptions.h | 3 +++
  8. net/base/features.cc | 3 +++
  9. net/base/features.h | 2 ++
  10. net/url_request/url_request_http_job.cc | 4 ++++
  11. 6 files changed, 21 insertions(+)
  12. diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  13. --- a/chrome/browser/about_flags.cc
  14. +++ b/chrome/browser/about_flags.cc
  15. @@ -7852,6 +7852,11 @@ const FeatureEntry kFeatureEntries[] = {
  16. FEATURE_VALUE_TYPE(
  17. chrome::android::kBookmarksExportUseSaf)},
  18. + {"cleartext-permitted",
  19. + flag_descriptions::kIsCleartextPermittedName,
  20. + flag_descriptions::kIsCleartextPermittedDescription, kOsAndroid,
  21. + FEATURE_VALUE_TYPE(net::features::kIsCleartextPermitted)},
  22. +
  23. // NOTE: Adding a new flag requires adding a corresponding entry to enum
  24. // "LoginCustomFlags" in tools/metrics/histograms/enums.xml. See "Flag
  25. // Histograms" in tools/metrics/histograms/README.md (run the
  26. diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
  27. --- a/chrome/browser/flag_descriptions.cc
  28. +++ b/chrome/browser/flag_descriptions.cc
  29. @@ -1460,6 +1460,10 @@ const char kHttpsOnlyModeDescription[] =
  30. "Adds a setting under chrome://settings/security to opt-in to HTTPS-First "
  31. "Mode.";
  32. +const char kIsCleartextPermittedName[] = "Allow cleartext traffic";
  33. +const char kIsCleartextPermittedDescription[] =
  34. + "Allow insecure connections over HTTP";
  35. +
  36. const char kIgnoreGpuBlocklistName[] = "Override software rendering list";
  37. const char kIgnoreGpuBlocklistDescription[] =
  38. "Overrides the built-in software rendering list and enables "
  39. diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
  40. --- a/chrome/browser/flag_descriptions.h
  41. +++ b/chrome/browser/flag_descriptions.h
  42. @@ -845,6 +845,9 @@ extern const char kHostedAppShimCreationDescription[];
  43. extern const char kHttpsOnlyModeName[];
  44. extern const char kHttpsOnlyModeDescription[];
  45. +extern const char kIsCleartextPermittedName[];
  46. +extern const char kIsCleartextPermittedDescription[];
  47. +
  48. extern const char kIgnoreGpuBlocklistName[];
  49. extern const char kIgnoreGpuBlocklistDescription[];
  50. diff --git a/net/base/features.cc b/net/base/features.cc
  51. --- a/net/base/features.cc
  52. +++ b/net/base/features.cc
  53. @@ -89,6 +89,9 @@ const base::FeatureParam<int> kUseDnsHttpsSvcbExtraTimePercent{
  54. const base::Feature kEnableTLS13EarlyData{"EnableTLS13EarlyData",
  55. base::FEATURE_DISABLED_BY_DEFAULT};
  56. +const base::Feature kIsCleartextPermitted{"IsCleartextPermitted",
  57. + base::FEATURE_ENABLED_BY_DEFAULT};
  58. +
  59. const base::Feature kNetworkQualityEstimator{"NetworkQualityEstimator",
  60. base::FEATURE_DISABLED_BY_DEFAULT};
  61. diff --git a/net/base/features.h b/net/base/features.h
  62. --- a/net/base/features.h
  63. +++ b/net/base/features.h
  64. @@ -37,6 +37,8 @@ NET_EXPORT extern const base::Feature kCapReferrerToOriginOnCrossOrigin;
  65. // Enables TLS 1.3 early data.
  66. NET_EXPORT extern const base::Feature kEnableTLS13EarlyData;
  67. +NET_EXPORT extern const base::Feature kIsCleartextPermitted;
  68. +
  69. // Support for altering the parameters used for DNS transaction timeout. See
  70. // ResolveContext::SecureTransactionTimeout().
  71. NET_EXPORT extern const base::Feature kDnsTransactionDynamicTimeouts;
  72. diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
  73. --- a/net/url_request/url_request_http_job.cc
  74. +++ b/net/url_request/url_request_http_job.cc
  75. @@ -215,6 +215,10 @@ std::unique_ptr<URLRequestJob> URLRequestHttpJob::Create(URLRequest* request) {
  76. }
  77. #if defined(OS_ANDROID)
  78. + if (base::FeatureList::IsEnabled(net::features::kIsCleartextPermitted) == false) {
  79. + return std::make_unique<URLRequestErrorJob>(request,
  80. + ERR_CLEARTEXT_NOT_PERMITTED);
  81. + }
  82. // Check whether the app allows cleartext traffic to this host, and return
  83. // ERR_CLEARTEXT_NOT_PERMITTED if not.
  84. if (request->context()->check_cleartext_permitted() &&
  85. --
  86. 2.20.1