@calimero-network/registry-cli 1.22.3 → 1.22.4

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
@@ -15,7 +15,7 @@ var DEFAULT_REGISTRY_URL = "https://apps.calimero.network";
15
15
  function defaultConfig() {
16
16
  return { registry: { url: DEFAULT_REGISTRY_URL } };
17
17
  }
18
- var RemoteConfig = class {
18
+ var RemoteConfig = class _RemoteConfig {
19
19
  configPath;
20
20
  config;
21
21
  constructor() {
@@ -57,7 +57,13 @@ var RemoteConfig = class {
57
57
  ...this.config.registry.apiKey ? { apiKey: this.config.registry.apiKey } : {}
58
58
  }
59
59
  };
60
- fs7.writeFileSync(this.configPath, JSON.stringify(configToSave, null, 2));
60
+ fs7.writeFileSync(this.configPath, JSON.stringify(configToSave, null, 2), {
61
+ mode: 384
62
+ });
63
+ try {
64
+ fs7.chmodSync(this.configPath, 384);
65
+ } catch {
66
+ }
61
67
  }
62
68
  /**
63
69
  * Get registry URL with priority:
@@ -72,9 +78,30 @@ var RemoteConfig = class {
72
78
  * Set registry URL
73
79
  */
74
80
  setRegistryUrl(url) {
81
+ if (_RemoteConfig.isInsecureRemoteUrl(url)) {
82
+ console.warn(
83
+ "\u26A0\uFE0F Registry URL uses http:// on a non-local host. Your API key would be sent in cleartext \u2014 prefer https:// for remote registries."
84
+ );
85
+ }
75
86
  this.config.registry.url = url;
76
87
  this.saveConfig();
77
88
  }
89
+ /**
90
+ * True when `url` is http:// to a host other than localhost/loopback, i.e. a
91
+ * Bearer token would traverse the network in cleartext.
92
+ */
93
+ static isInsecureRemoteUrl(url) {
94
+ let parsed;
95
+ try {
96
+ parsed = new URL(url);
97
+ } catch {
98
+ return false;
99
+ }
100
+ if (parsed.protocol !== "http:") return false;
101
+ const host = parsed.hostname.toLowerCase();
102
+ const isLocal = host === "localhost" || host === "127.0.0.1" || host === "::1" || host.endsWith(".localhost");
103
+ return !isLocal;
104
+ }
78
105
  /**
79
106
  * Get API key with priority:
80
107
  * 1. Environment variable CALIMERO_API_KEY