-
Notifications
You must be signed in to change notification settings - Fork 17
fix: strip credentials from URLs to prevent leaking auth tokens #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+131
−11
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a9635e
fix: strip credentials from URLs to prevent leaking auth tokens
69b19db
fix: black formatting and import path for pip_resolver
5692b24
address PR review feedback from romain-intel
714893a
fix: black formatting in env_descr.py is_downloadable_url
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """Tests for strip_url_credentials and safe_netloc helpers in utils.py.""" | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| sys.path.insert( | ||
| 0, | ||
| os.path.join( | ||
| os.path.dirname(__file__), | ||
| "..", | ||
| "..", | ||
| "..", | ||
| "metaflow-netflixext", | ||
| ), | ||
| ) | ||
|
|
||
| from urllib.parse import urlparse | ||
| from metaflow_extensions.nflx.plugins.conda.utils import ( | ||
| strip_url_credentials, | ||
| _safe_netloc, | ||
| ) | ||
|
|
||
|
|
||
| class TestStripUrlCredentials: | ||
| def test_no_credentials(self): | ||
| url = "https://pypi.org/simple/" | ||
| assert strip_url_credentials(url) == url | ||
|
|
||
| def test_user_and_password(self): | ||
| url = "https://user:token@private-pypi.example.com/simple/" | ||
| assert strip_url_credentials(url) == "https://private-pypi.example.com/simple/" | ||
|
|
||
| def test_user_only(self): | ||
| url = "https://user@private-pypi.example.com/simple/" | ||
| assert strip_url_credentials(url) == "https://private-pypi.example.com/simple/" | ||
|
|
||
| def test_preserves_port(self): | ||
| url = "https://user:token@private-pypi.example.com:8080/simple/" | ||
| assert ( | ||
| strip_url_credentials(url) | ||
| == "https://private-pypi.example.com:8080/simple/" | ||
| ) | ||
|
|
||
| def test_preserves_query_and_fragment(self): | ||
| url = "https://user:pass@host.com/path?q=1#frag" | ||
| assert strip_url_credentials(url) == "https://host.com/path?q=1#frag" | ||
|
|
||
| def test_file_url_unchanged(self): | ||
| url = "file:///tmp/packages/foo-1.0.tar.gz" | ||
| assert strip_url_credentials(url) == url | ||
|
|
||
| def test_empty_string(self): | ||
| assert strip_url_credentials("") == "" | ||
|
|
||
| def test_git_plus_https(self): | ||
| url = "git+https://token:x-oauth@github.com/org/repo.git@abc123" | ||
| result = strip_url_credentials(url) | ||
| assert "token" not in result | ||
| assert "x-oauth" not in result | ||
| assert "github.com" in result | ||
|
|
||
|
|
||
| class TestSafeNetloc: | ||
| def test_simple_host(self): | ||
| parsed = urlparse("https://pypi.org/simple/") | ||
| assert _safe_netloc(parsed) == "pypi.org" | ||
|
|
||
| def test_host_with_port(self): | ||
| parsed = urlparse("https://pypi.org:8080/simple/") | ||
| assert _safe_netloc(parsed) == "pypi.org:8080" | ||
|
|
||
| def test_credentials_stripped(self): | ||
| parsed = urlparse("https://user:token@private.com/simple/") | ||
| assert _safe_netloc(parsed) == "private.com" | ||
| assert "user" not in _safe_netloc(parsed) | ||
| assert "token" not in _safe_netloc(parsed) | ||
|
|
||
| def test_credentials_with_port_stripped(self): | ||
| parsed = urlparse("https://user:token@private.com:443/simple/") | ||
| assert _safe_netloc(parsed) == "private.com:443" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto