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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 | 16 +++++++++++-----
  8. 3 files changed, 21 insertions(+), 6 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. @@ -112,3 +112,12 @@ LOAD_FLAG(RESTRICTED_PREFETCH, 1 << 17)
  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 << 18)
  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. @@ -418,7 +418,7 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
  29. // Disable secure DNS for any DoH server hostname lookups to avoid deadlock.
  30. request_->SetDisableSecureDns(true);
  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. @@ -331,6 +331,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. @@ -338,11 +339,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. @@ -538,10 +542,12 @@ void URLRequestHttpJob::AddExtraHeaders() {
  61. } else {
  62. // Advertise "br" encoding only if transferred data is opaque to proxy.
  63. bool advertise_brotli = false;
  64. - if (request()->context()->enable_brotli()) {
  65. - if (request()->url().SchemeIsCryptographic() ||
  66. - IsLocalhost(request()->url())) {
  67. - advertise_brotli = true;
  68. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  69. + if (request()->context()->enable_brotli()) {
  70. + if (request()->url().SchemeIsCryptographic() ||
  71. + IsLocalhost(request()->url())) {
  72. + advertise_brotli = true;
  73. + }
  74. }
  75. }
  76. @@ -559,7 +565,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.17.1