Skip to content

Commit c1d02f2

Browse files
committed
Fix psf#6990: Preserve full URI path in digest auth when URL contains semicolons
1 parent ef439eb commit c1d02f2

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/requests/auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def sha512_utf8(x):
183183
p_parsed = urlparse(url)
184184
#: path is request-uri defined in RFC 2616 which should not be empty
185185
path = p_parsed.path or "/"
186+
if p_parsed.params:
187+
path += f";{p_parsed.params}"
186188
if p_parsed.query:
187189
path += f"?{p_parsed.query}"
188190

tests/test_digestauth.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Tests for Digest Auth URI handling (issue #6990)."""
2+
3+
import requests
4+
from requests.auth import HTTPDigestAuth
5+
6+
7+
def test_digest_auth_uri_includes_semicolon_params():
8+
"""Digest auth URI must include semicolon path parameters (issue #6990)."""
9+
auth = HTTPDigestAuth("user", "pass")
10+
auth._thread_local.chal = {
11+
"realm": "testrealm",
12+
"nonce": "testnonce",
13+
"qop": "auth",
14+
}
15+
auth._thread_local.last_nonce = ""
16+
auth._thread_local.nonce_count = 0
17+
18+
url = "http://example.com/path;jsessionid=abc123?q=1"
19+
header = auth.build_digest_header("GET", url)
20+
21+
assert 'uri="/path;jsessionid=abc123?q=1"' in header
22+
23+
24+
def test_digest_auth_uri_without_semicolon_params():
25+
"""Digest auth URI is unchanged for URLs without semicolon path params."""
26+
auth = HTTPDigestAuth("user", "pass")
27+
auth._thread_local.chal = {
28+
"realm": "testrealm",
29+
"nonce": "testnonce",
30+
"qop": "auth",
31+
}
32+
auth._thread_local.last_nonce = ""
33+
auth._thread_local.nonce_count = 0
34+
35+
url = "http://example.com/path?q=1"
36+
header = auth.build_digest_header("GET", url)
37+
38+
assert 'uri="/path?q=1"' in header

0 commit comments

Comments
 (0)