@moonpay/platform-sdk-core 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -45,8 +45,23 @@ __export(src_exports, {
45
45
  module.exports = __toCommonJS(src_exports);
46
46
 
47
47
  // src/api/client-context.ts
48
+ var DEFAULT_API_BASE_URL = "https://api.moonpay.com";
49
+ function isTrustedMoonPayUrl(value) {
50
+ let hostname;
51
+ let protocol;
52
+ try {
53
+ ({ hostname, protocol } = new URL(value));
54
+ } catch {
55
+ return false;
56
+ }
57
+ if (hostname === "localhost" || hostname === "127.0.0.1")
58
+ return true;
59
+ if (protocol !== "https:")
60
+ return false;
61
+ return hostname === "moonpay.com" || hostname.endsWith(".moonpay.com") || hostname === "moonpay.dev" || hostname.endsWith(".moonpay.dev") || hostname === "moonpay-dev.com" || hostname.endsWith(".moonpay-dev.com") || hostname === "moonpaycloud.com" || hostname.endsWith(".moonpaycloud.com");
62
+ }
48
63
  function createClientContext(options = {}) {
49
- const { apiBaseUrl = "https://api.moonpay.com" } = options;
64
+ const apiBaseUrl = options.apiBaseUrl && isTrustedMoonPayUrl(options.apiBaseUrl) ? options.apiBaseUrl : DEFAULT_API_BASE_URL;
50
65
  let _accessToken = "";
51
66
  let _clientToken = "";
52
67
  return {
@@ -63,14 +78,14 @@ function createClientContext(options = {}) {
63
78
  _clientToken = token;
64
79
  },
65
80
  fetch(url, options2) {
81
+ const resolvedUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
66
82
  const headers = {
67
83
  "Content-Type": "application/json",
68
84
  ...options2?.headers
69
85
  };
70
- if (_accessToken) {
86
+ if (_accessToken && isTrustedMoonPayUrl(resolvedUrl)) {
71
87
  headers.Authorization = `Bearer ${_accessToken}`;
72
88
  }
73
- const resolvedUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
74
89
  return fetch(resolvedUrl, { ...options2, headers });
75
90
  }
76
91
  };