Repository navigation
fix: improve url injection safeguards - #373
Open
betinacosta wants to merge 5 commits into
Open
betinacosta wants to merge 5 commits into
betinacosta wants to merge 5 commits into
Conversation
…ix/tenant-subdomain-token-url-injection
betinacosta
marked this pull request as ready for review
October 5, 2026 18:22
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.
Description
Replaces the unconstrained
str.replaceused to derive per-tenant OAuth2 token URLs inXsuaaAuthProviderwith a URL-aware substitution that only replaces the first DNS label of the configured token URL hostname.Background: When a subscriber tenant subdomain is provided for Destination Service access,
XsuaaAuthProvider._fetch_tokenpreviously derived the tenant-scoped token URL by callingstr(token_url).replace(str(identityzone), tenant_subdomain). This is URL-unaware: if theidentityzonevalue also appears in the path or query portion of the token URL, all occurrences are replaced, not just the hostname label. Although a pre-existing_validate_tenant_subdomaincall already blocks authority-injection payloads (slashes, dots, etc.), thestr.replaceapproach is semantically incorrect and a source of latent correctness bugs.Fix: A new helper
_derive_tenant_token_urlinsap_cloud_sdk.core._tenantusesurllib.parse.urlparse/urlunparseto precisely swap only the leading hostname label when it matchesidentityzone. Every other URL component — scheme, port, path, query, fragment — is preserved verbatim. If the first label does not matchidentityzone, the original URL is returned unchanged.Related Issue
Closes #
Type of Change
How to Test
test_identityzone_in_path_is_not_replacedintests/core/unit/test_http_client.py— this test fails against the oldstr.replaceimplementation and passes with_derive_tenant_token_url.Checklist
Additional Notes
_derive_tenant_token_urlis intentionally internal (prefixed_). It is co-located with_validate_tenant_subdomaininsap_cloud_sdk.core._tenantso all tenant-subdomain safety logic lives in one place.The fix has no effect on the normal happy path: a valid
identityzonethat is the first hostname label produces the same derived URL as before. Only the edge case whereidentityzonealso appears elsewhere in the URL is handled differently (correctly).