@co0ontty/wand 1.41.0 → 1.41.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.
- package/dist/build-info.json +3 -3
- package/dist/server.js +52 -2
- package/package.json +1 -1
package/dist/build-info.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"commit": "
|
|
3
|
-
"builtAt": "2026-05-30T15:
|
|
4
|
-
"version": "1.41.
|
|
2
|
+
"commit": "7881848a909b65c2a17ee9d443514110e2e23f1f",
|
|
3
|
+
"builtAt": "2026-05-30T15:40:31.007Z",
|
|
4
|
+
"version": "1.41.1",
|
|
5
5
|
"channel": "stable"
|
|
6
6
|
}
|
package/dist/server.js
CHANGED
|
@@ -481,6 +481,56 @@ function verifyAppToken(token, password, secret) {
|
|
|
481
481
|
function encodeConnectCode(url, token) {
|
|
482
482
|
return Buffer.from(`${url}#${token}`).toString("base64");
|
|
483
483
|
}
|
|
484
|
+
function firstHeaderValue(value) {
|
|
485
|
+
if (Array.isArray(value))
|
|
486
|
+
return value[0];
|
|
487
|
+
return value;
|
|
488
|
+
}
|
|
489
|
+
function firstHeaderListValue(value) {
|
|
490
|
+
return firstHeaderValue(value)?.split(",")[0]?.trim();
|
|
491
|
+
}
|
|
492
|
+
function unquoteHeaderValue(value) {
|
|
493
|
+
const trimmed = value.trim();
|
|
494
|
+
if (trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
|
|
495
|
+
return trimmed.slice(1, -1);
|
|
496
|
+
}
|
|
497
|
+
return trimmed;
|
|
498
|
+
}
|
|
499
|
+
function getForwardedParam(req, key) {
|
|
500
|
+
const forwarded = firstHeaderListValue(req.headers.forwarded);
|
|
501
|
+
if (!forwarded)
|
|
502
|
+
return undefined;
|
|
503
|
+
const targetKey = key.toLowerCase();
|
|
504
|
+
for (const part of forwarded.split(";")) {
|
|
505
|
+
const eqIdx = part.indexOf("=");
|
|
506
|
+
if (eqIdx < 1)
|
|
507
|
+
continue;
|
|
508
|
+
const partKey = part.slice(0, eqIdx).trim().toLowerCase();
|
|
509
|
+
if (partKey !== targetKey)
|
|
510
|
+
continue;
|
|
511
|
+
return unquoteHeaderValue(part.slice(eqIdx + 1));
|
|
512
|
+
}
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
function normalizePublicProtocol(value) {
|
|
516
|
+
const proto = value?.trim().toLowerCase();
|
|
517
|
+
if (proto === "http" || proto === "https")
|
|
518
|
+
return proto;
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
function getPublicRequestProtocol(req, fallback) {
|
|
522
|
+
return (normalizePublicProtocol(firstHeaderListValue(req.headers["x-forwarded-proto"]))
|
|
523
|
+
?? normalizePublicProtocol(getForwardedParam(req, "proto"))
|
|
524
|
+
?? (firstHeaderListValue(req.headers["x-forwarded-ssl"])?.toLowerCase() === "on" ? "https" : undefined)
|
|
525
|
+
?? (firstHeaderListValue(req.headers["x-forwarded-scheme"])?.toLowerCase() === "https" ? "https" : undefined)
|
|
526
|
+
?? fallback);
|
|
527
|
+
}
|
|
528
|
+
function getPublicRequestHost(req, config) {
|
|
529
|
+
return (firstHeaderListValue(req.headers["x-forwarded-host"])
|
|
530
|
+
?? getForwardedParam(req, "host")
|
|
531
|
+
?? req.headers.host
|
|
532
|
+
?? `${config.host}:${config.port}`);
|
|
533
|
+
}
|
|
484
534
|
function decodeConnectCode(code) {
|
|
485
535
|
try {
|
|
486
536
|
const decoded = Buffer.from(code, "base64").toString("utf8");
|
|
@@ -1335,8 +1385,8 @@ export async function startServer(config, configPath) {
|
|
|
1335
1385
|
app.get("/api/app-connect-code", requireAuth, (req, res) => {
|
|
1336
1386
|
const dbPassword = storage.getPassword();
|
|
1337
1387
|
const effectivePassword = dbPassword ?? config.password;
|
|
1338
|
-
const protocol = useHttps ? "https" : "http";
|
|
1339
|
-
const host = req
|
|
1388
|
+
const protocol = getPublicRequestProtocol(req, useHttps ? "https" : "http");
|
|
1389
|
+
const host = getPublicRequestHost(req, config);
|
|
1340
1390
|
const serverUrl = `${protocol}://${host}`;
|
|
1341
1391
|
const appSecret = config.appSecret ?? "";
|
|
1342
1392
|
const token = generateAppToken(effectivePassword, appSecret);
|