Restrict the Node server to a private address and document the host
The site port answered directly on the VM's public address, bypassing the proxy and letting clients forge X-Forwarded-For. HOST now limits where it listens. The Cards database and backups move to /data with owner-only folders, and SERVER.md describes the Proxmox VMs, ports and open points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a32956e49b
commit
5891320e1a
7 changed files with 156 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ import { connect } from "node:net";
|
|||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { test } from "node:test";
|
||||
import { createCardsApi, createStaticServer } from "../server.mjs";
|
||||
import { createCardsApi, createStaticServer, startServer } from "../server.mjs";
|
||||
import { createCardsApiHandler, createRateLimiter } from "../services/cards/api.js";
|
||||
|
||||
const projectRoot = resolve(".");
|
||||
|
|
@ -124,3 +124,28 @@ test("the rate limiter forgets past minutes instead of growing without bound", (
|
|||
for (let index = 1; index < 60; index += 1) limiter(request("10.0.0.1"), "api");
|
||||
assert.throws(() => limiter(request("10.0.0.1"), "api"), /Trop de tentatives/);
|
||||
});
|
||||
|
||||
test("the server only listens on the HOST address when it is configured", async (t) => {
|
||||
const originalEnv = { HOST: process.env.HOST, PORT: process.env.PORT };
|
||||
const originalLog = console.log;
|
||||
console.log = () => {};
|
||||
t.after(() => {
|
||||
console.log = originalLog;
|
||||
for (const [name, value] of Object.entries(originalEnv)) {
|
||||
if (value === undefined) delete process.env[name];
|
||||
else process.env[name] = value;
|
||||
}
|
||||
});
|
||||
const listenOn = async (host) => {
|
||||
if (host) process.env.HOST = host;
|
||||
else delete process.env.HOST;
|
||||
process.env.PORT = "0";
|
||||
const server = startServer({ cardsApiOptions: { enabled: false } });
|
||||
await new Promise((resolvePromise) => server.once("listening", resolvePromise));
|
||||
const { address } = server.address();
|
||||
await new Promise((resolvePromise) => server.close(resolvePromise));
|
||||
return address;
|
||||
};
|
||||
assert.equal(await listenOn("127.0.0.1"), "127.0.0.1");
|
||||
assert.equal(await listenOn(""), "::");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue