Reduce-HTTP-headers-in-DoH-requests-to-bare-minimum.patch 3.9 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. ---
  5. net/base/load_flags_list.h | 9 +++++++++
  6. net/dns/dns_transaction.cc | 2 +-
  7. net/url_request/url_request_http_job.cc | 8 +++++++-
  8. 3 files changed, 17 insertions(+), 2 deletions(-)
  9. diff --git a/net/base/load_flags_list.h b/net/base/load_flags_list.h
  10. --- a/net/base/load_flags_list.h
  11. +++ b/net/base/load_flags_list.h
  12. @@ -101,3 +101,12 @@ LOAD_FLAG(RESTRICTED_PREFETCH, 1 << 15)
  13. // is considered privileged, and therefore this flag must only be set from a
  14. // trusted process.
  15. LOAD_FLAG(CAN_USE_RESTRICTED_PREFETCH, 1 << 16)
  16. +
  17. +
  18. +
  19. +
  20. +// This load will not send Accept-Language or User-Agent headers, and not
  21. +// advertise brotli encoding.
  22. +// Used to comply with IETF (draft) DNS-over-HTTPS:
  23. +// "Implementors SHOULD NOT set non-essential HTTP headers in DoH client requests."
  24. +LOAD_FLAG(MINIMAL_HEADERS, 1 << 19)
  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. @@ -437,7 +437,7 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
  29. // Disable secure DNS for any DoH server hostname lookups to avoid deadlock.
  30. request_->SetSecureDnsPolicy(SecureDnsPolicy::kDisable);
  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. @@ -319,6 +319,7 @@ void URLRequestHttpJob::Start() {
  41. // plugin could set a referrer although sending the referrer is inhibited.
  42. request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer);
  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. @@ -326,11 +327,14 @@ void URLRequestHttpJob::Start() {
  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. AddCookieHeaderAndStart();
  60. @@ -552,6 +556,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  61. if (request_->Supports(SourceStream::SourceType::TYPE_DEFLATE)) {
  62. advertised_encoding_names.push_back("deflate");
  63. }
  64. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  65. // Advertise "br" encoding only if transferred data is opaque to proxy.
  66. if (request()->context()->enable_brotli() &&
  67. request_->Supports(SourceStream::SourceType::TYPE_BROTLI)) {
  68. @@ -560,6 +565,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  69. advertised_encoding_names.push_back("br");
  70. }
  71. }
  72. + } // minimal headers
  73. if (!advertised_encoding_names.empty()) {
  74. // Tell the server what compression formats are supported.
  75. request_info_.extra_headers.SetHeader(
  76. @@ -569,7 +575,7 @@ void URLRequestHttpJob::AddExtraHeaders() {
  77. }
  78. }
  79. - if (http_user_agent_settings_) {
  80. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS) && http_user_agent_settings_) {
  81. // Only add default Accept-Language if the request didn't have it
  82. // specified.
  83. std::string accept_language =
  84. --
  85. 2.20.1