Skip to content

Add URL escaping/unescaping for winhttp URL functions.#353

Open
zooba wants to merge 3 commits into
python:mainfrom
zooba:gh-351
Open

Add URL escaping/unescaping for winhttp URL functions.#353
zooba wants to merge 3 commits into
python:mainfrom
zooba:gh-351

Conversation

@zooba
Copy link
Copy Markdown
Member

@zooba zooba commented May 29, 2026

Fixes #351

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes #351 by making the WinHTTP URL helpers percent-decode userinfo (and host/path where appropriate) and percent-encode user/password when re-assembling URLs, so that HTTP Basic auth credentials with reserved characters (e.g. @ in SAML/SSO emails) are transmitted correctly. The native helpers also keep an "env-var" escape hatch so that %NAME% placeholders are passed through untouched and sanitise_url is updated to mirror that on both the username and password fields.

Changes:

  • Introduce native escape_url_part/unescape_url_part helpers in winhttp.cpp and rewire winhttp_urlopen, winhttp_urlsplit, and winhttp_urlunsplit to decode userinfo/host/path and re-encode credentials, dropping the previous add_nuls/mutating-URL approach.
  • Update sanitise_url to also preserve %...%-style usernames (not just passwords) and fix a typo where the password check called startswith twice.
  • Add tests for sanitising encoded credentials, round-tripping encoded userinfo through unsanitise_url, percent-decoded credentials in extract_url_auth, and urljoin behavior with %XX segments.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/_native/winhttp.cpp Adds escape/unescape helpers, decodes host/path/credentials before use, re-encodes credentials on unsplit, and switches WinHttpCreateUrl away from ICU_ESCAPE.
src/manage/urlutils.py sanitise_url now preserves env-var-style usernames and correctly checks password suffix.
tests/test_urlutils.py Adds sanitise/unsanitise/extract_url_auth cases for percent-encoded userinfo and urljoin cases for encoded path segments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_urlutils.py Outdated
Comment thread tests/test_urlutils.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract_url_auth does not percent-decode URL userinfo, breaking HTTP Basic auth for usernames containing '@' (e.g. SAML/SSO email identities)

2 participants