unplugin-https-reverse-proxy 4.1.0-beta.2 → 4.1.0-beta.3
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-7CA3EIIX.js → chunk-HBXMM25C.js} +101 -23
- package/dist/chunk-WOMR3ZLM.js +17 -0
- package/dist/esbuild.cjs +103 -20
- package/dist/esbuild.js +2 -1
- package/dist/index.cjs +103 -20
- package/dist/index.js +2 -1
- package/dist/nuxt.cjs +77 -16
- package/dist/nuxt.js +2 -1
- package/dist/privilege-state.cjs +44 -0
- package/dist/privilege-state.d.cts +7 -0
- package/dist/privilege-state.d.ts +7 -0
- package/dist/privilege-state.js +10 -0
- package/dist/rollup.cjs +103 -20
- package/dist/rollup.js +2 -1
- package/dist/rspack.cjs +103 -20
- package/dist/rspack.js +2 -1
- package/dist/vite.cjs +103 -20
- package/dist/vite.js +2 -1
- package/dist/webpack.cjs +103 -20
- package/dist/webpack.js +2 -1
- package/package.json +1 -1
- package/src/caddy/index.ts +7 -6
- package/src/caddy/privileged.ts +3 -0
- package/src/index.ts +48 -7
- package/src/privilege-state.ts +23 -0
- package/src/privileged/entry.ts +34 -6
- package/src/privileged/launch.ts +46 -4
- package/src/privileged/session.ts +3 -0
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
hmrSseBridgeClientScript,
|
|
9
9
|
setupHmrSseBridge
|
|
10
10
|
} from "./chunk-C5A7XLKL.js";
|
|
11
|
+
import {
|
|
12
|
+
isPrivilegeDenied,
|
|
13
|
+
markPrivilegeDenied
|
|
14
|
+
} from "./chunk-WOMR3ZLM.js";
|
|
11
15
|
import {
|
|
12
16
|
decodeMessage,
|
|
13
17
|
serializeMessage,
|
|
@@ -13615,27 +13619,39 @@ function isCaddyReloadCancellation(line) {
|
|
|
13615
13619
|
// src/caddy/privileged.ts
|
|
13616
13620
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
13617
13621
|
import { EventEmitter } from "node:events";
|
|
13618
|
-
import { dirname as
|
|
13622
|
+
import { dirname as dirname3, join as join5 } from "node:path";
|
|
13619
13623
|
import process6 from "node:process";
|
|
13620
13624
|
import { fileURLToPath } from "node:url";
|
|
13621
13625
|
|
|
13622
13626
|
// src/privileged/entry.ts
|
|
13623
13627
|
import { existsSync as existsSync3 } from "node:fs";
|
|
13624
|
-
import { join as join3 } from "node:path";
|
|
13628
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
13625
13629
|
import process3 from "node:process";
|
|
13626
13630
|
function resolveHelperEntry(options) {
|
|
13627
13631
|
const { moduleDir, nodeBin = process3.execPath, exists: exists2 = existsSync3 } = options;
|
|
13628
13632
|
for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
|
|
13629
|
-
const candidate =
|
|
13630
|
-
if (
|
|
13633
|
+
const candidate = findUp(moduleDir, name, exists2);
|
|
13634
|
+
if (candidate)
|
|
13631
13635
|
return { entry: nodeBin, args: [candidate] };
|
|
13632
13636
|
}
|
|
13633
|
-
const source =
|
|
13634
|
-
const tsxCli =
|
|
13635
|
-
if (
|
|
13637
|
+
const source = findUp(moduleDir, "privileged-helper.ts", exists2);
|
|
13638
|
+
const tsxCli = findUp(moduleDir, "node_modules/tsx/dist/cli.mjs", exists2);
|
|
13639
|
+
if (source && tsxCli)
|
|
13636
13640
|
return { entry: nodeBin, args: [tsxCli, source] };
|
|
13637
13641
|
throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
|
|
13638
13642
|
}
|
|
13643
|
+
function findUp(from, relative, exists2) {
|
|
13644
|
+
let current = from;
|
|
13645
|
+
while (true) {
|
|
13646
|
+
const candidate = join3(current, relative);
|
|
13647
|
+
if (exists2(candidate))
|
|
13648
|
+
return candidate;
|
|
13649
|
+
const parent = dirname2(current);
|
|
13650
|
+
if (parent === current)
|
|
13651
|
+
return void 0;
|
|
13652
|
+
current = parent;
|
|
13653
|
+
}
|
|
13654
|
+
}
|
|
13639
13655
|
|
|
13640
13656
|
// src/privileged/session.ts
|
|
13641
13657
|
import { Buffer } from "node:buffer";
|
|
@@ -13883,18 +13899,42 @@ function spawnElevatedOnWindows(options) {
|
|
|
13883
13899
|
function createHelperToken() {
|
|
13884
13900
|
return randomBytes(24).toString("hex");
|
|
13885
13901
|
}
|
|
13886
|
-
function
|
|
13902
|
+
function describePasswordReason(target, https) {
|
|
13903
|
+
const port = https ? "443" : "80";
|
|
13904
|
+
return [
|
|
13905
|
+
`reverse proxy needs administrator permission for ${target}`,
|
|
13906
|
+
` \xB7 bind port ${port}${https ? ` for https://${target}` : ""}`,
|
|
13907
|
+
` \xB7 add ${target} to the hosts file`,
|
|
13908
|
+
"",
|
|
13909
|
+
"This is the only prompt; the rest of the dev server keeps running as you.",
|
|
13910
|
+
"Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
|
|
13911
|
+
];
|
|
13912
|
+
}
|
|
13913
|
+
function authenticateSudo(sudoCommand = "sudo", options = {}) {
|
|
13887
13914
|
if (platform() === "win32")
|
|
13888
13915
|
return { ok: true };
|
|
13889
13916
|
if (spawnSync(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
|
|
13890
13917
|
return { ok: true };
|
|
13918
|
+
if (options.target) {
|
|
13919
|
+
for (const line of describePasswordReason(options.target, options.https ?? false))
|
|
13920
|
+
process5.stderr.write(`${line}
|
|
13921
|
+
`);
|
|
13922
|
+
process5.stderr.write("\n");
|
|
13923
|
+
}
|
|
13891
13924
|
if (spawnSync(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
|
|
13892
13925
|
return { ok: true };
|
|
13893
13926
|
return {
|
|
13894
13927
|
ok: false,
|
|
13928
|
+
denied: true,
|
|
13895
13929
|
message: "administrator permission is required to edit the hosts file and bind ports 80/443"
|
|
13896
13930
|
};
|
|
13897
13931
|
}
|
|
13932
|
+
var PrivilegeDeniedError = class extends Error {
|
|
13933
|
+
constructor(message) {
|
|
13934
|
+
super(message);
|
|
13935
|
+
this.name = "PrivilegeDeniedError";
|
|
13936
|
+
}
|
|
13937
|
+
};
|
|
13898
13938
|
async function startPrivilegedHelper(options) {
|
|
13899
13939
|
var _a4, _b3;
|
|
13900
13940
|
const {
|
|
@@ -13910,9 +13950,11 @@ async function startPrivilegedHelper(options) {
|
|
|
13910
13950
|
connectTimeoutMs = 12e4
|
|
13911
13951
|
} = options;
|
|
13912
13952
|
if (!skipAuth && !direct) {
|
|
13913
|
-
const auth = authenticateSudo(sudoCommand);
|
|
13914
|
-
if (!auth.ok)
|
|
13915
|
-
|
|
13953
|
+
const auth = authenticateSudo(sudoCommand, options.reason);
|
|
13954
|
+
if (!auth.ok) {
|
|
13955
|
+
const message = auth.message ?? "administrator permission is required";
|
|
13956
|
+
throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
|
|
13957
|
+
}
|
|
13916
13958
|
}
|
|
13917
13959
|
const forwarded = collectForwardedEnv(env2);
|
|
13918
13960
|
const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
|
|
@@ -14017,6 +14059,7 @@ async function openHelperSession(scope2) {
|
|
|
14017
14059
|
caddyStoragePath: scope2.caddyStoragePath,
|
|
14018
14060
|
caddyBin: scope2.caddyBin,
|
|
14019
14061
|
caddyConfigPath: scope2.caddyConfigPath,
|
|
14062
|
+
reason: scope2.reason,
|
|
14020
14063
|
log: scope2.log
|
|
14021
14064
|
});
|
|
14022
14065
|
await writeToken(scope2.runtimeDir, token);
|
|
@@ -14046,7 +14089,7 @@ async function writeToken(runtimeDir, token) {
|
|
|
14046
14089
|
|
|
14047
14090
|
// src/caddy/privileged.ts
|
|
14048
14091
|
function resolvePrivilegedEnv() {
|
|
14049
|
-
const moduleDir = typeof __dirname === "string" ? __dirname :
|
|
14092
|
+
const moduleDir = typeof __dirname === "string" ? __dirname : dirname3(fileURLToPath(import.meta.url));
|
|
14050
14093
|
const resolved = resolveHelperEntry({ moduleDir });
|
|
14051
14094
|
return { helperEntry: resolved.entry, helperArgs: resolved.args };
|
|
14052
14095
|
}
|
|
@@ -14102,6 +14145,7 @@ function openPrivilegedSession(runtimeDir, options) {
|
|
|
14102
14145
|
// execute a path supplied over the socket.
|
|
14103
14146
|
caddyBin: options.caddyBin,
|
|
14104
14147
|
caddyConfigPath: options.caddyConfigPath,
|
|
14148
|
+
reason: options.reason,
|
|
14105
14149
|
log: options.log
|
|
14106
14150
|
});
|
|
14107
14151
|
}
|
|
@@ -14302,12 +14346,13 @@ function splitHostPort(addr) {
|
|
|
14302
14346
|
return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
|
|
14303
14347
|
}
|
|
14304
14348
|
var defaultDependencies = {
|
|
14305
|
-
openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
|
|
14349
|
+
openSession: (runtimeDir, reason) => openPrivilegedSession(runtimeDir, {
|
|
14306
14350
|
log: (message) => consola.debug(message),
|
|
14307
14351
|
// Both paths are fixed here, before any socket traffic: the privileged
|
|
14308
14352
|
// helper must never execute something named in a request.
|
|
14309
14353
|
caddyBin: caddyPath,
|
|
14310
|
-
caddyConfigPath: caddyFilePath
|
|
14354
|
+
caddyConfigPath: caddyFilePath,
|
|
14355
|
+
reason
|
|
14311
14356
|
})
|
|
14312
14357
|
};
|
|
14313
14358
|
var CaddyInstant = class {
|
|
@@ -14334,11 +14379,11 @@ var CaddyInstant = class {
|
|
|
14334
14379
|
* reused across instances so a second dev server does not ask for a
|
|
14335
14380
|
* password again.
|
|
14336
14381
|
*/
|
|
14337
|
-
async session() {
|
|
14382
|
+
async session(reason) {
|
|
14338
14383
|
if (this._session && !this._session.client.connected)
|
|
14339
14384
|
this._session = void 0;
|
|
14340
14385
|
if (!this._session)
|
|
14341
|
-
this._session = await this.deps.openSession(TEMP_DIR);
|
|
14386
|
+
this._session = await this.deps.openSession(TEMP_DIR, reason);
|
|
14342
14387
|
return this._session;
|
|
14343
14388
|
}
|
|
14344
14389
|
async getCaddyfile() {
|
|
@@ -14443,9 +14488,9 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14443
14488
|
this._target = target;
|
|
14444
14489
|
if (!this.inited)
|
|
14445
14490
|
await this.init();
|
|
14446
|
-
const session = await this.session();
|
|
14447
14491
|
const sourceHost = splitHostPort(source).host;
|
|
14448
14492
|
const targetHost = splitHostPort(target).host;
|
|
14493
|
+
const session = await this.session({ target: targetHost, https });
|
|
14449
14494
|
await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
|
|
14450
14495
|
consola.success("update host success\n");
|
|
14451
14496
|
const normalizeBase = (b) => {
|
|
@@ -14682,16 +14727,27 @@ async function printForwardProxy() {
|
|
|
14682
14727
|
}
|
|
14683
14728
|
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
14684
14729
|
_printUrls == null ? void 0 : _printUrls();
|
|
14730
|
+
if (isPrivilegeDenied())
|
|
14731
|
+
return;
|
|
14685
14732
|
if (caddy)
|
|
14686
14733
|
return;
|
|
14687
|
-
|
|
14688
|
-
caddy
|
|
14734
|
+
const instance = new CaddyInstant();
|
|
14735
|
+
caddy = instance;
|
|
14736
|
+
instance.run(source, target, {
|
|
14689
14737
|
base,
|
|
14690
14738
|
...options
|
|
14691
14739
|
}).then(async () => {
|
|
14692
14740
|
await printForwardProxy();
|
|
14693
14741
|
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
14694
14742
|
}).catch((e) => {
|
|
14743
|
+
if (caddy === instance)
|
|
14744
|
+
caddy = void 0;
|
|
14745
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
14746
|
+
markPrivilegeDenied();
|
|
14747
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
14748
|
+
consola.info("Restart the dev server to enable it again.");
|
|
14749
|
+
return;
|
|
14750
|
+
}
|
|
14695
14751
|
throw e;
|
|
14696
14752
|
});
|
|
14697
14753
|
});
|
|
@@ -14771,6 +14827,8 @@ var unpluginFactory = (options) => ({
|
|
|
14771
14827
|
...(_a4 = process8.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
|
|
14772
14828
|
};
|
|
14773
14829
|
const source = `${devServer.host}:${devServer.port}`;
|
|
14830
|
+
if (isPrivilegeDenied())
|
|
14831
|
+
return;
|
|
14774
14832
|
if (caddy)
|
|
14775
14833
|
return;
|
|
14776
14834
|
let base = "/";
|
|
@@ -14792,8 +14850,9 @@ var unpluginFactory = (options) => ({
|
|
|
14792
14850
|
} else {
|
|
14793
14851
|
options.https = false;
|
|
14794
14852
|
}
|
|
14795
|
-
|
|
14796
|
-
caddy
|
|
14853
|
+
const instance = new CaddyInstant();
|
|
14854
|
+
caddy = instance;
|
|
14855
|
+
instance.run(source, target, {
|
|
14797
14856
|
base,
|
|
14798
14857
|
...options
|
|
14799
14858
|
}).then(() => {
|
|
@@ -14802,6 +14861,14 @@ var unpluginFactory = (options) => ({
|
|
|
14802
14861
|
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
14803
14862
|
});
|
|
14804
14863
|
}).catch((e) => {
|
|
14864
|
+
if (caddy === instance)
|
|
14865
|
+
caddy = void 0;
|
|
14866
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
14867
|
+
markPrivilegeDenied();
|
|
14868
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
14869
|
+
consola.info("Restart the dev server to enable it again.");
|
|
14870
|
+
return;
|
|
14871
|
+
}
|
|
14805
14872
|
throw e;
|
|
14806
14873
|
});
|
|
14807
14874
|
},
|
|
@@ -14832,9 +14899,10 @@ var unpluginFactory = (options) => ({
|
|
|
14832
14899
|
}))) == null ? void 0 : _b3.content) == null ? void 0 : _c2.server
|
|
14833
14900
|
};
|
|
14834
14901
|
const source = `${devServer.host}:${devServer.port}`;
|
|
14902
|
+
if (isPrivilegeDenied())
|
|
14903
|
+
return;
|
|
14835
14904
|
if (caddy)
|
|
14836
14905
|
return;
|
|
14837
|
-
caddy = new CaddyInstant();
|
|
14838
14906
|
let base = "/";
|
|
14839
14907
|
const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
|
|
14840
14908
|
if (typeof publicPath === "string" && publicPath) {
|
|
@@ -14844,13 +14912,23 @@ var unpluginFactory = (options) => ({
|
|
|
14844
14912
|
base = `/${base}`;
|
|
14845
14913
|
if (base !== "/" && !base.endsWith("/"))
|
|
14846
14914
|
base = `${base}/`;
|
|
14847
|
-
|
|
14915
|
+
const instance = new CaddyInstant();
|
|
14916
|
+
caddy = instance;
|
|
14917
|
+
instance.run(source, target, {
|
|
14848
14918
|
base,
|
|
14849
14919
|
...options
|
|
14850
14920
|
}).then(async () => {
|
|
14851
14921
|
await printForwardProxy();
|
|
14852
14922
|
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
14853
14923
|
}).catch((e) => {
|
|
14924
|
+
if (caddy === instance)
|
|
14925
|
+
caddy = void 0;
|
|
14926
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
14927
|
+
markPrivilegeDenied();
|
|
14928
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
14929
|
+
consola.info("Restart the dev server to enable it again.");
|
|
14930
|
+
return;
|
|
14931
|
+
}
|
|
14854
14932
|
throw e;
|
|
14855
14933
|
});
|
|
14856
14934
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/privilege-state.ts
|
|
2
|
+
var denied = false;
|
|
3
|
+
function markPrivilegeDenied() {
|
|
4
|
+
denied = true;
|
|
5
|
+
}
|
|
6
|
+
function isPrivilegeDenied() {
|
|
7
|
+
return denied;
|
|
8
|
+
}
|
|
9
|
+
function resetPrivilegeDenied() {
|
|
10
|
+
denied = false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
markPrivilegeDenied,
|
|
15
|
+
isPrivilegeDenied,
|
|
16
|
+
resetPrivilegeDenied
|
|
17
|
+
};
|
package/dist/esbuild.cjs
CHANGED
|
@@ -13678,16 +13678,28 @@ var import_node_process2 = __toESM(require("process"), 1);
|
|
|
13678
13678
|
function resolveHelperEntry(options) {
|
|
13679
13679
|
const { moduleDir, nodeBin = import_node_process2.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
|
|
13680
13680
|
for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
|
|
13681
|
-
const candidate = (
|
|
13682
|
-
if (
|
|
13681
|
+
const candidate = findUp(moduleDir, name, exists2);
|
|
13682
|
+
if (candidate)
|
|
13683
13683
|
return { entry: nodeBin, args: [candidate] };
|
|
13684
13684
|
}
|
|
13685
|
-
const source = (
|
|
13686
|
-
const tsxCli = (
|
|
13687
|
-
if (
|
|
13685
|
+
const source = findUp(moduleDir, "privileged-helper.ts", exists2);
|
|
13686
|
+
const tsxCli = findUp(moduleDir, "node_modules/tsx/dist/cli.mjs", exists2);
|
|
13687
|
+
if (source && tsxCli)
|
|
13688
13688
|
return { entry: nodeBin, args: [tsxCli, source] };
|
|
13689
13689
|
throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
|
|
13690
13690
|
}
|
|
13691
|
+
function findUp(from, relative, exists2) {
|
|
13692
|
+
let current = from;
|
|
13693
|
+
while (true) {
|
|
13694
|
+
const candidate = (0, import_node_path2.join)(current, relative);
|
|
13695
|
+
if (exists2(candidate))
|
|
13696
|
+
return candidate;
|
|
13697
|
+
const parent = (0, import_node_path2.dirname)(current);
|
|
13698
|
+
if (parent === current)
|
|
13699
|
+
return void 0;
|
|
13700
|
+
current = parent;
|
|
13701
|
+
}
|
|
13702
|
+
}
|
|
13691
13703
|
|
|
13692
13704
|
// src/privileged/session.ts
|
|
13693
13705
|
var import_node_buffer = require("buffer");
|
|
@@ -13986,18 +13998,42 @@ function spawnElevatedOnWindows(options) {
|
|
|
13986
13998
|
function createHelperToken() {
|
|
13987
13999
|
return (0, import_node_crypto.randomBytes)(24).toString("hex");
|
|
13988
14000
|
}
|
|
13989
|
-
function
|
|
14001
|
+
function describePasswordReason(target, https) {
|
|
14002
|
+
const port = https ? "443" : "80";
|
|
14003
|
+
return [
|
|
14004
|
+
`reverse proxy needs administrator permission for ${target}`,
|
|
14005
|
+
` \xB7 bind port ${port}${https ? ` for https://${target}` : ""}`,
|
|
14006
|
+
` \xB7 add ${target} to the hosts file`,
|
|
14007
|
+
"",
|
|
14008
|
+
"This is the only prompt; the rest of the dev server keeps running as you.",
|
|
14009
|
+
"Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
|
|
14010
|
+
];
|
|
14011
|
+
}
|
|
14012
|
+
function authenticateSudo(sudoCommand = "sudo", options = {}) {
|
|
13990
14013
|
if ((0, import_node_os3.platform)() === "win32")
|
|
13991
14014
|
return { ok: true };
|
|
13992
14015
|
if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
|
|
13993
14016
|
return { ok: true };
|
|
14017
|
+
if (options.target) {
|
|
14018
|
+
for (const line of describePasswordReason(options.target, options.https ?? false))
|
|
14019
|
+
import_node_process5.default.stderr.write(`${line}
|
|
14020
|
+
`);
|
|
14021
|
+
import_node_process5.default.stderr.write("\n");
|
|
14022
|
+
}
|
|
13994
14023
|
if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
|
|
13995
14024
|
return { ok: true };
|
|
13996
14025
|
return {
|
|
13997
14026
|
ok: false,
|
|
14027
|
+
denied: true,
|
|
13998
14028
|
message: "administrator permission is required to edit the hosts file and bind ports 80/443"
|
|
13999
14029
|
};
|
|
14000
14030
|
}
|
|
14031
|
+
var PrivilegeDeniedError = class extends Error {
|
|
14032
|
+
constructor(message) {
|
|
14033
|
+
super(message);
|
|
14034
|
+
this.name = "PrivilegeDeniedError";
|
|
14035
|
+
}
|
|
14036
|
+
};
|
|
14001
14037
|
async function startPrivilegedHelper(options) {
|
|
14002
14038
|
var _a4, _b3;
|
|
14003
14039
|
const {
|
|
@@ -14013,9 +14049,11 @@ async function startPrivilegedHelper(options) {
|
|
|
14013
14049
|
connectTimeoutMs = 12e4
|
|
14014
14050
|
} = options;
|
|
14015
14051
|
if (!skipAuth && !direct) {
|
|
14016
|
-
const auth = authenticateSudo(sudoCommand);
|
|
14017
|
-
if (!auth.ok)
|
|
14018
|
-
|
|
14052
|
+
const auth = authenticateSudo(sudoCommand, options.reason);
|
|
14053
|
+
if (!auth.ok) {
|
|
14054
|
+
const message = auth.message ?? "administrator permission is required";
|
|
14055
|
+
throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
|
|
14056
|
+
}
|
|
14019
14057
|
}
|
|
14020
14058
|
const forwarded = collectForwardedEnv(env2);
|
|
14021
14059
|
const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
|
|
@@ -14120,6 +14158,7 @@ async function openHelperSession(scope2) {
|
|
|
14120
14158
|
caddyStoragePath: scope2.caddyStoragePath,
|
|
14121
14159
|
caddyBin: scope2.caddyBin,
|
|
14122
14160
|
caddyConfigPath: scope2.caddyConfigPath,
|
|
14161
|
+
reason: scope2.reason,
|
|
14123
14162
|
log: scope2.log
|
|
14124
14163
|
});
|
|
14125
14164
|
await writeToken(scope2.runtimeDir, token);
|
|
@@ -14206,6 +14245,7 @@ function openPrivilegedSession(runtimeDir, options) {
|
|
|
14206
14245
|
// execute a path supplied over the socket.
|
|
14207
14246
|
caddyBin: options.caddyBin,
|
|
14208
14247
|
caddyConfigPath: options.caddyConfigPath,
|
|
14248
|
+
reason: options.reason,
|
|
14209
14249
|
log: options.log
|
|
14210
14250
|
});
|
|
14211
14251
|
}
|
|
@@ -14406,12 +14446,13 @@ function splitHostPort(addr) {
|
|
|
14406
14446
|
return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
|
|
14407
14447
|
}
|
|
14408
14448
|
var defaultDependencies = {
|
|
14409
|
-
openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
|
|
14449
|
+
openSession: (runtimeDir, reason) => openPrivilegedSession(runtimeDir, {
|
|
14410
14450
|
log: (message) => consola.debug(message),
|
|
14411
14451
|
// Both paths are fixed here, before any socket traffic: the privileged
|
|
14412
14452
|
// helper must never execute something named in a request.
|
|
14413
14453
|
caddyBin: caddyPath,
|
|
14414
|
-
caddyConfigPath: caddyFilePath
|
|
14454
|
+
caddyConfigPath: caddyFilePath,
|
|
14455
|
+
reason
|
|
14415
14456
|
})
|
|
14416
14457
|
};
|
|
14417
14458
|
var CaddyInstant = class {
|
|
@@ -14438,11 +14479,11 @@ var CaddyInstant = class {
|
|
|
14438
14479
|
* reused across instances so a second dev server does not ask for a
|
|
14439
14480
|
* password again.
|
|
14440
14481
|
*/
|
|
14441
|
-
async session() {
|
|
14482
|
+
async session(reason) {
|
|
14442
14483
|
if (this._session && !this._session.client.connected)
|
|
14443
14484
|
this._session = void 0;
|
|
14444
14485
|
if (!this._session)
|
|
14445
|
-
this._session = await this.deps.openSession(TEMP_DIR);
|
|
14486
|
+
this._session = await this.deps.openSession(TEMP_DIR, reason);
|
|
14446
14487
|
return this._session;
|
|
14447
14488
|
}
|
|
14448
14489
|
async getCaddyfile() {
|
|
@@ -14547,9 +14588,9 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14547
14588
|
this._target = target;
|
|
14548
14589
|
if (!this.inited)
|
|
14549
14590
|
await this.init();
|
|
14550
|
-
const session = await this.session();
|
|
14551
14591
|
const sourceHost = splitHostPort(source).host;
|
|
14552
14592
|
const targetHost = splitHostPort(target).host;
|
|
14593
|
+
const session = await this.session({ target: targetHost, https });
|
|
14553
14594
|
await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
|
|
14554
14595
|
consola.success("update host success\n");
|
|
14555
14596
|
const normalizeBase = (b) => {
|
|
@@ -14981,6 +15022,15 @@ var hmrSseBridgeClientScript = `
|
|
|
14981
15022
|
})();
|
|
14982
15023
|
`;
|
|
14983
15024
|
|
|
15025
|
+
// src/privilege-state.ts
|
|
15026
|
+
var denied = false;
|
|
15027
|
+
function markPrivilegeDenied() {
|
|
15028
|
+
denied = true;
|
|
15029
|
+
}
|
|
15030
|
+
function isPrivilegeDenied() {
|
|
15031
|
+
return denied;
|
|
15032
|
+
}
|
|
15033
|
+
|
|
14984
15034
|
// src/index.ts
|
|
14985
15035
|
var config;
|
|
14986
15036
|
var caddy;
|
|
@@ -15020,16 +15070,27 @@ async function printForwardProxy() {
|
|
|
15020
15070
|
}
|
|
15021
15071
|
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
15022
15072
|
_printUrls == null ? void 0 : _printUrls();
|
|
15073
|
+
if (isPrivilegeDenied())
|
|
15074
|
+
return;
|
|
15023
15075
|
if (caddy)
|
|
15024
15076
|
return;
|
|
15025
|
-
|
|
15026
|
-
caddy
|
|
15077
|
+
const instance = new CaddyInstant();
|
|
15078
|
+
caddy = instance;
|
|
15079
|
+
instance.run(source, target, {
|
|
15027
15080
|
base,
|
|
15028
15081
|
...options
|
|
15029
15082
|
}).then(async () => {
|
|
15030
15083
|
await printForwardProxy();
|
|
15031
15084
|
consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
15032
15085
|
}).catch((e) => {
|
|
15086
|
+
if (caddy === instance)
|
|
15087
|
+
caddy = void 0;
|
|
15088
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
15089
|
+
markPrivilegeDenied();
|
|
15090
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
15091
|
+
consola.info("Restart the dev server to enable it again.");
|
|
15092
|
+
return;
|
|
15093
|
+
}
|
|
15033
15094
|
throw e;
|
|
15034
15095
|
});
|
|
15035
15096
|
});
|
|
@@ -15109,6 +15170,8 @@ var unpluginFactory = (options) => ({
|
|
|
15109
15170
|
...(_a4 = import_node_process8.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
|
|
15110
15171
|
};
|
|
15111
15172
|
const source = `${devServer.host}:${devServer.port}`;
|
|
15173
|
+
if (isPrivilegeDenied())
|
|
15174
|
+
return;
|
|
15112
15175
|
if (caddy)
|
|
15113
15176
|
return;
|
|
15114
15177
|
let base = "/";
|
|
@@ -15130,8 +15193,9 @@ var unpluginFactory = (options) => ({
|
|
|
15130
15193
|
} else {
|
|
15131
15194
|
options.https = false;
|
|
15132
15195
|
}
|
|
15133
|
-
|
|
15134
|
-
caddy
|
|
15196
|
+
const instance = new CaddyInstant();
|
|
15197
|
+
caddy = instance;
|
|
15198
|
+
instance.run(source, target, {
|
|
15135
15199
|
base,
|
|
15136
15200
|
...options
|
|
15137
15201
|
}).then(() => {
|
|
@@ -15140,6 +15204,14 @@ var unpluginFactory = (options) => ({
|
|
|
15140
15204
|
consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
15141
15205
|
});
|
|
15142
15206
|
}).catch((e) => {
|
|
15207
|
+
if (caddy === instance)
|
|
15208
|
+
caddy = void 0;
|
|
15209
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
15210
|
+
markPrivilegeDenied();
|
|
15211
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
15212
|
+
consola.info("Restart the dev server to enable it again.");
|
|
15213
|
+
return;
|
|
15214
|
+
}
|
|
15143
15215
|
throw e;
|
|
15144
15216
|
});
|
|
15145
15217
|
},
|
|
@@ -15170,9 +15242,10 @@ var unpluginFactory = (options) => ({
|
|
|
15170
15242
|
}))) == null ? void 0 : _b3.content) == null ? void 0 : _c2.server
|
|
15171
15243
|
};
|
|
15172
15244
|
const source = `${devServer.host}:${devServer.port}`;
|
|
15245
|
+
if (isPrivilegeDenied())
|
|
15246
|
+
return;
|
|
15173
15247
|
if (caddy)
|
|
15174
15248
|
return;
|
|
15175
|
-
caddy = new CaddyInstant();
|
|
15176
15249
|
let base = "/";
|
|
15177
15250
|
const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
|
|
15178
15251
|
if (typeof publicPath === "string" && publicPath) {
|
|
@@ -15182,13 +15255,23 @@ var unpluginFactory = (options) => ({
|
|
|
15182
15255
|
base = `/${base}`;
|
|
15183
15256
|
if (base !== "/" && !base.endsWith("/"))
|
|
15184
15257
|
base = `${base}/`;
|
|
15185
|
-
|
|
15258
|
+
const instance = new CaddyInstant();
|
|
15259
|
+
caddy = instance;
|
|
15260
|
+
instance.run(source, target, {
|
|
15186
15261
|
base,
|
|
15187
15262
|
...options
|
|
15188
15263
|
}).then(async () => {
|
|
15189
15264
|
await printForwardProxy();
|
|
15190
15265
|
consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
15191
15266
|
}).catch((e) => {
|
|
15267
|
+
if (caddy === instance)
|
|
15268
|
+
caddy = void 0;
|
|
15269
|
+
if (e instanceof PrivilegeDeniedError) {
|
|
15270
|
+
markPrivilegeDenied();
|
|
15271
|
+
consola.warn("reverse proxy skipped: administrator permission was not granted.");
|
|
15272
|
+
consola.info("Restart the dev server to enable it again.");
|
|
15273
|
+
return;
|
|
15274
|
+
}
|
|
15192
15275
|
throw e;
|
|
15193
15276
|
});
|
|
15194
15277
|
}
|
package/dist/esbuild.js
CHANGED