@farm.js/create-app 0.1.0-beta.91 → 0.1.0-beta.93

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.js CHANGED
@@ -2671,18 +2671,21 @@ function isInteractive() {
2671
2671
  return process.stdin.isTTY === true && process.stdout.isTTY === true;
2672
2672
  }
2673
2673
  function getEndpoint() {
2674
- const candidate = process.env.FARM_TELEMETRY_ENDPOINT || DEFAULT_TELEMETRY_ENDPOINT;
2674
+ return process.env.FARM_TELEMETRY_ENDPOINT || DEFAULT_TELEMETRY_ENDPOINT;
2675
+ }
2676
+ function resolveTelemetryEndpoint(candidate) {
2675
2677
  try {
2676
2678
  const url = new URL(candidate);
2679
+ const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
2677
2680
  const isLocal = [
2678
2681
  "localhost",
2679
2682
  "127.0.0.1",
2680
2683
  "::1"
2681
- ].includes(url.hostname);
2682
- if (url.protocol !== "https:" && !(url.protocol === "http:" && isLocal)) return DEFAULT_TELEMETRY_ENDPOINT;
2683
- return url.toString();
2684
+ ].includes(hostname);
2685
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && isLocal)) return;
2686
+ return url;
2684
2687
  } catch {
2685
- return DEFAULT_TELEMETRY_ENDPOINT;
2688
+ return;
2686
2689
  }
2687
2690
  }
2688
2691
  async function resolveState() {
@@ -2810,18 +2813,12 @@ async function send(payload) {
2810
2813
  debug("delivery failed after retries");
2811
2814
  }
2812
2815
  async function sendOnce(payload) {
2813
- let endpoint;
2814
- try {
2815
- endpoint = new URL(getEndpoint());
2816
- } catch {
2817
- debug("invalid endpoint URL");
2816
+ const endpoint = resolveTelemetryEndpoint(getEndpoint());
2817
+ if (!endpoint) {
2818
+ debug("invalid or insecure telemetry endpoint; event skipped");
2818
2819
  return "rejected";
2819
2820
  }
2820
2821
  const requestTransport = endpoint.protocol === "http:" ? node_http.request : node_https.request;
2821
- if (endpoint.protocol !== "http:" && endpoint.protocol !== "https:") {
2822
- debug(`unsupported endpoint protocol ${endpoint.protocol}`);
2823
- return "rejected";
2824
- }
2825
2822
  const body = JSON.stringify(payload);
2826
2823
  return new Promise((resolve) => {
2827
2824
  let settled = false;