Reduce-HTTP-headers-in-DoH-requests-to-bare-minimum.patch 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sat, 28 Apr 2018 08:30:26 +0200
  3. Subject: Reduce HTTP headers in DoH requests to bare minimum
  4. License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
  5. ---
  6. net/base/load_flags_list.h | 6 ++++++
  7. net/dns/dns_transaction.cc | 2 +-
  8. net/url_request/url_request_http_job.cc | 8 +++++++-
  9. 3 files changed, 14 insertions(+), 2 deletions(-)
  10. diff --git a/net/base/load_flags_list.h b/net/base/load_flags_list.h
  11. --- a/net/base/load_flags_list.h
  12. +++ b/net/base/load_flags_list.h
  13. @@ -102,6 +102,12 @@ LOAD_FLAG(RESTRICTED_PREFETCH, 1 << 15)
  14. // trusted process.
  15. LOAD_FLAG(CAN_USE_RESTRICTED_PREFETCH, 1 << 16)
  16. +// This load will not send Accept-Language or User-Agent headers, and not
  17. +// advertise brotli encoding.
  18. +// Used to comply with IETF (draft) DNS-over-HTTPS:
  19. +// "Implementors SHOULD NOT set non-essential HTTP headers in DoH client requests."
  20. +LOAD_FLAG(MINIMAL_HEADERS, 1 << 19)
  21. +
  22. // True if the request should attempt to use the single-keyed cache to satisfy
  23. // the request. The single-keyed cache will only be used if the "unusable" flag
  24. // on the cache entry is not true. Otherwise it will fall back to the
  25. diff --git a/net/dns/dns_transaction.cc b/net/dns/dns_transaction.cc
  26. --- a/net/dns/dns_transaction.cc
  27. +++ b/net/dns/dns_transaction.cc
  28. @@ -445,7 +445,7 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
  29. // avoid deadlock and enable the use of preconfigured IP addresses.
  30. request_->SetSecureDnsPolicy(SecureDnsPolicy::kBootstrap);
  31. request_->SetLoadFlags(request_->load_flags() | LOAD_DISABLE_CACHE |
  32. - LOAD_BYPASS_PROXY);
  33. + LOAD_MINIMAL_HEADERS | LOAD_BYPASS_PROXY);
  34. request_->set_allow_credentials(false);
  35. request_->set_isolation_info(isolation_info);
  36. }
  37. diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
  38. --- a/net/url_request/url_request_http_job.cc
  39. +++ b/net/url_request/url_request_http_job.cc
  40. @@ -314,6 +314,7 @@ void URLRequestHttpJob::OnGotFirstPartySetMetadata(
  41. // fields in the referrer.
  42. GURL referrer(request_->referrer());
  43. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  44. // Our consumer should have made sure that this is a safe referrer (e.g. via
  45. // URLRequestJob::ComputeReferrerForPolicy).
  46. if (referrer.is_valid()) {
  47. @@ -321,11 +322,14 @@ void URLRequestHttpJob::OnGotFirstPartySetMetadata(
  48. request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
  49. referer_value);
  50. }
  51. + }
  52. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  53. request_info_.extra_headers.SetHeaderIfMissing(
  54. HttpRequestHeaders::kUserAgent,
  55. http_user_agent_settings_ ?
  56. http_user_agent_settings_->GetUserAgent() : std::string());
  57. + }
  58. AddExtraHeaders();
  59. @@ -595,6 +599,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  60. if (request_->Supports(SourceStream::SourceType::TYPE_DEFLATE)) {
  61. advertised_encoding_names.push_back("deflate");
  62. }
  63. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  64. // Advertise "br" encoding only if transferred data is opaque to proxy.
  65. if (request()->context()->enable_brotli() &&
  66. request_->Supports(SourceStream::SourceType::TYPE_BROTLI)) {
  67. @@ -603,6 +608,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  68. advertised_encoding_names.push_back("br");
  69. }
  70. }
  71. + } // minimal headers
  72. if (!advertised_encoding_names.empty()) {
  73. // Tell the server what compression formats are supported.
  74. request_info_.extra_headers.SetHeader(
  75. @@ -612,7 +618,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  76. }
  77. }
  78. - if (http_user_agent_settings_) {
  79. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS) && http_user_agent_settings_) {
  80. // Only add default Accept-Language if the request didn't have it
  81. // specified.
  82. std::string accept_language =
  83. --
  84. 2.25.1