cli-tunnel 1.2.0-beta.5 → 1.2.0-beta.6
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 +67 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -632,44 +632,93 @@ async function main() {
|
|
|
632
632
|
cols, rows, cwd,
|
|
633
633
|
env: safeEnv,
|
|
634
634
|
});
|
|
635
|
-
// Detect CSPRNG crash (Node.js 23 + node-pty issue) and retry
|
|
635
|
+
// Detect CSPRNG crash (Node.js 23 + node-pty issue) and retry with fallbacks
|
|
636
636
|
let ptyExitedEarly = false;
|
|
637
637
|
const earlyExitCheck = new Promise((resolve) => {
|
|
638
638
|
ptyProcess.onExit(({ exitCode }) => {
|
|
639
|
-
if (exitCode === 134 || exitCode === 3221226505) {
|
|
639
|
+
if (exitCode === 134 || exitCode === 3221226505) {
|
|
640
640
|
ptyExitedEarly = true;
|
|
641
641
|
resolve();
|
|
642
642
|
}
|
|
643
643
|
});
|
|
644
|
-
setTimeout(resolve, 2000);
|
|
644
|
+
setTimeout(resolve, 2000);
|
|
645
645
|
});
|
|
646
646
|
await earlyExitCheck;
|
|
647
647
|
if (ptyExitedEarly && process.platform === 'win32') {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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, {
|
|
652
660
|
name: 'xterm-256color',
|
|
653
661
|
cols, rows, cwd,
|
|
654
|
-
env:
|
|
662
|
+
env: fullSafeEnv,
|
|
655
663
|
});
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const retryCheck = new Promise((resolve) => {
|
|
664
|
+
let retry1Failed = false;
|
|
665
|
+
const retry1Check = new Promise((resolve) => {
|
|
659
666
|
ptyProcess.onExit(({ exitCode }) => {
|
|
660
667
|
if (exitCode === 134 || exitCode === 3221226505) {
|
|
661
|
-
|
|
668
|
+
retry1Failed = true;
|
|
662
669
|
resolve();
|
|
663
670
|
}
|
|
664
671
|
});
|
|
665
672
|
setTimeout(resolve, 2000);
|
|
666
673
|
});
|
|
667
|
-
await
|
|
668
|
-
if (
|
|
669
|
-
|
|
670
|
-
console.log(` ${YELLOW}⚠${RESET}
|
|
671
|
-
|
|
672
|
-
|
|
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
|
+
}
|
|
673
722
|
}
|
|
674
723
|
}
|
|
675
724
|
ptyProcess.onData((data) => {
|