Repository navigation
Raise InvalidURL for out-of-range ports - #3883
Open
swastiktawate wants to merge 2 commits into
Open
swastiktawate wants to merge 2 commits into
swastiktawate wants to merge 2 commits into
Conversation
normalize_port() accepted any integer port, so values such as 99999, 65536, and -1 reached the socket layer. Raise InvalidURL when the port is below 0 or above 65535, and add tests covering 65536, 99999, and -1. See discussion encode#3875.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
URL() accepted out-of-range ports such as 99999, 65536, and -1, because normalize_port() only checked that int(port) works. The bad value reached the socket layer, where on Linux it wraps modulo 65536, so a request to port 99999 can reach a server on port 34463.
This change raises InvalidURL in normalize_port() when the port is below 0 or above 65535, mirroring the existing error for non-numeric ports. Port 0 is left accepted, since some parsers accept it and it is a separate decision.
Tests: added test_url_invalid_port_range in tests/models/test_url.py covering 65536, 99999, and -1. tests/models/test_url.py: 93 passed.
Fixes #3875. The bug was reported in discussion #3875 and independently reproduced there by Mickael Saidi.