fix: validate destination tenant subdomain - #345
Merged
Merged
Conversation
…ix/validate-destination-tenant-subdomain
betinacosta
marked this pull request as ready for review
September 18, 2026 14:26
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
Adds strict RFC 1123 DNS-label validation to
XsuaaAuthProvider._fetch_tokenbefore the subscriber tenant subdomain is interpolated into the OAuth token URL.Previously, the
tenantstring accepted by every public Destination (and other service) client method was forwarded unchanged into astr.replacecall on the token URL. Becausestr.replacehas no URL awareness, a value containing URL delimiters — for exampleevil.example/oauth/token?ignore=— would change the parsed authority of the token URL to an attacker-chosen hostname while moving the trusted authentication suffix into a query parameter. The binding'sclient_idandclient_secretwould then be posted to that endpoint; standard TLS verification does not block this because it verifies the attacker-chosen authority rather than the intended one.The fix calls
_validate_tenant_subdomainbefore any URL manipulation. The function enforces the regex^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$and raisesValueErrorimmediately if the value is not a single valid DNS label. This ensures only the provider identity-zone label in the token URL can be replaced, preserving the trusted authentication origin.The validation is placed in
XsuaaAuthProvider(sap_cloud_sdk.core.protocol.http.models) rather than in any individual service module so that all SDK clients using XSUAA client-credentials flow are protected uniformly.Related Issue
Closes #
Type of Change
How to Test
XsuaaAuthProviderwith a synthetic config (anytoken_url,identityzone,client_id,client_secret).provider._fetch_token("evil.example/oauth/token?ignore=")— expectValueError: Invalid tenant_subdomain.provider._fetch_token("tenant-123")— expect normal token acquisition (no error).All 6 new tests should pass; no existing tests should regress.
Checklist
Additional Notes
_validate_tenant_subdomainis intentionally private (sap_cloud_sdk.core._tenant). It is not part of the public API.tenant_subdomainisNone) are unaffected; the validation is guarded bytenant_subdomain is not None.ValueErrorat token-acquisition time rather than silently routing credentials to an unintended endpoint. This is the intended behavior change.