@@ -324,7 +324,7 @@ func (apiClient *ApiClient) Do(
324324 body interface {},
325325 headers http.Header ,
326326) (* http.Response , errors.Error ) {
327- uri , err := GetURIStringPointer (apiClient .endpoint , path , query )
327+ uri , err := ResolveRequestURI (apiClient .endpoint , path , query )
328328 if err != nil {
329329 return nil , errors .Default .Wrap (err , fmt .Sprintf ("Unable to construct URI from %s, %s, %s" , apiClient .endpoint , path , query ))
330330 }
@@ -453,8 +453,12 @@ func UnmarshalResponseXML(res *http.Response, v interface{}) errors.Error {
453453 return nil
454454}
455455
456- // GetURIStringPointer FIXME ...
457- func GetURIStringPointer (baseUrl string , relativePath string , query url.Values ) (* string , errors.Error ) {
456+ // ResolveRequestURI combines baseUrl, relativePath and query into the absolute URI used
457+ // for an API request. relativePath must be a relative reference (no scheme or host of its
458+ // own): url.URL.ResolveReference resolves an absolute reference by discarding the base
459+ // entirely (RFC 3986 §5.3), so an absolute or protocol-relative relativePath would silently
460+ // ignore baseUrl and target whatever host it carries instead.
461+ func ResolveRequestURI (baseUrl string , relativePath string , query url.Values ) (* string , errors.Error ) {
458462 // If the base URL doesn't end with a slash, and has a relative path attached
459463 // the values will be removed by the Go package, therefore we need to add a missing slash.
460464 AddMissingSlashToURL (& baseUrl )
@@ -468,6 +472,9 @@ func GetURIStringPointer(baseUrl string, relativePath string, query url.Values)
468472 if err != nil {
469473 return nil , errors .Convert (err )
470474 }
475+ if u .IsAbs () || u .Host != "" {
476+ return nil , errors .BadInput .New (fmt .Sprintf ("relativePath must be a relative path, not an absolute URL: %s" , relativePath ))
477+ }
471478 if query != nil {
472479 queryString := u .Query ()
473480 for key , values := range query {
0 commit comments