@jondotsoy/envs 0.1.9-alpha.3 → 0.1.9-alpha.4
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/envs.js +17 -3
- package/package.json +1 -1
package/envs.js
CHANGED
|
@@ -503,6 +503,12 @@ async function serveUi(ctx) {
|
|
|
503
503
|
let token = randomBytes(24).toString("base64url");
|
|
504
504
|
const session = randomBytes(24).toString("base64url");
|
|
505
505
|
const guard = (handler) => async (req) => {
|
|
506
|
+
const res = await check(req, handler);
|
|
507
|
+
for (const [name, value] of Object.entries(HARDENING_HEADERS))
|
|
508
|
+
res.headers.set(name, value);
|
|
509
|
+
return res;
|
|
510
|
+
};
|
|
511
|
+
const check = async (req, handler) => {
|
|
506
512
|
const port = server.port;
|
|
507
513
|
const hosts = [`127.0.0.1:${port}`, `localhost:${port}`];
|
|
508
514
|
if (!hosts.includes(req.headers.get("host") ?? "")) {
|
|
@@ -513,7 +519,7 @@ async function serveUi(ctx) {
|
|
|
513
519
|
return new Response("Forbidden origin", { status: 403 });
|
|
514
520
|
}
|
|
515
521
|
const url = new URL(req.url);
|
|
516
|
-
if (url.pathname === "/" && sameToken(url.searchParams.get("token"), token)) {
|
|
522
|
+
if (req.method === "GET" && url.pathname === "/" && sameToken(url.searchParams.get("token"), token)) {
|
|
517
523
|
token = randomBytes(24).toString("base64url");
|
|
518
524
|
ctx.log(`New single-use URL: ${urlWith(token)}`);
|
|
519
525
|
opened?.then((cleanup) => cleanup?.(), () => {});
|
|
@@ -521,13 +527,16 @@ async function serveUi(ctx) {
|
|
|
521
527
|
status: 302,
|
|
522
528
|
headers: {
|
|
523
529
|
location: "/",
|
|
524
|
-
"set-cookie": `${TOKEN_COOKIE}=${session}; HttpOnly; SameSite=
|
|
530
|
+
"set-cookie": `${TOKEN_COOKIE}=${session}; HttpOnly; SameSite=Lax; Path=/`
|
|
525
531
|
}
|
|
526
532
|
});
|
|
527
533
|
}
|
|
528
534
|
if (!sameToken(presentedToken(req), session)) {
|
|
529
535
|
return new Response("Unauthorized: open the address printed by `envs edit --ui`.", { status: 401 });
|
|
530
536
|
}
|
|
537
|
+
if (!["GET", "HEAD", "PUT", "POST"].includes(req.method)) {
|
|
538
|
+
return new Response("Method not allowed", { status: 405, headers: { allow: "GET, HEAD, PUT, POST" } });
|
|
539
|
+
}
|
|
531
540
|
if (req.method !== "GET" && req.method !== "HEAD" && !req.headers.get("content-type")?.toLowerCase().startsWith("application/json")) {
|
|
532
541
|
return new Response("Unsupported media type", { status: 415 });
|
|
533
542
|
}
|
|
@@ -592,10 +601,15 @@ async function serveUi(ctx) {
|
|
|
592
601
|
await server.stop(true);
|
|
593
602
|
return 0;
|
|
594
603
|
}
|
|
595
|
-
var ANSI, isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v), isScalar = (v) => ["string", "number", "boolean"].includes(typeof v), TOKEN_COOKIE = "envs_token", MAX_BODY_BYTES;
|
|
604
|
+
var ANSI, isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v), isScalar = (v) => ["string", "number", "boolean"].includes(typeof v), TOKEN_COOKIE = "envs_token", HARDENING_HEADERS, MAX_BODY_BYTES;
|
|
596
605
|
var init_server = __esm(() => {
|
|
597
606
|
init_envs();
|
|
598
607
|
ANSI = /\x1b\[[0-9;]*m/g;
|
|
608
|
+
HARDENING_HEADERS = {
|
|
609
|
+
"x-content-type-options": "nosniff",
|
|
610
|
+
"content-security-policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
|
|
611
|
+
"referrer-policy": "no-referrer"
|
|
612
|
+
};
|
|
599
613
|
MAX_BODY_BYTES = 5 * 1024 * 1024;
|
|
600
614
|
});
|
|
601
615
|
|