@hyperframes/inspector 0.9.31 → 0.9.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/server.js
CHANGED
|
@@ -5,6 +5,15 @@ import { createRequire } from "node:module"; const require = createRequire(impor
|
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import { readFileSync, realpathSync } from "node:fs";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
|
+
|
|
9
|
+
// src/pageServer.ts
|
|
10
|
+
function isLoopbackHost(host) {
|
|
11
|
+
if (!host) return true;
|
|
12
|
+
const name = host.replace(/:\d+$/, "").replace(/^\[|\]$/g, "").toLowerCase();
|
|
13
|
+
return name === "127.0.0.1" || name === "localhost" || name === "::1";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/server.ts
|
|
8
17
|
import { Inspector } from "./service.js";
|
|
9
18
|
var version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
10
19
|
var MAX_BODY = 64e3;
|
|
@@ -22,11 +31,6 @@ function failureOf(error) {
|
|
|
22
31
|
if (!(error instanceof Error)) return { status: 500, message: "internal_error" };
|
|
23
32
|
return { status: message === "no-composition" ? 404 : 400, message };
|
|
24
33
|
}
|
|
25
|
-
function loopback(host) {
|
|
26
|
-
if (!host) return true;
|
|
27
|
-
const name = host.replace(/:\d+$/, "").replace(/^\[|\]$/g, "").toLowerCase();
|
|
28
|
-
return name === "127.0.0.1" || name === "localhost" || name === "::1";
|
|
29
|
-
}
|
|
30
34
|
function readBody(req) {
|
|
31
35
|
return new Promise((resolve, reject) => {
|
|
32
36
|
const chunks = [];
|
|
@@ -62,7 +66,7 @@ function createInspectorServer(project) {
|
|
|
62
66
|
const inspector = new Inspector(project);
|
|
63
67
|
const server = createServer(async (req, res) => {
|
|
64
68
|
res.setHeader("Content-Type", "application/json");
|
|
65
|
-
if (!
|
|
69
|
+
if (!isLoopbackHost(req.headers.host)) {
|
|
66
70
|
send(res, 403, "host_not_allowed");
|
|
67
71
|
return;
|
|
68
72
|
}
|