hanoman 0.1.32 → 0.1.33
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
CHANGED
package/dist/server.js
CHANGED
|
@@ -29930,11 +29930,32 @@ function wsControlOrigins(env) {
|
|
|
29930
29930
|
function assertWsOrigin(origin, allowed) {
|
|
29931
29931
|
if (!origin || !allowed.has(origin)) throw new Error("WebSocket Origin rejected");
|
|
29932
29932
|
}
|
|
29933
|
+
function wsAllowlistFor(configured, host2, env) {
|
|
29934
|
+
if (configured.size > 0 || env.NODE_ENV === "production") return configured;
|
|
29935
|
+
const value = host2?.trim().toLowerCase();
|
|
29936
|
+
if (!value) return configured;
|
|
29937
|
+
let parsed;
|
|
29938
|
+
try {
|
|
29939
|
+
parsed = new URL(`http://${value}`);
|
|
29940
|
+
} catch {
|
|
29941
|
+
return configured;
|
|
29942
|
+
}
|
|
29943
|
+
if (!parsed.host || parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) return configured;
|
|
29944
|
+
const hosts = /* @__PURE__ */ new Set([parsed.host]);
|
|
29945
|
+
if (parsed.port === "80" || parsed.port === "443") hosts.add(parsed.hostname);
|
|
29946
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
29947
|
+
for (const candidate of hosts) {
|
|
29948
|
+
allowed.add(`http://${candidate}`);
|
|
29949
|
+
allowed.add(`https://${candidate}`);
|
|
29950
|
+
}
|
|
29951
|
+
return allowed;
|
|
29952
|
+
}
|
|
29933
29953
|
function admitBrowserWs(req, target2, allowedOrigins) {
|
|
29934
29954
|
const origin = typeof req.headers.origin === "string" ? req.headers.origin : void 0;
|
|
29935
29955
|
if (!origin && process.env.NODE_ENV === "test" && allowedOrigins.size === 0)
|
|
29936
29956
|
return { kind: "test", id: "test" };
|
|
29937
|
-
|
|
29957
|
+
const host2 = typeof req.headers.host === "string" ? req.headers.host : void 0;
|
|
29958
|
+
assertWsOrigin(origin, wsAllowlistFor(allowedOrigins, host2, process.env));
|
|
29938
29959
|
const token = ticketFromProtocol(req.headers["sec-websocket-protocol"]);
|
|
29939
29960
|
if (!token) throw new Error("WebSocket ticket required");
|
|
29940
29961
|
const principal = consumeWsTicket(token, target2);
|