unplugin-https-reverse-proxy 4.1.0-beta.11 → 4.1.0-beta.13
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/{chunk-AQLHWJ4E.js → chunk-U6J2RMIR.js} +129 -35
- package/dist/esbuild.cjs +142 -48
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +142 -48
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +140 -48
- package/dist/nuxt.js +1 -1
- package/dist/privileged-helper.cjs +57 -37
- package/dist/privileged-helper.js +57 -37
- package/dist/rollup.cjs +142 -48
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +142 -48
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +142 -48
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +142 -48
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/index.ts +3 -1
- package/src/index.ts +5 -0
- package/src/privileged/bootstrap.ts +10 -7
- package/src/privileged/client.ts +1 -1
- package/src/privileged/launch.ts +72 -3
- package/src/privileged/path-guard.ts +7 -0
- package/src/privileged/windows-elevation.ts +91 -33
- package/src/privileged-helper.ts +26 -0
package/dist/nuxt.cjs
CHANGED
|
@@ -44,10 +44,10 @@ var import_unplugin = require("unplugin");
|
|
|
44
44
|
|
|
45
45
|
// src/caddy/index.ts
|
|
46
46
|
var import_node_child_process3 = require("child_process");
|
|
47
|
-
var
|
|
47
|
+
var import_node_fs5 = require("fs");
|
|
48
48
|
var import_promises2 = require("fs/promises");
|
|
49
49
|
var import_node_os5 = require("os");
|
|
50
|
-
var
|
|
50
|
+
var import_node_path6 = require("path");
|
|
51
51
|
var import_node_process8 = __toESM(require("process"), 1);
|
|
52
52
|
var import_got_cjs = require("got-cjs");
|
|
53
53
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
@@ -13296,7 +13296,7 @@ function isCaddyReloadCancellation(line) {
|
|
|
13296
13296
|
// src/caddy/privileged.ts
|
|
13297
13297
|
var import_node_buffer2 = require("buffer");
|
|
13298
13298
|
var import_node_events = require("events");
|
|
13299
|
-
var
|
|
13299
|
+
var import_node_path5 = require("path");
|
|
13300
13300
|
var import_node_process7 = __toESM(require("process"), 1);
|
|
13301
13301
|
var import_node_url = require("url");
|
|
13302
13302
|
|
|
@@ -13332,16 +13332,18 @@ function findUp(from, relative, exists2) {
|
|
|
13332
13332
|
|
|
13333
13333
|
// src/privileged/session.ts
|
|
13334
13334
|
var import_node_buffer = require("buffer");
|
|
13335
|
-
var
|
|
13335
|
+
var import_node_fs4 = require("fs");
|
|
13336
13336
|
var import_promises = require("fs/promises");
|
|
13337
13337
|
var import_node_os4 = require("os");
|
|
13338
|
-
var
|
|
13338
|
+
var import_node_path4 = require("path");
|
|
13339
13339
|
var lockfile2 = __toESM(require("proper-lockfile"), 1);
|
|
13340
13340
|
|
|
13341
13341
|
// src/privileged/launch.ts
|
|
13342
13342
|
var import_node_child_process2 = require("child_process");
|
|
13343
13343
|
var import_node_crypto = require("crypto");
|
|
13344
|
+
var import_node_fs3 = require("fs");
|
|
13344
13345
|
var import_node_os3 = require("os");
|
|
13346
|
+
var import_node_path3 = require("path");
|
|
13345
13347
|
var import_node_process6 = __toESM(require("process"), 1);
|
|
13346
13348
|
|
|
13347
13349
|
// src/privileged/client.ts
|
|
@@ -13455,7 +13457,7 @@ async function connectClient(options) {
|
|
|
13455
13457
|
} catch (error) {
|
|
13456
13458
|
lastError = error;
|
|
13457
13459
|
const code = lastError.code;
|
|
13458
|
-
if (code === "EACCES" || lastError instanceof HelperConnectionError)
|
|
13460
|
+
if (code === "EACCES" || code === "EPERM" || lastError instanceof HelperConnectionError)
|
|
13459
13461
|
throw lastError;
|
|
13460
13462
|
await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
|
|
13461
13463
|
}
|
|
@@ -13587,39 +13589,78 @@ function createClient(socket, initialBuffer, callTimeoutMs) {
|
|
|
13587
13589
|
// src/privileged/windows-elevation.ts
|
|
13588
13590
|
var import_node_child_process = require("child_process");
|
|
13589
13591
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
13592
|
+
var ERROR_CANCELLED = 1223;
|
|
13590
13593
|
function quotePowerShell(value2) {
|
|
13591
13594
|
return `'${value2.replace(/'/g, "''")}'`;
|
|
13592
13595
|
}
|
|
13596
|
+
function quoteWindowsArg(arg) {
|
|
13597
|
+
if (arg === "")
|
|
13598
|
+
return '""';
|
|
13599
|
+
if (!/[\s"]/.test(arg))
|
|
13600
|
+
return arg;
|
|
13601
|
+
let quoted = '"';
|
|
13602
|
+
let backslashes = 0;
|
|
13603
|
+
for (const char of arg) {
|
|
13604
|
+
if (char === "\\") {
|
|
13605
|
+
backslashes++;
|
|
13606
|
+
continue;
|
|
13607
|
+
}
|
|
13608
|
+
quoted += char === '"' ? `${"\\".repeat(backslashes * 2 + 1)}"` : `${"\\".repeat(backslashes)}${char}`;
|
|
13609
|
+
backslashes = 0;
|
|
13610
|
+
}
|
|
13611
|
+
return `${quoted}${"\\".repeat(backslashes * 2)}"`;
|
|
13612
|
+
}
|
|
13593
13613
|
function buildElevationCommand(options) {
|
|
13594
|
-
const
|
|
13595
|
-
|
|
13596
|
-
"
|
|
13597
|
-
"-
|
|
13598
|
-
quotePowerShell(options.file)
|
|
13614
|
+
const lines = [
|
|
13615
|
+
// The message read back on failure is localized; keep it readable as UTF-8.
|
|
13616
|
+
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
|
|
13617
|
+
"$psi = New-Object System.Diagnostics.ProcessStartInfo",
|
|
13618
|
+
`$psi.FileName = ${quotePowerShell(options.file)}`,
|
|
13619
|
+
`$psi.Arguments = ${quotePowerShell(options.args.map(quoteWindowsArg).join(" "))}`
|
|
13599
13620
|
];
|
|
13600
|
-
if (argumentList)
|
|
13601
|
-
parts.push("-ArgumentList", argumentList);
|
|
13602
13621
|
if (options.cwd)
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13622
|
+
lines.push(`$psi.WorkingDirectory = ${quotePowerShell(options.cwd)}`);
|
|
13623
|
+
lines.push(
|
|
13624
|
+
"$psi.Verb = 'runas'",
|
|
13625
|
+
"$psi.UseShellExecute = $true",
|
|
13626
|
+
"$psi.WindowStyle = 'Hidden'",
|
|
13627
|
+
"try { $p = [System.Diagnostics.Process]::Start($psi); if ($p) { [Console]::Out.Write($p.Id) } }",
|
|
13628
|
+
`catch { $e = $_.Exception; while ($e.InnerException) { $e = $e.InnerException }; if ($e.NativeErrorCode -eq ${ERROR_CANCELLED}) { exit ${ERROR_CANCELLED} }; [Console]::Error.Write($e.Message); exit 1 }`
|
|
13629
|
+
);
|
|
13630
|
+
return lines.join("\n");
|
|
13607
13631
|
}
|
|
13608
13632
|
function spawnElevatedOnWindows(options) {
|
|
13609
|
-
return new Promise((resolve2
|
|
13610
|
-
const script = buildElevationCommand(options);
|
|
13633
|
+
return new Promise((resolve2) => {
|
|
13611
13634
|
const child = (0, import_node_child_process.spawn)(
|
|
13612
13635
|
"powershell.exe",
|
|
13613
|
-
["-NoProfile", "-NonInteractive", "-Command",
|
|
13614
|
-
{ stdio: "ignore", windowsHide: true }
|
|
13636
|
+
["-NoProfile", "-NonInteractive", "-Command", buildElevationCommand(options)],
|
|
13637
|
+
{ stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
|
|
13615
13638
|
);
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
));
|
|
13639
|
+
let stdout = "";
|
|
13640
|
+
let stderr = "";
|
|
13641
|
+
child.stdout.on("data", (data) => {
|
|
13642
|
+
stdout += data.toString();
|
|
13643
|
+
});
|
|
13644
|
+
child.stderr.on("data", (data) => {
|
|
13645
|
+
stderr = (stderr + data.toString()).slice(-4096);
|
|
13646
|
+
});
|
|
13647
|
+
child.once("error", (error) => resolve2({
|
|
13648
|
+
ok: false,
|
|
13649
|
+
denied: false,
|
|
13650
|
+
message: `could not start PowerShell to request administrator permission: ${error.message}`
|
|
13651
|
+
}));
|
|
13652
|
+
child.once("close", (code) => {
|
|
13653
|
+
if (code === 0) {
|
|
13654
|
+
const pid = Number(stdout.trim());
|
|
13655
|
+
return resolve2({ ok: true, pid: Number.isSafeInteger(pid) && pid > 0 ? pid : void 0 });
|
|
13656
|
+
}
|
|
13657
|
+
if (code === ERROR_CANCELLED)
|
|
13658
|
+
return resolve2({ ok: false, denied: true, message: "administrator permission was cancelled" });
|
|
13659
|
+
resolve2({
|
|
13660
|
+
ok: false,
|
|
13661
|
+
denied: false,
|
|
13662
|
+
message: `could not start the privileged helper as administrator (PowerShell exited with ${code}).${stderr.trim() ? ` ${stderr.trim()}` : ""}`
|
|
13663
|
+
});
|
|
13623
13664
|
});
|
|
13624
13665
|
});
|
|
13625
13666
|
}
|
|
@@ -13750,8 +13791,18 @@ async function startPrivilegedHelper(options) {
|
|
|
13750
13791
|
...options.caddyAdminSocket ? ["--caddy-admin", options.caddyAdminSocket] : []
|
|
13751
13792
|
];
|
|
13752
13793
|
let child;
|
|
13794
|
+
let helperExited;
|
|
13753
13795
|
if (!direct && (0, import_node_os3.platform)() === "win32") {
|
|
13754
|
-
|
|
13796
|
+
const errorFile = (0, import_node_path3.join)((0, import_node_os3.tmpdir)(), `uhrp-helper-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.log`);
|
|
13797
|
+
const elevated = await spawnElevatedOnWindows({
|
|
13798
|
+
file: helperEntry,
|
|
13799
|
+
args: [...childArgv, "--error-file", errorFile],
|
|
13800
|
+
cwd: import_node_process6.default.cwd()
|
|
13801
|
+
});
|
|
13802
|
+
if (!elevated.ok)
|
|
13803
|
+
throw elevated.denied ? new PrivilegeDeniedError(elevated.message) : new Error(elevated.message);
|
|
13804
|
+
if (elevated.pid !== void 0)
|
|
13805
|
+
helperExited = watchWindowsHelper(elevated.pid, errorFile);
|
|
13755
13806
|
} else {
|
|
13756
13807
|
const command = direct ? helperEntry : sudoCommand;
|
|
13757
13808
|
const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
|
|
@@ -13785,7 +13836,10 @@ async function startPrivilegedHelper(options) {
|
|
|
13785
13836
|
}
|
|
13786
13837
|
}
|
|
13787
13838
|
try {
|
|
13788
|
-
const
|
|
13839
|
+
const connecting = connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
|
|
13840
|
+
connecting.catch(() => {
|
|
13841
|
+
});
|
|
13842
|
+
const client = await (helperExited ? Promise.race([connecting, helperExited.promise]) : connecting);
|
|
13789
13843
|
return {
|
|
13790
13844
|
client,
|
|
13791
13845
|
async close() {
|
|
@@ -13800,6 +13854,42 @@ async function startPrivilegedHelper(options) {
|
|
|
13800
13854
|
} catch {
|
|
13801
13855
|
}
|
|
13802
13856
|
throw error;
|
|
13857
|
+
} finally {
|
|
13858
|
+
helperExited == null ? void 0 : helperExited.stop();
|
|
13859
|
+
}
|
|
13860
|
+
}
|
|
13861
|
+
function watchWindowsHelper(pid, errorFile) {
|
|
13862
|
+
let timer;
|
|
13863
|
+
const promise = new Promise((_, reject2) => {
|
|
13864
|
+
timer = setInterval(() => {
|
|
13865
|
+
if (isProcessRunning(pid))
|
|
13866
|
+
return;
|
|
13867
|
+
clearInterval(timer);
|
|
13868
|
+
let detail = "";
|
|
13869
|
+
try {
|
|
13870
|
+
detail = (0, import_node_fs3.readFileSync)(errorFile, "utf8").trim().slice(-4096);
|
|
13871
|
+
} catch {
|
|
13872
|
+
}
|
|
13873
|
+
reject2(new Error(`privileged helper exited before accepting connections.${detail ? ` ${detail}` : " No diagnostic output from the helper."}`));
|
|
13874
|
+
}, 250);
|
|
13875
|
+
});
|
|
13876
|
+
return {
|
|
13877
|
+
promise,
|
|
13878
|
+
stop() {
|
|
13879
|
+
clearInterval(timer);
|
|
13880
|
+
try {
|
|
13881
|
+
(0, import_node_fs3.rmSync)(errorFile, { force: true });
|
|
13882
|
+
} catch {
|
|
13883
|
+
}
|
|
13884
|
+
}
|
|
13885
|
+
};
|
|
13886
|
+
}
|
|
13887
|
+
function isProcessRunning(pid) {
|
|
13888
|
+
try {
|
|
13889
|
+
import_node_process6.default.kill(pid, 0);
|
|
13890
|
+
return true;
|
|
13891
|
+
} catch (error) {
|
|
13892
|
+
return error.code !== "ESRCH";
|
|
13803
13893
|
}
|
|
13804
13894
|
}
|
|
13805
13895
|
async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
@@ -13812,12 +13902,12 @@ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
|
|
|
13812
13902
|
|
|
13813
13903
|
// src/privileged/session.ts
|
|
13814
13904
|
function tokenPath(runtimeDir) {
|
|
13815
|
-
return (0,
|
|
13905
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.token");
|
|
13816
13906
|
}
|
|
13817
13907
|
function sessionSocketPath(runtimeDir) {
|
|
13818
13908
|
if ((0, import_node_os4.platform)() === "win32")
|
|
13819
13909
|
return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
|
|
13820
|
-
return (0,
|
|
13910
|
+
return (0, import_node_path4.join)(runtimeDir, "helper.sock");
|
|
13821
13911
|
}
|
|
13822
13912
|
async function openHelperSession(scope2) {
|
|
13823
13913
|
const socketPath = sessionSocketPath(scope2.runtimeDir);
|
|
@@ -13832,7 +13922,7 @@ async function openHelperSession(scope2) {
|
|
|
13832
13922
|
}
|
|
13833
13923
|
}
|
|
13834
13924
|
async function tryReuse(socketPath, scope2) {
|
|
13835
|
-
if (!(0,
|
|
13925
|
+
if (!(0, import_node_fs4.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
|
|
13836
13926
|
return void 0;
|
|
13837
13927
|
const token = await readToken(scope2.runtimeDir);
|
|
13838
13928
|
if (!token)
|
|
@@ -13876,7 +13966,7 @@ async function startNew(socketPath, scope2) {
|
|
|
13876
13966
|
};
|
|
13877
13967
|
}
|
|
13878
13968
|
async function acquireStartLock(runtimeDir) {
|
|
13879
|
-
const lockPath = (0,
|
|
13969
|
+
const lockPath = (0, import_node_path4.join)(runtimeDir, "helper.start.lock");
|
|
13880
13970
|
try {
|
|
13881
13971
|
await (0, import_promises.writeFile)(lockPath, "", { flag: "a" });
|
|
13882
13972
|
} catch {
|
|
@@ -13910,7 +14000,7 @@ async function writeToken(runtimeDir, token) {
|
|
|
13910
14000
|
// src/caddy/privileged.ts
|
|
13911
14001
|
var import_meta = {};
|
|
13912
14002
|
function resolvePrivilegedEnv() {
|
|
13913
|
-
const moduleDir = typeof __dirname === "string" ? __dirname : (0,
|
|
14003
|
+
const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
13914
14004
|
const resolved = resolveHelperEntry({ moduleDir });
|
|
13915
14005
|
return { helperEntry: resolved.entry, helperArgs: resolved.args };
|
|
13916
14006
|
}
|
|
@@ -13950,7 +14040,7 @@ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
|
|
|
13950
14040
|
}
|
|
13951
14041
|
};
|
|
13952
14042
|
function caddyStoragePath() {
|
|
13953
|
-
return import_node_process7.default.platform === "win32" ? (0,
|
|
14043
|
+
return import_node_process7.default.platform === "win32" ? (0, import_node_path5.join)(import_node_process7.default.env.AppData ?? "", "Caddy") : (0, import_node_path5.join)(import_node_process7.default.env.HOME ?? "", "Library/Application Support/Caddy");
|
|
13954
14044
|
}
|
|
13955
14045
|
function openPrivilegedSession(runtimeDir, options) {
|
|
13956
14046
|
const env2 = resolvePrivilegedEnv();
|
|
@@ -14094,11 +14184,11 @@ async function download() {
|
|
|
14094
14184
|
if (await testCaddy())
|
|
14095
14185
|
return caddyPath;
|
|
14096
14186
|
return new Promise((resolve2, reject2) => {
|
|
14097
|
-
if (!(0,
|
|
14098
|
-
(0,
|
|
14099
|
-
(0,
|
|
14187
|
+
if (!(0, import_node_fs5.existsSync)(TEMP_DIR)) {
|
|
14188
|
+
(0, import_node_fs5.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
14189
|
+
(0, import_node_fs5.chmodSync)(TEMP_DIR, 448);
|
|
14100
14190
|
}
|
|
14101
|
-
const file = (0,
|
|
14191
|
+
const file = (0, import_node_fs5.createWriteStream)(caddyPath);
|
|
14102
14192
|
let _platform = (0, import_node_os5.platform)().toString();
|
|
14103
14193
|
_platform === "win32" && (_platform = "windows");
|
|
14104
14194
|
let _arch = import_node_process8.default.arch.toString();
|
|
@@ -14107,13 +14197,13 @@ async function download() {
|
|
|
14107
14197
|
if (!support)
|
|
14108
14198
|
return reject2(new Error("not support"));
|
|
14109
14199
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
|
|
14110
|
-
(0,
|
|
14200
|
+
(0, import_node_fs5.existsSync)(caddyPath) && (0, import_node_fs5.unlinkSync)(caddyPath);
|
|
14111
14201
|
const httpProxy = import_node_process8.default.env.HTTP_PROXY || import_node_process8.default.env.http_proxy;
|
|
14112
14202
|
const httpsProxy = import_node_process8.default.env.HTTPS_PROXY || import_node_process8.default.env.https_proxy;
|
|
14113
14203
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
14114
14204
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
14115
14205
|
const chmodCaddyOnce = once(() => {
|
|
14116
|
-
(0,
|
|
14206
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14117
14207
|
});
|
|
14118
14208
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
14119
14209
|
agent: {
|
|
@@ -14127,7 +14217,7 @@ async function download() {
|
|
|
14127
14217
|
logProgressOver();
|
|
14128
14218
|
if (import_node_process8.default.platform === "win32")
|
|
14129
14219
|
return resolve2(caddyPath);
|
|
14130
|
-
(0,
|
|
14220
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14131
14221
|
resolve2(caddyPath);
|
|
14132
14222
|
}).on("error", (err) => {
|
|
14133
14223
|
reject2(err);
|
|
@@ -14136,10 +14226,10 @@ async function download() {
|
|
|
14136
14226
|
}
|
|
14137
14227
|
function testCaddy() {
|
|
14138
14228
|
return new Promise((resolve2) => {
|
|
14139
|
-
if (!(0,
|
|
14229
|
+
if (!(0, import_node_fs5.existsSync)(caddyPath))
|
|
14140
14230
|
return resolve2(false);
|
|
14141
14231
|
try {
|
|
14142
|
-
(0,
|
|
14232
|
+
(0, import_node_fs5.chmodSync)(caddyPath, 493);
|
|
14143
14233
|
} catch {
|
|
14144
14234
|
}
|
|
14145
14235
|
(0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
|
|
@@ -14150,7 +14240,7 @@ function testCaddy() {
|
|
|
14150
14240
|
});
|
|
14151
14241
|
}
|
|
14152
14242
|
function caddyRootPath() {
|
|
14153
|
-
return (0,
|
|
14243
|
+
return (0, import_node_path6.join)(
|
|
14154
14244
|
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14155
14245
|
"./pki/authorities/local"
|
|
14156
14246
|
);
|
|
@@ -14213,12 +14303,14 @@ var CaddyInstant = class {
|
|
|
14213
14303
|
async session(reason) {
|
|
14214
14304
|
if (this._session && !this._session.client.connected)
|
|
14215
14305
|
this._session = void 0;
|
|
14216
|
-
if (!this._session)
|
|
14306
|
+
if (!this._session) {
|
|
14307
|
+
await this.deps.config().writeCaddyConfig([], this.proxyKey);
|
|
14217
14308
|
this._session = await this.deps.openSession(TEMP_DIR, reason);
|
|
14309
|
+
}
|
|
14218
14310
|
return this._session;
|
|
14219
14311
|
}
|
|
14220
14312
|
async getCaddyfile() {
|
|
14221
|
-
if (!(0,
|
|
14313
|
+
if (!(0, import_node_fs5.existsSync)(caddyFilePath)) {
|
|
14222
14314
|
this.caddyfile = "";
|
|
14223
14315
|
return "";
|
|
14224
14316
|
}
|
package/dist/nuxt.js
CHANGED
|
@@ -23,17 +23,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/privileged-helper.ts
|
|
26
|
-
var
|
|
26
|
+
var import_node_fs4 = require("fs");
|
|
27
|
+
var import_node_os2 = require("os");
|
|
28
|
+
var import_node_path3 = require("path");
|
|
29
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
27
30
|
|
|
28
31
|
// src/privileged/bootstrap.ts
|
|
29
32
|
var import_node_buffer = require("buffer");
|
|
30
33
|
var import_node_fs3 = require("fs");
|
|
31
34
|
var import_node_net3 = require("net");
|
|
32
35
|
var import_node_path2 = require("path");
|
|
33
|
-
var
|
|
36
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
34
37
|
|
|
35
38
|
// src/privileged/path-guard.ts
|
|
36
39
|
var import_node_fs = require("fs");
|
|
40
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
37
41
|
function describe(stats) {
|
|
38
42
|
return `uid=${stats.uid} mode=${(stats.mode & 511).toString(8)}`;
|
|
39
43
|
}
|
|
@@ -62,6 +66,8 @@ function checkPrivilegedPath(path, options) {
|
|
|
62
66
|
guidance: "Provide a regular file or directory at this path manually."
|
|
63
67
|
};
|
|
64
68
|
}
|
|
69
|
+
if (import_node_process.default.platform === "win32")
|
|
70
|
+
return void 0;
|
|
65
71
|
const allowedOwner = stats.uid === 0 || options.ownerUid !== void 0 && stats.uid === options.ownerUid;
|
|
66
72
|
if (!allowedOwner) {
|
|
67
73
|
return {
|
|
@@ -88,7 +94,7 @@ var import_node_child_process = require("child_process");
|
|
|
88
94
|
var import_node_fs2 = require("fs");
|
|
89
95
|
var import_node_os = require("os");
|
|
90
96
|
var import_node_path = require("path");
|
|
91
|
-
var
|
|
97
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
92
98
|
var import_node_util = require("util");
|
|
93
99
|
|
|
94
100
|
// src/privileged/hosts-file.ts
|
|
@@ -239,8 +245,8 @@ function isAllowedFreePort(port) {
|
|
|
239
245
|
// src/privileged/server.ts
|
|
240
246
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
241
247
|
function execFileQuiet(file, args) {
|
|
242
|
-
return new Promise((
|
|
243
|
-
(0, import_node_child_process.execFile)(file, args, (error, stdout) =>
|
|
248
|
+
return new Promise((resolve2) => {
|
|
249
|
+
(0, import_node_child_process.execFile)(file, args, (error, stdout) => resolve2({ stdout: error && !stdout ? "" : stdout }));
|
|
244
250
|
});
|
|
245
251
|
}
|
|
246
252
|
var HOSTS_PATH = (0, import_node_os.platform)() === "win32" ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts";
|
|
@@ -351,7 +357,7 @@ function createHelperRuntime(deps) {
|
|
|
351
357
|
try {
|
|
352
358
|
switch (request.method) {
|
|
353
359
|
case "ping":
|
|
354
|
-
return { id: request.id, ok: true, result: { pid:
|
|
360
|
+
return { id: request.id, ok: true, result: { pid: import_node_process2.default.pid } };
|
|
355
361
|
case "hosts.add": {
|
|
356
362
|
const { ip, host } = request.params;
|
|
357
363
|
if (!isSafeIp(ip) || !isSafeHost(host))
|
|
@@ -482,14 +488,14 @@ async function trustLocalCaWithSystemTools(caddyBin, adminSocket) {
|
|
|
482
488
|
}
|
|
483
489
|
function createNodeHelperDeps(options) {
|
|
484
490
|
const hostsPath = options.hostsPath ?? HOSTS_PATH;
|
|
485
|
-
const log = options.log ?? ((message) =>
|
|
491
|
+
const log = options.log ?? ((message) => import_node_process2.default.stdout.write(`${message}
|
|
486
492
|
`));
|
|
487
493
|
let caddy;
|
|
488
|
-
|
|
494
|
+
import_node_process2.default.on("exit", () => {
|
|
489
495
|
if ((caddy == null ? void 0 : caddy.pid) === void 0)
|
|
490
496
|
return;
|
|
491
497
|
try {
|
|
492
|
-
|
|
498
|
+
import_node_process2.default.kill(caddy.pid, "SIGTERM");
|
|
493
499
|
} catch {
|
|
494
500
|
}
|
|
495
501
|
});
|
|
@@ -515,10 +521,10 @@ function createNodeHelperDeps(options) {
|
|
|
515
521
|
const pids = (0, import_node_os.platform)() === "win32" ? parseWindowsListeningPids((await execFileAsync("netstat", ["-ano"])).stdout, port) : parseListeningPids((await execFileQuiet("lsof", [`-ti:${port}`, "-sTCP:LISTEN"])).stdout);
|
|
516
522
|
const killed = [];
|
|
517
523
|
for (const pid of pids) {
|
|
518
|
-
if (pid ===
|
|
524
|
+
if (pid === import_node_process2.default.pid || keepPid !== void 0 && pid === keepPid)
|
|
519
525
|
continue;
|
|
520
526
|
try {
|
|
521
|
-
|
|
527
|
+
import_node_process2.default.kill(pid, "SIGTERM");
|
|
522
528
|
killed.push(pid);
|
|
523
529
|
} catch {
|
|
524
530
|
}
|
|
@@ -527,7 +533,7 @@ function createNodeHelperDeps(options) {
|
|
|
527
533
|
},
|
|
528
534
|
caddyBin: options.caddyBin,
|
|
529
535
|
caddyConfigPath: options.caddyConfigPath,
|
|
530
|
-
caddyCwd: options.caddyCwd ??
|
|
536
|
+
caddyCwd: options.caddyCwd ?? import_node_process2.default.cwd(),
|
|
531
537
|
caddyEnv: options.caddyEnv ?? {},
|
|
532
538
|
trustLocalCa: () => trustLocalCaWithSystemTools(options.caddyBin, options.caddyAdminSocket),
|
|
533
539
|
caddyStoragePath: options.caddyStoragePath,
|
|
@@ -535,8 +541,8 @@ function createNodeHelperDeps(options) {
|
|
|
535
541
|
startCaddy: (emit) => {
|
|
536
542
|
var _a, _b;
|
|
537
543
|
const child = (0, import_node_child_process.spawn)(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
|
|
538
|
-
cwd: options.caddyCwd ??
|
|
539
|
-
env: { ...
|
|
544
|
+
cwd: options.caddyCwd ?? import_node_process2.default.cwd(),
|
|
545
|
+
env: { ...import_node_process2.default.env, ...options.caddyEnv },
|
|
540
546
|
stdio: ["ignore", "pipe", "pipe"],
|
|
541
547
|
detached: (0, import_node_os.platform)() !== "win32"
|
|
542
548
|
});
|
|
@@ -605,7 +611,7 @@ var HANDSHAKE_TIMEOUT_MS = 12e4;
|
|
|
605
611
|
var DEFAULT_IDLE_TIMEOUT_MS = 3e4;
|
|
606
612
|
async function startHelper(options) {
|
|
607
613
|
const { socketPath, token } = options;
|
|
608
|
-
const log = options.log ?? ((message) =>
|
|
614
|
+
const log = options.log ?? ((message) => import_node_process3.default.stdout.write(`[uhrp-helper] ${message}
|
|
609
615
|
`));
|
|
610
616
|
for (const check of [
|
|
611
617
|
checkPrivilegedPath(options.caddyBin, { label: "Caddy binary", ownerUid: options.ownerUid }),
|
|
@@ -686,7 +692,7 @@ async function startHelper(options) {
|
|
|
686
692
|
return;
|
|
687
693
|
}
|
|
688
694
|
authenticated = true;
|
|
689
|
-
socket.write(`${JSON.stringify({ type: "handshake", ok: true, pid:
|
|
695
|
+
socket.write(`${JSON.stringify({ type: "handshake", ok: true, pid: import_node_process3.default.pid })}
|
|
690
696
|
`);
|
|
691
697
|
attachSocket(socket, runtime, log);
|
|
692
698
|
if (rest.trim() !== "")
|
|
@@ -711,21 +717,21 @@ async function startHelper(options) {
|
|
|
711
717
|
server.close();
|
|
712
718
|
return;
|
|
713
719
|
}
|
|
714
|
-
server.close(() =>
|
|
715
|
-
(_b = (_a2 = setTimeout(() =>
|
|
720
|
+
server.close(() => import_node_process3.default.exit(0));
|
|
721
|
+
(_b = (_a2 = setTimeout(() => import_node_process3.default.exit(0), 1e3)).unref) == null ? void 0 : _b.call(_a2);
|
|
716
722
|
}, idleTimeoutMs);
|
|
717
723
|
(_a = idleTimer.unref) == null ? void 0 : _a.call(idleTimer);
|
|
718
724
|
}
|
|
719
|
-
await new Promise((
|
|
725
|
+
await new Promise((resolve2, reject) => {
|
|
720
726
|
server.once("error", reject);
|
|
721
|
-
|
|
727
|
+
const shareWithUser = import_node_process3.default.platform === "win32";
|
|
728
|
+
server.listen({ path: socketPath, readableAll: shareWithUser, writableAll: shareWithUser }, () => resolve2());
|
|
722
729
|
});
|
|
723
730
|
scheduleIdleExit();
|
|
724
731
|
try {
|
|
725
|
-
if (
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
} else {
|
|
732
|
+
if (import_node_process3.default.platform !== "win32") {
|
|
733
|
+
if (typeof options.ownerUid === "number")
|
|
734
|
+
(0, import_node_fs3.chownSync)(socketPath, options.ownerUid, options.ownerGid ?? options.ownerUid);
|
|
729
735
|
(0, import_node_fs3.chmodSync)(socketPath, 384);
|
|
730
736
|
}
|
|
731
737
|
} catch (error) {
|
|
@@ -737,14 +743,14 @@ async function startHelper(options) {
|
|
|
737
743
|
for (const socket of connections)
|
|
738
744
|
socket.destroy();
|
|
739
745
|
connections.clear();
|
|
740
|
-
await new Promise((
|
|
741
|
-
server.close(() =>
|
|
746
|
+
await new Promise((resolve2) => {
|
|
747
|
+
server.close(() => resolve2());
|
|
742
748
|
});
|
|
743
749
|
}
|
|
744
750
|
};
|
|
745
751
|
}
|
|
746
752
|
function removeOwnSocket(socketPath, token) {
|
|
747
|
-
if (
|
|
753
|
+
if (import_node_process3.default.platform === "win32")
|
|
748
754
|
return;
|
|
749
755
|
try {
|
|
750
756
|
const tokensDir = (0, import_node_path2.dirname)(socketPath);
|
|
@@ -809,7 +815,7 @@ function parseArgs(argv) {
|
|
|
809
815
|
};
|
|
810
816
|
}
|
|
811
817
|
async function main() {
|
|
812
|
-
const args = parseArgs(
|
|
818
|
+
const args = parseArgs(import_node_process4.default.argv.slice(2));
|
|
813
819
|
const helper = await startHelper({
|
|
814
820
|
socketPath: args.socket,
|
|
815
821
|
token: args.token,
|
|
@@ -821,28 +827,42 @@ async function main() {
|
|
|
821
827
|
caddyStoragePath: args.caddyStorage,
|
|
822
828
|
caddyAdminSocket: args.caddyAdmin,
|
|
823
829
|
caddyEnv: {
|
|
824
|
-
HOME:
|
|
830
|
+
HOME: import_node_process4.default.env.HOME ?? "",
|
|
825
831
|
// Keep Caddy's storage next to the invoking user's home even though the
|
|
826
832
|
// process runs as root.
|
|
827
|
-
XDG_DATA_HOME:
|
|
833
|
+
XDG_DATA_HOME: import_node_process4.default.env.XDG_DATA_HOME ?? ""
|
|
828
834
|
}
|
|
829
835
|
});
|
|
830
836
|
for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
|
|
831
|
-
|
|
837
|
+
import_node_process4.default.on(signal, () => {
|
|
832
838
|
});
|
|
833
|
-
|
|
839
|
+
import_node_process4.default.on("SIGTERM", () => {
|
|
834
840
|
if (helper.runtime.clientCount() > 0)
|
|
835
841
|
return;
|
|
836
|
-
void helper.runtime.dispose().finally(() =>
|
|
842
|
+
void helper.runtime.dispose().finally(() => import_node_process4.default.exit(0));
|
|
837
843
|
});
|
|
838
|
-
|
|
844
|
+
import_node_process4.default.stdout.on("error", () => {
|
|
839
845
|
});
|
|
840
|
-
|
|
846
|
+
import_node_process4.default.stderr.on("error", () => {
|
|
841
847
|
});
|
|
842
848
|
}
|
|
843
849
|
main().catch((error) => {
|
|
844
|
-
|
|
850
|
+
import_node_process4.default.stderr.write(`[uhrp-helper] fatal: ${error.message}
|
|
845
851
|
`);
|
|
846
|
-
|
|
852
|
+
const errorFile = errorFileFrom(import_node_process4.default.argv.slice(2));
|
|
853
|
+
if (errorFile) {
|
|
854
|
+
try {
|
|
855
|
+
(0, import_node_fs4.writeFileSync)(errorFile, error.message, { flag: "wx" });
|
|
856
|
+
} catch {
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
import_node_process4.default.exit(1);
|
|
847
860
|
});
|
|
861
|
+
function errorFileFrom(argv) {
|
|
862
|
+
const index = argv.indexOf("--error-file");
|
|
863
|
+
const path = index >= 0 ? argv[index + 1] : void 0;
|
|
864
|
+
if (!path || !/^uhrp-helper-[0-9a-f]+\.log$/.test((0, import_node_path3.basename)(path)))
|
|
865
|
+
return void 0;
|
|
866
|
+
return (0, import_node_path3.resolve)((0, import_node_path3.dirname)(path)) === (0, import_node_path3.resolve)((0, import_node_os2.tmpdir)()) ? path : void 0;
|
|
867
|
+
}
|
|
848
868
|
exports.default = module.exports;
|