-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-46756: Fix authorization check in urllib.request #31353
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
Changes from all commits
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 |
---|---|---|
|
@@ -164,7 +164,6 @@ def test_password_manager(self): | |
self.assertEqual(find_user_pass("Some Realm", | ||
"http://example.com/spam"), | ||
('joe', 'password')) | ||
|
||
self.assertEqual(find_user_pass("Some Realm", | ||
"http://example.com/spam/spam"), | ||
('joe', 'password')) | ||
|
@@ -173,12 +172,29 @@ def test_password_manager(self): | |
|
||
add("c", "http://example.com/foo", "foo", "ni") | ||
add("c", "http://example.com/bar", "bar", "nini") | ||
add("c", "http://example.com/foo/bar", "foobar", "nibar") | ||
|
||
self.assertEqual(find_user_pass("c", "http://example.com/foo"), | ||
('foo', 'ni')) | ||
|
||
self.assertEqual(find_user_pass("c", "http://example.com/bar"), | ||
('bar', 'nini')) | ||
self.assertEqual(find_user_pass("c", "http://example.com/foo/"), | ||
('foo', 'ni')) | ||
self.assertEqual(find_user_pass("c", "http://example.com/foo/bar"), | ||
('foo', 'ni')) | ||
self.assertEqual(find_user_pass("c", "http://example.com/foo/baz"), | ||
('foo', 'ni')) | ||
self.assertEqual(find_user_pass("c", "http://example.com/foobar"), | ||
(None, None)) | ||
|
||
add("c", "http://example.com/baz/", "baz", "ninini") | ||
|
||
self.assertEqual(find_user_pass("c", "http://example.com/baz"), | ||
(None, None)) | ||
Comment on lines
+192
to
+193
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. I am not sure about this test. Should 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. I am not sure. I think, this test, which doesn't consider If there is any reference to this in any rfc or any other software behavior that will be helpful as a validation. |
||
self.assertEqual(find_user_pass("c", "http://example.com/baz/"), | ||
('baz', 'ninini')) | ||
self.assertEqual(find_user_pass("c", "http://example.com/baz/bar"), | ||
('baz', 'ninini')) | ||
|
||
# For the same path, newer password should be considered. | ||
|
||
|
@@ -1658,8 +1674,9 @@ def test_basic_prior_auth_auto_send(self): | |
auth_prior_handler.add_password( | ||
None, request_url, user, password, is_authenticated=True) | ||
|
||
is_auth = pwd_manager.is_authenticated(request_url) | ||
self.assertTrue(is_auth) | ||
self.assertTrue(pwd_manager.is_authenticated(request_url)) | ||
self.assertTrue(pwd_manager.is_authenticated(request_url + '/nested')) | ||
self.assertFalse(pwd_manager.is_authenticated(request_url + 'plain')) | ||
|
||
opener = OpenerDirector() | ||
opener.add_handler(auth_prior_handler) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Fix a bug in :meth:`urllib.request.HTTPPasswordMgr.find_user_password` and | ||
:meth:`urllib.request.HTTPPasswordMgrWithPriorAuth.is_authenticated` which | ||
allowed to bypass authorization. For example, access to URI | ||
``example.org/foobar`` was allowed if the user was authorized for URI | ||
``example.org/foo``. |
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.
This line
along with this test a line 184 confuses me.
/foo
path's password will be used. A comment above line 175 will be helpful./foo/bar
have it's own username:password?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.
This behavior seems intentional. See a comment at line 155: "For the same realm, password set the highest path is the winner." Tests at lines 158, 164 and 167 ensure this, but only for the root path. I added new tests for non-root path.
Should I repeat this comment above line 175?
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.
Oh I see. I missed seeing the context in the diff. I notice an example illustrating the behavior for the comment already present in line 149 and line 150.
So, I don't think we need another comment. Thank you.