Node operators register RPC endpoints that carry credentials, such as https://user:secret@node.example.com. The URL validator checks the part before the @ (the user info) too loosely in some places and too strictly in ot…
Node operators register RPC endpoints that carry credentials, such as https://user:secret@node.example.com. The URL validator checks the part before the @ (the user info) too loosely in some places and too strictly in others: valid endpoints are refused and broken ones are stored.
from marshmallow import validate
url = validate.URL()
url("http://:pass@example.com") # 1. empty user name
url("http://user:pa:ss@example.com") # 2. colon in the password
url("http://user name@example.com") # 3. space in the user name
url("http://%0G@example.com") # 4. broken percent escape
1 and 2 return the URL. 3 and 4 raise ValidationError: Not a valid URL.
1 and 2 raise ValidationError: Not a valid URL. 3 and 4 return the URL.
The user info, when present, is everything between :// and the @ in front of the host. Following RFC 3986 it may be empty and may contain, any number of times and in any order:
- . _ ~! $ & ' ( ) * + , ; =:% followed by two hexadecimal digitsNothing else is allowed there: no spaces, no /, no ^, no non-ASCII letters, no second @. URLs without user info, and http://user:pass@example.com, keep working.
Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
url-validator-user-info-rules
Changes under src/ are evaluated.