-
-
Notifications
You must be signed in to change notification settings - Fork 795
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
Add localhost to allowed loopback addresses #1423
Changes from all commits
c77092f
f083d92
dfb29c6
99f083b
ae54867
e7ef89c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -778,7 +778,7 @@ def redirect_to_uri_allowed(uri, allowed_uris): | |||||
|
||||||
allowed_uri_is_loopback = ( | ||||||
parsed_allowed_uri.scheme == "http" | ||||||
and parsed_allowed_uri.hostname in ["127.0.0.1", "::1"] | ||||||
and parsed_allowed_uri.hostname in ["127.0.0.1", "::1", "localhost"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a setting along these lines"
Suggested change
|
||||||
and parsed_allowed_uri.port is None | ||||||
) | ||||||
if ( | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,9 +205,8 @@ def test_validate_authorization_request_unsafe_query(self): | |
|
||
@pytest.mark.parametrize( | ||
"uri, expected_result", | ||
# localhost is _not_ a loopback URI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh I'm sorry I put you through creating this PR, but according to RFC8252:
Given this, I think the default should remain as is, perhaps with a setting added to allow one to override the default to allow localhost. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh it's fine, no worries at all. Thanks for taking the time looking at it! |
||
[ | ||
("http://localhost:3456", False), | ||
("http://localhost:3456", True), # localhost is supported | ||
# only http scheme is supported for loopback URIs | ||
("https://127.0.0.1:3456", False), | ||
("http://127.0.0.1:3456", True), | ||
|
@@ -216,7 +215,7 @@ def test_validate_authorization_request_unsafe_query(self): | |
], | ||
) | ||
def test_uri_loopback_redirect_check(uri, expected_result): | ||
allowed_uris = ["http://127.0.0.1", "http://[::1]"] | ||
allowed_uris = ["http://127.0.0.1", "http://[::1]", "http://localhost"] | ||
if expected_result: | ||
assert redirect_to_uri_allowed(uri, allowed_uris) | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
@pytest.mark.usefixtures("oauth2_settings") | ||
class TestValidators(TestCase): | ||
def test_validate_good_uris(self): | ||
validator = RedirectURIValidator(allowed_schemes=["https"]) | ||
validator = RedirectURIValidator(allowed_schemes=["https", "http"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why you changed this to add http. |
||
good_uris = [ | ||
"https://example.com/", | ||
"https://example.org/?key=val", | ||
|
@@ -17,20 +17,22 @@ def test_validate_good_uris(self): | |
"https://1.1.1.1", | ||
"https://127.0.0.1", | ||
"https://255.255.255.255", | ||
"http://localhost", | ||
] | ||
for uri in good_uris: | ||
# Check ValidationError not thrown | ||
validator(uri) | ||
|
||
def test_validate_custom_uri_scheme(self): | ||
validator = RedirectURIValidator(allowed_schemes=["my-scheme", "https", "git+ssh"]) | ||
validator = RedirectURIValidator(allowed_schemes=["my-scheme", "https", "git+ssh", "http"]) | ||
good_uris = [ | ||
"my-scheme://example.com", | ||
"my-scheme://example", | ||
"my-scheme://localhost", | ||
"https://example.com", | ||
"HTTPS://example.com", | ||
"git+ssh://example.com", | ||
"http://localhost", | ||
] | ||
for uri in good_uris: | ||
# Check ValidationError not thrown | ||
|
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.
Per comment referencing RFC8252, please change this to a setting with the default as is without
localhost
.