Skip to content

fix(connect): prevent URL host confusion in Url join#467

Open
tdstein wants to merge 1 commit intomainfrom
fix/urljoin-host-confusion
Open

fix(connect): prevent URL host confusion in Url join#467
tdstein wants to merge 1 commit intomainfrom
fix/urljoin-host-confusion

Conversation

@tdstein
Copy link
Copy Markdown
Collaborator

@tdstein tdstein commented Apr 9, 2026

Summary

Hardens URL composition in posit.connect.urls so a protocol-relative (//evil/...) or fully-qualified (https://evil/...) path fragment cannot retarget the configured Connect base URL.

  • Adds _assert_same_origin(base, resolved) check inside Url._append — the hot path used by every cfg.url + path call in the client. Raises ValueError on mismatch (scheme, host, or port).
  • Adds a public safe_urljoin(base, fragment) helper for any future call site that needs urljoin semantics — lstrips leading /, urljoins, then asserts same origin.
  • No existing call sites needed rewriting; Url + path already routed through _append.

Test plan

  • 11 new cases in tests/posit/connect/test_urls.py:
    • relative / absolute-from-root / normal
    • protocol-relative //evil neutralized (and rejected by safe_urljoin)
    • absolute https://evil neutralized (and rejected by safe_urljoin)
    • port mismatch rejected
  • Full tests/posit/connect/ suite: 356 passed
  • CI

Add a same-origin assertion to the internal _append used by Url, and
introduce urls.safe_urljoin() for cases that need explicit urljoin
semantics. Both refuse to resolve a fragment to a different
scheme/host/port than the configured Connect base URL, defending
against user- or server-supplied fragments like "//evil" or
"https://evil" that would otherwise escape the base URL.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2373 2223 94% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/posit/connect/urls.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 0d6de44 by action🐍

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.

1 participant