Repository navigation
Reject trailing newline in percent-decoded URL userinfo - #604
Open
shashank11yadav wants to merge 1 commit into
Open
shashank11yadav wants to merge 1 commit into
shashank11yadav wants to merge 1 commit into
Conversation
A userinfo with two or more colons is percent-decoded before it is matched against the username regex. A decoded newline in the middle was rejected, but one at the very end was accepted, because `$` also matches just before a trailing newline. Anchor the dot-atom and non-quoted-string branches with `\Z` so both positions agree.
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.
Fixes #603
validators.url()percent-decodes a userinfo that has two or more colons before matching it against the username regex. A decoded newline in the middle of that userinfo was rejected, but the same newline at the very end was accepted. The closing$in two branches of_username_regexalso matches just before a trailing newline. Sourl("http://a:b:c%0A@example.com")returned True, whileurl("http://a:b:c%0Ad@example.com")returned a ValidationError.This PR changes those two closing
$anchors to\Z(the dot-atom and non-quoted-string branches insrc/validators/url.py). Only a value that ends in exactly one newline changes behaviour. The extended-Latin branch is not touched.This is a consistency fix in the same class as #492 and #513, which made
slug()and the hostname and port checks reject a trailing newline. It is not a claim that RFC 3986 forbids%0Ain userinfo. Path and query still accept percent-encoded controls, and this PR does not change that.Tests: one parametrized test,
test_returns_failed_validation_on_newline_in_decoded_userinfointests/test_url.py, with six cases. Three trailing-newline cases fail before the fix and pass after it. The other three (a newline in the middle, at the start, and two trailing newlines) were already rejected and stay rejected.How it was tested (commit 36c82f4):
uv run --no-sync pytest tests/test_url.py: 334 passed.uv run --no-sync pytest tests/test_url.py -k test_returns_failed_validation_on_newline_in_decoded_userinfo: 6 passed.uv run --no-sync ruff check .: pass.uv run --no-sync ruff format --check .: pass.Not run: pyright (
uv run --no-sync pyright ., which CI runs) and bandit (uv run --no-sync bandit -c pyproject.toml -r src/validators, which CI runs). Neither was run for this change.