Repository navigation
private=False is ignored for IPv6 hosts in hostname() and url()
#591
yuchengshen931122-creator
started this conversation in
Security
Replies: 1 comment
|
A note on history that we missed when writing this. #451, #452 and #453 added a What is described above is what remains while that is open: (Prepared with the help of an AI assistant.) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello, and thank you for maintaining
validators.While writing specification-based tests for a university software-testing course project (NYCU, Taiwan), we noticed that the
privateflag ofhostname()andurl()only takes effect for IPv4 hosts. We are raising it in this category becauseSECURITY.mdpoints here, and because code that relies onprivate=Falseto keep requests away from internal hosts is affected.What the documentation says
hostname()andurl():What happens (0.36.0,
masterat 22786cc, Python 3.13)Cause
In
hostname()the flag is passed on toipv4(..., private=private)only.ipv6()has noprivateparameter, so every syntactically valid IPv6 host is accepted whatever the flag says.Why it may matter
An application that calls
url(user_input, private=False)before fetching the URL, as a simple guard against server-side request forgery, can be bypassed with an IPv6 literal such ashttp://[::1]/orhttp://[::ffff:169.254.169.254]/.Possible directions
ipv6()aprivateparameter based on the properties ofipaddress.IPv6Address(is_private,is_loopback,is_link_local, andipv4_mappedfor mapped addresses), and pass it on fromhostname(); orWe are happy to open a pull request with tests for whichever direction you prefer.
Found with a decision table over "kind of host ×
private" while designing tests from the docstrings. The behaviour above was reproduced against the commit named; the analysis and this text were prepared with the help of an AI assistant (Claude Code).All reactions