cli-tunnel 1.2.0-beta.6 → 1.2.0-beta.8

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.
Files changed (2) hide show
  1. package/dist/index.js +17 -97
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -243,7 +243,9 @@ const server = http.createServer((req, res) => {
243
243
  // #18: Guard against malformed URI encoding
244
244
  let decodedUrl;
245
245
  try {
246
- decodedUrl = decodeURIComponent(req.url || '/');
246
+ // Strip query string before resolving file path
247
+ const urlPath = (req.url || '/').split('?')[0];
248
+ decodedUrl = decodeURIComponent(urlPath);
247
249
  }
248
250
  catch {
249
251
  res.writeHead(400);
@@ -603,27 +605,15 @@ async function main() {
603
605
  }
604
606
  catch { /* use as-is */ }
605
607
  }
606
- // F-07: Security — allowlist safe environment variables for PTY
607
- const SAFE_ENV_VARS = new Set([
608
- 'PATH', 'HOME', 'USERPROFILE', 'SHELL', 'TERM', 'LANG', 'LC_ALL', 'LC_CTYPE',
609
- 'USER', 'LOGNAME', 'EDITOR', 'VISUAL', 'COLORTERM', 'TERM_PROGRAM',
610
- 'HOSTNAME', 'COMPUTERNAME', 'PWD', 'OLDPWD', 'SHLVL', 'TMPDIR', 'TMP', 'TEMP',
611
- 'XDG_RUNTIME_DIR', 'XDG_DATA_HOME', 'XDG_CONFIG_HOME', 'XDG_CACHE_HOME',
612
- 'DISPLAY', 'WAYLAND_DISPLAY', 'DBUS_SESSION_BUS_ADDRESS',
613
- 'PROGRAMFILES', 'PROGRAMFILES(X86)', 'SYSTEMROOT', 'WINDIR', 'COMSPEC',
614
- 'APPDATA', 'LOCALAPPDATA', 'PROGRAMDATA',
615
- 'NODE_ENV',
616
- 'GOPATH', 'GOROOT', 'CARGO_HOME', 'RUSTUP_HOME',
617
- 'JAVA_HOME', 'MAVEN_HOME', 'GRADLE_HOME',
618
- 'PYTHONPATH', 'VIRTUAL_ENV', 'CONDA_DEFAULT_ENV',
619
- 'KUBECONFIG', 'DOCKER_HOST', 'DOCKER_CONFIG',
620
- 'GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL',
621
- 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'http_proxy', 'https_proxy', 'no_proxy',
622
- 'SSH_AUTH_SOCK', 'GPG_TTY',
623
- ]);
608
+ // F-07: Security — filter dangerous environment variables for PTY
609
+ // Blocklist approach: pass everything except known dangerous vars and secrets
610
+ const DANGEROUS_VARS = new Set(['NODE_OPTIONS', 'NODE_REPL_HISTORY', 'NODE_EXTRA_CA_CERTS',
611
+ 'NODE_PATH', 'NODE_REDIRECT_WARNINGS', 'NODE_PENDING_DEPRECATION',
612
+ 'UV_THREADPOOL_SIZE', 'LD_PRELOAD', 'DYLD_INSERT_LIBRARIES']);
613
+ const sensitivePattern = /token|secret|key|password|credential|api_key|private_key|access_key|connection_string|auth/i;
624
614
  const safeEnv = {};
625
615
  for (const [k, v] of Object.entries(process.env)) {
626
- if (SAFE_ENV_VARS.has(k) && v !== undefined) {
616
+ if (v !== undefined && !DANGEROUS_VARS.has(k) && !sensitivePattern.test(k)) {
627
617
  safeEnv[k] = v;
628
618
  }
629
619
  }
@@ -632,7 +622,7 @@ async function main() {
632
622
  cols, rows, cwd,
633
623
  env: safeEnv,
634
624
  });
635
- // Detect CSPRNG crash (Node.js 23 + node-pty issue) and retry with fallbacks
625
+ // Detect CSPRNG crash (rare Node.js + PTY issue) and show helpful message
636
626
  let ptyExitedEarly = false;
637
627
  const earlyExitCheck = new Promise((resolve) => {
638
628
  ptyProcess.onExit(({ exitCode }) => {
@@ -644,82 +634,12 @@ async function main() {
644
634
  setTimeout(resolve, 2000);
645
635
  });
646
636
  await earlyExitCheck;
647
- if (ptyExitedEarly && process.platform === 'win32') {
648
- // Retry 1: Use full environment — CSPRNG may need env vars we filtered out
649
- console.log(` ${YELLOW}⚠${RESET} Process crashed, retrying with full environment...\n`);
650
- // Blocklist approach: pass everything EXCEPT known dangerous vars
651
- const DANGEROUS_VARS = new Set(['NODE_OPTIONS', 'NODE_REPL_HISTORY', 'NODE_EXTRA_CA_CERTS',
652
- 'NODE_PATH', 'NODE_REDIRECT_WARNINGS', 'NODE_PENDING_DEPRECATION',
653
- 'UV_THREADPOOL_SIZE', 'LD_PRELOAD', 'DYLD_INSERT_LIBRARIES']);
654
- const fullSafeEnv = {};
655
- for (const [k, v] of Object.entries(process.env)) {
656
- if (!DANGEROUS_VARS.has(k) && v !== undefined)
657
- fullSafeEnv[k] = v;
658
- }
659
- ptyProcess = nodePty.spawn(resolvedCmd, commandArgs, {
660
- name: 'xterm-256color',
661
- cols, rows, cwd,
662
- env: fullSafeEnv,
663
- });
664
- let retry1Failed = false;
665
- const retry1Check = new Promise((resolve) => {
666
- ptyProcess.onExit(({ exitCode }) => {
667
- if (exitCode === 134 || exitCode === 3221226505) {
668
- retry1Failed = true;
669
- resolve();
670
- }
671
- });
672
- setTimeout(resolve, 2000);
673
- });
674
- await retry1Check;
675
- if (retry1Failed) {
676
- // Retry 2: cmd.exe wrapper with full env
677
- console.log(` ${YELLOW}⚠${RESET} Still crashing, retrying via cmd.exe wrapper...\n`);
678
- const cmdLine = [resolvedCmd, ...commandArgs].map(a => a.includes(' ') ? `"${a}"` : a).join(' ');
679
- ptyProcess = nodePty.spawn('cmd.exe', ['/c', cmdLine], {
680
- name: 'xterm-256color',
681
- cols, rows, cwd,
682
- env: fullSafeEnv,
683
- });
684
- let retry2Failed = false;
685
- const retry2Check = new Promise((resolve) => {
686
- ptyProcess.onExit(({ exitCode }) => {
687
- if (exitCode === 134 || exitCode === 3221226505) {
688
- retry2Failed = true;
689
- resolve();
690
- }
691
- });
692
- setTimeout(resolve, 2000);
693
- });
694
- await retry2Check;
695
- if (retry2Failed) {
696
- // Retry 3: useConpty: false with full env
697
- console.log(` ${YELLOW}⚠${RESET} Still crashing, retrying with legacy PTY backend...\n`);
698
- ptyProcess = nodePty.spawn(resolvedCmd, commandArgs, {
699
- name: 'xterm-256color',
700
- cols, rows, cwd,
701
- env: fullSafeEnv,
702
- useConpty: false,
703
- });
704
- let retry3Failed = false;
705
- const retry3Check = new Promise((resolve) => {
706
- ptyProcess.onExit(({ exitCode }) => {
707
- if (exitCode === 134 || exitCode === 3221226505) {
708
- retry3Failed = true;
709
- resolve();
710
- }
711
- });
712
- setTimeout(resolve, 2000);
713
- });
714
- await retry3Check;
715
- if (retry3Failed) {
716
- const nodeVer = process.version;
717
- console.log(` ${YELLOW}⚠${RESET} The command crashed due to a known Node.js ${nodeVer} + PTY compatibility issue.`);
718
- console.log(` ${BOLD}Fix:${RESET} Install Node.js 22 LTS: ${GREEN}nvm install 22${RESET} or ${GREEN}winget install OpenJS.NodeJS.LTS${RESET}\n`);
719
- process.exit(1);
720
- }
721
- }
722
- }
637
+ if (ptyExitedEarly) {
638
+ const nodeVer = process.version;
639
+ console.log(` ${YELLOW}⚠${RESET} The command crashed (CSPRNG assertion failure).`);
640
+ console.log(` This is a known issue with Node.js ${nodeVer} + PTY on Windows.`);
641
+ console.log(` ${BOLD}Fix:${RESET} Install Node.js 22 LTS: ${GREEN}nvm install 22${RESET} or ${GREEN}winget install OpenJS.NodeJS.LTS${RESET}\n`);
642
+ process.exit(1);
723
643
  }
724
644
  ptyProcess.onData((data) => {
725
645
  process.stdout.write(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-tunnel",
3
- "version": "1.2.0-beta.6",
3
+ "version": "1.2.0-beta.8",
4
4
  "description": "Tunnel any CLI app to your phone — PTY + devtunnel + xterm.js",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",