Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_netrc_auth(url, raise_errors=False):

try:
_netrc = netrc(netrc_path).authenticators(host)
if _netrc:
if _netrc and any(_netrc):
# Return with login / password
login_i = 0 if _netrc[0] else 1
return (_netrc[login_i], _netrc[2])
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ def test_not_vulnerable_to_bad_url_parsing(self, tmp_path, monkeypatch):
auth = get_netrc_auth("http://example.com:@evil.com/'")
assert auth is None

def test_empty_default_credentials_ignored(self, tmp_path, monkeypatch):
"""Empty default credentials should not be returned."""
netrc_path = tmp_path / ".netrc"
monkeypatch.setenv("NETRC", str(netrc_path))
with open(netrc_path, "w") as f:
f.write("machine example.com login user password pass\ndefault\n")

auth = get_netrc_auth("http://httpbin.org/")
assert auth is None


class TestToKeyValList:
@pytest.mark.parametrize(
Expand Down
Loading