Reduce-HTTP-headers-in-DoH-requests-to-bare-minimum.patch 3.7 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 | 1 +
  7. net/url_request/url_request_http_job.cc | 16 +++++++++++-----
  8. 3 files changed, 21 insertions(+), 5 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. @@ -405,6 +405,7 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
  29. // perspective to prevent the client from sending AIA requests).
  30. request_->SetLoadFlags(request_->load_flags() | LOAD_DISABLE_CACHE |
  31. LOAD_BYPASS_PROXY |
  32. + LOAD_IGNORE_LIMITS | LOAD_MINIMAL_HEADERS |
  33. LOAD_DISABLE_CERT_NETWORK_FETCHES);
  34. request_->set_allow_credentials(false);
  35. }
  36. diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
  37. --- a/net/url_request/url_request_http_job.cc
  38. +++ b/net/url_request/url_request_http_job.cc
  39. @@ -278,6 +278,7 @@ void URLRequestHttpJob::Start() {
  40. // plugin could set a referrer although sending the referrer is inhibited.
  41. request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer);
  42. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  43. // Our consumer should have made sure that this is a safe referrer. See for
  44. // instance WebCore::FrameLoader::HideReferrer.
  45. if (referrer.is_valid()) {
  46. @@ -293,11 +294,14 @@ void URLRequestHttpJob::Start() {
  47. request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
  48. referer_value);
  49. }
  50. + }
  51. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  52. request_info_.extra_headers.SetHeaderIfMissing(
  53. HttpRequestHeaders::kUserAgent,
  54. http_user_agent_settings_ ?
  55. http_user_agent_settings_->GetUserAgent() : std::string());
  56. + }
  57. AddExtraHeaders();
  58. AddCookieHeaderAndStart();
  59. @@ -510,10 +514,12 @@ void URLRequestHttpJob::AddExtraHeaders() {
  60. } else {
  61. // Advertise "br" encoding only if transferred data is opaque to proxy.
  62. bool advertise_brotli = false;
  63. - if (request()->context()->enable_brotli()) {
  64. - if (request()->url().SchemeIsCryptographic() ||
  65. - IsLocalhost(request()->url())) {
  66. - advertise_brotli = true;
  67. + if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
  68. + if (request()->context()->enable_brotli()) {
  69. + if (request()->url().SchemeIsCryptographic() ||
  70. + IsLocalhost(request()->url())) {
  71. + advertise_brotli = true;
  72. + }
  73. }
  74. }
  75. @@ -531,7 +537,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.17.1