Skip to content

Commit accff72

Browse files
authored
Merge pull request from GHSA-34jh-p97f-mpxf
* Strip Proxy-Authorization header on redirects * Fix test_retry_default_remove_headers_on_redirect * Set release date
1 parent 34be4a5 commit accff72

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.2.2 (2024-06-17)
2+
==================
3+
4+
- Added the ``Proxy-Authorization`` header to the list of headers to strip from requests when redirecting to a different host. As before, different headers can be set via ``Retry.remove_headers_on_redirect``.
5+
16
2.2.1 (2024-02-16)
27
==================
38

src/urllib3/util/retry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ class Retry:
189189
RETRY_AFTER_STATUS_CODES = frozenset([413, 429, 503])
190190

191191
#: Default headers to be used for ``remove_headers_on_redirect``
192-
DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset(["Cookie", "Authorization"])
192+
DEFAULT_REMOVE_HEADERS_ON_REDIRECT = frozenset(
193+
["Cookie", "Authorization", "Proxy-Authorization"]
194+
)
193195

194196
#: Default maximum backoff time.
195197
DEFAULT_BACKOFF_MAX = 120

test/test_retry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ def test_retry_method_not_allowed(self) -> None:
334334
def test_retry_default_remove_headers_on_redirect(self) -> None:
335335
retry = Retry()
336336

337-
assert retry.remove_headers_on_redirect == {"authorization", "cookie"}
337+
assert retry.remove_headers_on_redirect == {
338+
"authorization",
339+
"proxy-authorization",
340+
"cookie",
341+
}
338342

339343
def test_retry_set_remove_headers_on_redirect(self) -> None:
340344
retry = Retry(remove_headers_on_redirect=["X-API-Secret"])

test/with_dummyserver/test_poolmanager.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,30 @@ def test_redirect_cross_host_remove_headers(self) -> None:
144144
"GET",
145145
f"{self.base_url}/redirect",
146146
fields={"target": f"{self.base_url_alt}/headers"},
147-
headers={"Authorization": "foo", "Cookie": "foo=bar"},
147+
headers={
148+
"Authorization": "foo",
149+
"Proxy-Authorization": "bar",
150+
"Cookie": "foo=bar",
151+
},
148152
)
149153

150154
assert r.status == 200
151155

152156
data = r.json()
153157

154158
assert "Authorization" not in data
159+
assert "Proxy-Authorization" not in data
155160
assert "Cookie" not in data
156161

157162
r = http.request(
158163
"GET",
159164
f"{self.base_url}/redirect",
160165
fields={"target": f"{self.base_url_alt}/headers"},
161-
headers={"authorization": "foo", "cookie": "foo=bar"},
166+
headers={
167+
"authorization": "foo",
168+
"proxy-authorization": "baz",
169+
"cookie": "foo=bar",
170+
},
162171
)
163172

164173
assert r.status == 200
@@ -167,6 +176,8 @@ def test_redirect_cross_host_remove_headers(self) -> None:
167176

168177
assert "authorization" not in data
169178
assert "Authorization" not in data
179+
assert "proxy-authorization" not in data
180+
assert "Proxy-Authorization" not in data
170181
assert "cookie" not in data
171182
assert "Cookie" not in data
172183

@@ -176,7 +187,11 @@ def test_redirect_cross_host_no_remove_headers(self) -> None:
176187
"GET",
177188
f"{self.base_url}/redirect",
178189
fields={"target": f"{self.base_url_alt}/headers"},
179-
headers={"Authorization": "foo", "Cookie": "foo=bar"},
190+
headers={
191+
"Authorization": "foo",
192+
"Proxy-Authorization": "bar",
193+
"Cookie": "foo=bar",
194+
},
180195
retries=Retry(remove_headers_on_redirect=[]),
181196
)
182197

@@ -185,6 +200,7 @@ def test_redirect_cross_host_no_remove_headers(self) -> None:
185200
data = r.json()
186201

187202
assert data["Authorization"] == "foo"
203+
assert data["Proxy-Authorization"] == "bar"
188204
assert data["Cookie"] == "foo=bar"
189205

190206
def test_redirect_cross_host_set_removed_headers(self) -> None:
@@ -196,6 +212,7 @@ def test_redirect_cross_host_set_removed_headers(self) -> None:
196212
headers={
197213
"X-API-Secret": "foo",
198214
"Authorization": "bar",
215+
"Proxy-Authorization": "baz",
199216
"Cookie": "foo=bar",
200217
},
201218
retries=Retry(remove_headers_on_redirect=["X-API-Secret"]),
@@ -207,11 +224,13 @@ def test_redirect_cross_host_set_removed_headers(self) -> None:
207224

208225
assert "X-API-Secret" not in data
209226
assert data["Authorization"] == "bar"
227+
assert data["Proxy-Authorization"] == "baz"
210228
assert data["Cookie"] == "foo=bar"
211229

212230
headers = {
213231
"x-api-secret": "foo",
214232
"authorization": "bar",
233+
"proxy-authorization": "baz",
215234
"cookie": "foo=bar",
216235
}
217236
r = http.request(
@@ -229,12 +248,14 @@ def test_redirect_cross_host_set_removed_headers(self) -> None:
229248
assert "x-api-secret" not in data
230249
assert "X-API-Secret" not in data
231250
assert data["Authorization"] == "bar"
251+
assert data["Proxy-Authorization"] == "baz"
232252
assert data["Cookie"] == "foo=bar"
233253

234254
# Ensure the header argument itself is not modified in-place.
235255
assert headers == {
236256
"x-api-secret": "foo",
237257
"authorization": "bar",
258+
"proxy-authorization": "baz",
238259
"cookie": "foo=bar",
239260
}
240261

0 commit comments

Comments
 (0)