forked from bromite/bromite
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Reduce-HTTP-headers-in-DoH-requests-to-bare-minimum.patch
75 lines (68 loc) · 3.45 KB
/
Reduce-HTTP-headers-in-DoH-requests-to-bare-minimum.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Sat, 28 Apr 2018 08:30:26 +0200
Subject: Reduce HTTP headers in DoH requests to bare minimum
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
net/base/load_flags_list.h | 4 ++++
net/dns/dns_transaction.cc | 2 +-
net/url_request/url_request_http_job.cc | 10 +++++++---
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/base/load_flags_list.h b/net/base/load_flags_list.h
--- a/net/base/load_flags_list.h
+++ b/net/base/load_flags_list.h
@@ -115,3 +115,7 @@ LOAD_FLAG(DISABLE_SHARED_DICTIONARY_AFTER_CROSS_ORIGIN_REDIRECT, 1 << 18)
// This flag is used to bypass HSTS upgrades. This flag must be set for AIA,
// CRL, and OCSP requests in order to prevent circular dependencies.
LOAD_FLAG(SHOULD_BYPASS_HSTS, 1 << 19)
+
+// Used to comply with IETF (draft) DNS-over-HTTPS:
+// "Implementors SHOULD NOT set non-essential HTTP headers in DoH client requests."
+LOAD_FLAG(MINIMAL_HEADERS, 1 << 20)
diff --git a/net/dns/dns_transaction.cc b/net/dns/dns_transaction.cc
--- a/net/dns/dns_transaction.cc
+++ b/net/dns/dns_transaction.cc
@@ -484,7 +484,7 @@ class DnsHTTPAttempt : public DnsAttempt, public URLRequest::Delegate {
// avoid deadlock and enable the use of preconfigured IP addresses.
request_->SetSecureDnsPolicy(SecureDnsPolicy::kBootstrap);
request_->SetLoadFlags(request_->load_flags() | LOAD_DISABLE_CACHE |
- LOAD_BYPASS_PROXY);
+ LOAD_MINIMAL_HEADERS | LOAD_BYPASS_PROXY);
request_->set_allow_credentials(false);
request_->set_isolation_info(isolation_info);
}
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -520,6 +520,7 @@ void URLRequestHttpJob::OnGotFirstPartySetMetadata(
// fields in the referrer.
GURL referrer(request_->referrer());
+ if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
// Our consumer should have made sure that this is a safe referrer (e.g. via
// URLRequestJob::ComputeReferrerForPolicy).
if (referrer.is_valid()) {
@@ -527,11 +528,14 @@ void URLRequestHttpJob::OnGotFirstPartySetMetadata(
request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
referer_value);
}
+ }
+ if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS)) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kUserAgent,
http_user_agent_settings_ ?
http_user_agent_settings_->GetUserAgent() : std::string());
+ }
AddExtraHeaders();
@@ -777,10 +781,10 @@ void URLRequestHttpJob::StartTransactionInternal() {
void URLRequestHttpJob::AddExtraHeaders() {
request_info_.extra_headers.SetAcceptEncodingIfMissing(
request()->url(), request()->accepted_stream_types(),
- request()->context()->enable_brotli(),
- request()->context()->enable_zstd());
+ !(request_info_.load_flags & LOAD_MINIMAL_HEADERS) && request()->context()->enable_brotli(),
+ !(request_info_.load_flags & LOAD_MINIMAL_HEADERS) && request()->context()->enable_zstd());
- if (http_user_agent_settings_) {
+ if (!(request_info_.load_flags & LOAD_MINIMAL_HEADERS) && http_user_agent_settings_) {
// Only add default Accept-Language if the request didn't have it
// specified.
std::string accept_language =
--