@infosupport/huddle-cli 0.0.0-experiment-66.38.1 → 0.0.0-experiment-66.40.1

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.
@@ -33,9 +33,14 @@ function parseIssueNumber(raw) {
33
33
  * itself (install + restart) is done by self-update.ts. On a switch this
34
34
  * function does not return (process.exit with the exit code of the new process).
35
35
  */
36
- function ensureCliForChannel(relaunchArgs) {
36
+ function ensureCliForChannel(relaunchArgs, opts = {}) {
37
37
  const wanted = (0, config_1.activeExperiment)();
38
- if (wanted === cliExperiment())
38
+ // Normally we only switch when the experiment NUMBER differs — otherwise every
39
+ // command would reinstall. But `huddle experiment use <n>` must pick up a newer
40
+ // build of the SAME experiment (the CLI version is baked in, so the number
41
+ // alone can't tell 66.34 from 66.35): force a reinstall of the channel tag,
42
+ // which npm resolves to the latest build for that experiment.
43
+ if (!opts.force && wanted === cliExperiment())
39
44
  return;
40
45
  const spec = wanted !== undefined ? `${self_update_1.CLI_PACKAGE}@experiment-${wanted}` : `${self_update_1.CLI_PACKAGE}@latest`;
41
46
  try {
@@ -56,7 +61,9 @@ async function runExperimentUse(issue, initOpts = {}) {
56
61
  console.log((0, utils_1.green)(`Experiment ${issue} activated`) + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
57
62
  const relaunchArgs = ['init', ...(initOpts.runtime ? ['--runtime', initOpts.runtime] : [])];
58
63
  try {
59
- ensureCliForChannel(relaunchArgs);
64
+ // Force: `use` always (re)installs the latest build of the target experiment,
65
+ // even when already on that experiment number, so a republished build lands.
66
+ ensureCliForChannel(relaunchArgs, { force: true });
60
67
  }
61
68
  catch (err) {
62
69
  // Activation failed → roll back the config so a subsequent `huddle init`
package/dist/firewall.js CHANGED
@@ -109,7 +109,11 @@ async function runFirewallDelete(opts) {
109
109
  qs.set('container', opts.container);
110
110
  const query = qs.toString();
111
111
  const rules = await (0, api_1.get)(`/api/rules${query ? `?${query}` : ''}`);
112
- const matches = rules.filter((r) => r.domain === target);
112
+ // Hostnames are case-insensitive everywhere else in the firewall stack, so
113
+ // match the domain case-insensitively — a rule stored as `GitHub.com` must be
114
+ // deletable by typing `github.com`.
115
+ const needle = target.toLowerCase();
116
+ const matches = rules.filter((r) => r.domain.toLowerCase() === needle);
113
117
  if (matches.length === 0) {
114
118
  const scope = opts.container ? ` for container ${opts.container}` : '';
115
119
  throw new Error(`No firewall rule found for "${target}"${scope}.`);
package/dist/init.js CHANGED
@@ -145,15 +145,10 @@ async function runInit(opts, images) {
145
145
  // network (moby/moby#36174). Which source IP the gateway sees for forwarded
146
146
  // traffic no longer matters — the control plane authenticates with the
147
147
  // operator token instead of source-IP filtering.
148
- // Team-managed firewall-rules folder (#69): the gateway can only read folders
149
- // the CLI binds into its container, so mount the configured host folder at the
150
- // same path (so the path stored in the DB setting resolves identically inside
151
- // the gateway). Read-only — Huddle never writes back to the team's Git folder.
152
- // Bind the CLI config dir (~/.huddle) read-write so the gateway/portal can
153
- // read and write the team-folder paths there (config.json is the single
154
- // source of truth). Then bind each configured team folder to a FIXED path so
155
- // the gateway reads it without ever knowing the host path. Read-only — Huddle
156
- // never writes back to the team's Git folders.
148
+ // Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
149
+ // the gateway/portal read and write the folder paths there (config.json is the
150
+ // single source of truth), then bind each configured team folder to a FIXED
151
+ // path so the gateway reads it without knowing the host path. Read-only.
157
152
  const fwFolder = cfg.firewallRulesFolder?.trim();
158
153
  const extFolder = cfg.extensionsFolder?.trim();
159
154
  const homeMountFlag = ` -v "${config_1.CONFIG_DIR}:/huddle-home:rw" -e HUDDLE_HOME_DIR=/huddle-home`;
@@ -171,7 +166,7 @@ async function runInit(opts, images) {
171
166
  ` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
172
167
  ` -p ${HOST_PORT}:3000` +
173
168
  ` -v ${VOLUME}:/data` +
174
- ` -v ${runtime.socketPath}:/var/run/docker.sock` +
169
+ ` -v "${runtime.socketPath}:/var/run/docker.sock"` +
175
170
  ` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
176
171
  homeMountFlag +
177
172
  fwMountFlag +
package/dist/migrate.js CHANGED
@@ -123,6 +123,7 @@ function buildOverride(compose, opts = {}) {
123
123
  const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
124
124
  const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
125
125
  const warnings = [];
126
+ const blockers = [];
126
127
  const marked = findMarkedNetworks(compose);
127
128
  if (marked.length === 0) {
128
129
  throw new Error(`No network marked with \`${exports.HUDDLE_NETWORK_LABEL}: "true"\` was found. ` +
@@ -132,17 +133,25 @@ function buildOverride(compose, opts = {}) {
132
133
  throw new Error(`Multiple networks marked with \`${exports.HUDDLE_NETWORK_LABEL}\`: ${marked.join(', ')}. Mark exactly one.`);
133
134
  }
134
135
  const markedNetwork = marked[0];
135
- // Pick a collision-free key for the injected egress network.
136
- const existingNetKeys = new Set(Object.keys(compose.networks ?? {}));
136
+ // Pick a key for the injected egress network that collides with NOTHING: not
137
+ // an existing network, and not the marked network itself (otherwise the two
138
+ // keys in the service's `networks` map below collapse into one and the egress
139
+ // net is silently never added). Keep suffixing until it is unique.
140
+ const taken = new Set(Object.keys(compose.networks ?? {}));
141
+ taken.add(markedNetwork);
137
142
  let huddleNetKey = opts.huddleNetKey ?? exports.HUDDLE_NET_KEY;
138
- if (existingNetKeys.has(huddleNetKey) && huddleNetKey !== markedNetwork) {
139
- huddleNetKey = `${exports.HUDDLE_NET_KEY}-egress`;
143
+ if (taken.has(huddleNetKey)) {
144
+ let n = 0;
145
+ do {
146
+ huddleNetKey = n === 0 ? `${exports.HUDDLE_NET_KEY}-egress` : `${exports.HUDDLE_NET_KEY}-egress-${n}`;
147
+ n++;
148
+ } while (taken.has(huddleNetKey));
140
149
  }
141
150
  // Guardrail: the marked network must be internal, otherwise it already has a
142
151
  // route to the internet and would bypass the firewall/proxy.
143
152
  const markedDef = (compose.networks?.[markedNetwork] ?? {});
144
153
  if (!isTruthy(markedDef.internal)) {
145
- warnings.push(`Network "${markedNetwork}" is not marked \`internal: true\`. It must be internal, ` +
154
+ blockers.push(`Network "${markedNetwork}" is not marked \`internal: true\`. It must be internal, ` +
146
155
  'otherwise services can reach the internet directly and bypass Huddle.');
147
156
  }
148
157
  const services = Object.entries(compose.services ?? {})
@@ -161,7 +170,7 @@ function buildOverride(compose, opts = {}) {
161
170
  continue;
162
171
  const def = (compose.networks?.[netKey] ?? {});
163
172
  if (!isTruthy(def.internal)) {
164
- warnings.push(`Service "${name}" is also on network "${netKey}", which is not internal. ` +
173
+ blockers.push(`Service "${name}" is also on network "${netKey}", which is not internal. ` +
165
174
  'Remove it or make it internal — a second non-internal network bypasses Huddle.');
166
175
  }
167
176
  }
@@ -191,7 +200,7 @@ function buildOverride(compose, opts = {}) {
191
200
  [huddleNetKey]: { external: true, name: internalNet },
192
201
  },
193
202
  };
194
- return { markedNetwork, services, override, warnings };
203
+ return { markedNetwork, services, override, warnings, blockers };
195
204
  }
196
205
  function tokenize(input) {
197
206
  const out = [];
@@ -253,9 +262,14 @@ function rejectUnsupportedYaml(lines) {
253
262
  const value = lineValue(text);
254
263
  if (BLOCK_SCALAR_HEADER.test(value))
255
264
  throw unsupportedYaml('a block scalar (`|` or `>`)');
256
- if (/^&[A-Za-z0-9_]/.test(value))
265
+ // Match an anchor/alias in any NODE position: at the value start OR right
266
+ // after a flow opener/separator (`[`, `{`, `,`) or a flow-map colon — so
267
+ // `networks: [*net]` and `{n: *net}` are caught too, not just `x: *net`.
268
+ // The trailing name char keeps this off scalar `&`/`*` (env URLs, globs like
269
+ // `*.log`), which never start an anchor/alias name.
270
+ if (/(^|[[{,:]\s*)&[A-Za-z0-9_]/.test(value))
257
271
  throw unsupportedYaml('a YAML anchor (`&`)');
258
- if (/^\*[A-Za-z0-9_]/.test(value))
272
+ if (/(^|[[{,:]\s*)\*[A-Za-z0-9_]/.test(value))
259
273
  throw unsupportedYaml('a YAML alias (`*`)');
260
274
  }
261
275
  }
@@ -263,12 +277,18 @@ function parseYaml(input) {
263
277
  const lines = tokenize(input);
264
278
  rejectUnsupportedYaml(lines);
265
279
  let pos = 0;
266
- function parseNode(indent) {
280
+ // Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
281
+ // nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
282
+ const MAX_DEPTH = 64;
283
+ function parseNode(indent, depth) {
284
+ if (depth > MAX_DEPTH) {
285
+ throw new Error(`YAML nesting exceeds ${MAX_DEPTH} levels; refusing to parse this compose file.`);
286
+ }
267
287
  if (pos >= lines.length || lines[pos].indent < indent)
268
288
  return null;
269
- return isSeqItem(lines[pos].text) ? parseSequence(indent) : parseMapping(indent);
289
+ return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
270
290
  }
271
- function parseMapping(indent) {
291
+ function parseMapping(indent, depth) {
272
292
  const map = {};
273
293
  while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
274
294
  const { text } = lines[pos];
@@ -284,7 +304,7 @@ function parseYaml(input) {
284
304
  map[key] = parseScalar(rest);
285
305
  }
286
306
  else if (pos < lines.length && lines[pos].indent > indent) {
287
- map[key] = parseNode(lines[pos].indent);
307
+ map[key] = parseNode(lines[pos].indent, depth + 1);
288
308
  }
289
309
  else {
290
310
  map[key] = null;
@@ -292,20 +312,20 @@ function parseYaml(input) {
292
312
  }
293
313
  return map;
294
314
  }
295
- function parseSequence(indent) {
315
+ function parseSequence(indent, depth) {
296
316
  const arr = [];
297
317
  while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
298
318
  const afterDash = lines[pos].text.replace(/^-\s*/, '');
299
319
  if (afterDash === '') {
300
320
  pos++;
301
- arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent) : null);
321
+ arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
302
322
  }
303
323
  else if (findKeyColon(afterDash) >= 0) {
304
324
  // Inline map item: "- key: value". Re-interpret the remainder as a
305
325
  // mapping that starts at a virtual indent past the dash.
306
326
  const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
307
327
  lines[pos] = { indent: virtualIndent, text: afterDash };
308
- arr.push(parseMapping(virtualIndent));
328
+ arr.push(parseMapping(virtualIndent, depth + 1));
309
329
  }
310
330
  else {
311
331
  arr.push(parseScalar(afterDash));
@@ -314,7 +334,7 @@ function parseYaml(input) {
314
334
  }
315
335
  return arr;
316
336
  }
317
- const root = parseNode(lines.length ? lines[0].indent : 0);
337
+ const root = parseNode(lines.length ? lines[0].indent : 0, 0);
318
338
  return (root && typeof root === 'object' ? root : {});
319
339
  }
320
340
  function isSeqItem(text) {
@@ -535,7 +555,17 @@ async function runMigrate(opts) {
535
555
  console.log(`Wired services: ${result.services.length ? result.services.map(utils_1.bold).join(', ') : (0, utils_1.dim)('(none)')}`);
536
556
  for (const w of result.warnings)
537
557
  console.log((0, utils_1.yellow)(`[!] ${w}`));
558
+ for (const b of result.blockers)
559
+ console.log((0, utils_1.red)(`[x] ${b}`));
538
560
  console.log();
561
+ // Fail closed: these blockers mean the migrated service would keep a direct
562
+ // route to the internet, so writing the override and reporting success would
563
+ // be misleading. Refuse unless the operator explicitly overrides with --force.
564
+ if (result.blockers.length > 0 && !opts.force) {
565
+ throw new Error(`Refusing to write the override: the migration would leave a direct internet path ` +
566
+ `(${result.blockers.length} blocker(s) above). Fix your compose file, or re-run with ` +
567
+ `--force to generate it anyway.`);
568
+ }
539
569
  const overrideText = '# Generated by `huddle migrate` — do NOT edit by hand; re-run the command instead.\n' +
540
570
  '# Merge this on top of your docker-compose.yml so the marked services reach the\n' +
541
571
  '# internet only through the Huddle proxy. Your own compose file stays untouched.\n' +
package/dist/runtime.js CHANGED
@@ -72,13 +72,14 @@ function parseDockerContextSocket(json) {
72
72
  const path = host.slice('unix://'.length);
73
73
  if (!path.startsWith('/'))
74
74
  return null;
75
- // The returned path is later interpolated UNquoted into a `docker run -v
76
- // <path>:...` shell command (init.ts). The `Host` from `docker context
75
+ // The returned path is interpolated into a `docker run -v "<path>:..."` shell
76
+ // command (init.ts), where it is DOUBLE-QUOTED. The `Host` from `docker context
77
77
  // inspect` is attacker-influenceable (whoever can create/activate a docker
78
- // context controls the value), so only allow characters that occur in a real
79
- // socket path. This way a manipulated context cannot smuggle in shell
80
- // metacharacters ($(), backticks, ;, |, spaces, ...) — command injection.
81
- if (!/^[A-Za-z0-9._/-]+$/.test(path))
78
+ // context controls the value), so restrict it to characters that occur in a real
79
+ // socket path: allow spaces (legal in e.g. macOS `/Users/First Last/.rd/...`)
80
+ // but never the metacharacters that stay dangerous inside double quotes
81
+ // ($, backtick, ", \) or the command separators (;, |, &, (), newline).
82
+ if (!/^[A-Za-z0-9._/ -]+$/.test(path))
82
83
  return null;
83
84
  return path;
84
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-66.38.1",
3
+ "version": "0.0.0-experiment-66.40.1",
4
4
  "description": "Huddle CLI — start devcontainers and manage firewall rules",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Info Support B.V.",