Skip to content

fix: percent-encode userinfo in add_http_basic_auth - #69457

Open
zza-830 wants to merge 2 commits into
saltstack:masterfrom
zza-830:master
Open

fix: percent-encode userinfo in add_http_basic_auth#69457
zza-830 wants to merge 2 commits into
saltstack:masterfrom
zza-830:master

Conversation

@zza-830

@zza-830 zza-830 commented Jun 16, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes add_http_basic_auth to percent-encode user and password fields per RFC 3986 §3.2.1.

Problem

Passwords containing special characters (+, /, @, :, etc.) were inserted verbatim into the URL userinfo component. This caused URL parsing errors like Port number ended with 'N' when the password contained these characters.

Solution

Uses urllib.parse.quote() on both user and password fields before constructing the netloc. Alphanumeric characters and -, _, ., ~ are left unencoded (safe by default in quote()).

Example

# Before: broken
add_http_basic_auth(url, user='someUser', password='some+Generated/Password')
# => 'https://someUser:some+Generated/Password@example.com'  # '+' and '/' break URL parsing

# After: correct
add_http_basic_auth(url, user='someUser', password='some+Generated/Password')
# => 'https://someUser:some%2BGenerated%2FPassword@example.com'

Fixes #55561

RFC 3986 section 3.2.1 requires userinfo (user/password) to be
percent-encoded. Passwords containing special characters were not
encoded, causing URL parsing errors.

Now uses urllib.parse.quote on both user and password fields.

Fixes saltstack#55561
@zza-830
zza-830 requested a review from a team as a code owner June 16, 2026 07:04
@dwoz dwoz added the test:full Run the full test suite label Jun 16, 2026
@dwoz dwoz added this to the Potassium v3009.0 milestone Jun 16, 2026
Adds changelog/55561.fixed.md describing the userinfo percent-encoding
fix and reformats tests/unit/utils/test_url.py to match black's line
length rules.
@twangboy

Copy link
Copy Markdown
Contributor

Please create this against the earliest branch where the bug exists, probably 3006.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

salt.utils.url fails to properly quote URL userinfo

3 participants