@hadoku/service-kernel 0.1.31 → 0.1.32
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/lifecycle/busy.d.ts
CHANGED
|
@@ -52,6 +52,14 @@ export interface BusyReport {
|
|
|
52
52
|
count: number;
|
|
53
53
|
runs: BusyRun[];
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* How a request reached this server, read from the headers alone: `edge` when it carries the
|
|
57
|
+
* edge's seal header (claimed, not verified: a forged one still reads `edge`, and so still alerts),
|
|
58
|
+
* `tunnel` when Cloudflare proxied it but the edge did not (a direct hit on the tunnel hostname),
|
|
59
|
+
* `local` when nothing proxied it (a probe from this host). A remote caller cannot read as `local`:
|
|
60
|
+
* it cannot strip the headers Cloudflare adds after it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function arrivedVia(headers: Record<string, unknown>): 'edge' | 'tunnel' | 'local';
|
|
55
63
|
export declare function isLocalProbe(req: Pick<Request, 'socket' | 'headers'>): boolean;
|
|
56
64
|
/** `report` computes the app's own `BusyReport`; this adds the local-only gate and fail-safe. */
|
|
57
65
|
export declare function busyHandler(report: () => BusyReport): RequestHandler;
|
package/dist/lifecycle/busy.js
CHANGED
|
@@ -16,11 +16,23 @@ const PROXIED_HEADERS = [
|
|
|
16
16
|
'forwarded',
|
|
17
17
|
'x-edge-auth',
|
|
18
18
|
];
|
|
19
|
+
/**
|
|
20
|
+
* How a request reached this server, read from the headers alone: `edge` when it carries the
|
|
21
|
+
* edge's seal header (claimed, not verified: a forged one still reads `edge`, and so still alerts),
|
|
22
|
+
* `tunnel` when Cloudflare proxied it but the edge did not (a direct hit on the tunnel hostname),
|
|
23
|
+
* `local` when nothing proxied it (a probe from this host). A remote caller cannot read as `local`:
|
|
24
|
+
* it cannot strip the headers Cloudflare adds after it.
|
|
25
|
+
*/
|
|
26
|
+
export function arrivedVia(headers) {
|
|
27
|
+
if (headers['x-edge-auth'] !== undefined)
|
|
28
|
+
return 'edge';
|
|
29
|
+
return PROXIED_HEADERS.some((h) => headers[h] !== undefined) ? 'tunnel' : 'local';
|
|
30
|
+
}
|
|
19
31
|
export function isLocalProbe(req) {
|
|
20
32
|
const addr = req.socket?.remoteAddress;
|
|
21
33
|
if (addr === undefined || !LOOPBACK.has(addr))
|
|
22
34
|
return false;
|
|
23
|
-
return
|
|
35
|
+
return arrivedVia(req.headers) === 'local';
|
|
24
36
|
}
|
|
25
37
|
/** `report` computes the app's own `BusyReport`; this adds the local-only gate and fail-safe. */
|
|
26
38
|
export function busyHandler(report) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { busyHandler, isLocalProbe, type BusyReport, type BusyRun } from './busy.js';
|
|
1
|
+
export { arrivedVia, busyHandler, isLocalProbe, type BusyReport, type BusyRun } from './busy.js';
|
|
2
2
|
export { bootClock } from './bootClock.js';
|
|
3
3
|
export { closeConnections, sendThenFlush, type Closable, type Flushable } from './flush-sockets.js';
|
|
4
4
|
export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, type AnnounceOptions, type CreditCount, type Embed, type ReleaseNotes, type ReleaseOrdering, } from './announce.js';
|
package/dist/lifecycle/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { busyHandler, isLocalProbe } from "./busy.js";
|
|
1
|
+
export { arrivedVia, busyHandler, isLocalProbe } from "./busy.js";
|
|
2
2
|
export { bootClock } from "./bootClock.js";
|
|
3
3
|
export { closeConnections, sendThenFlush } from "./flush-sockets.js";
|
|
4
4
|
export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, } from "./announce.js";
|
|
@@ -76,11 +76,11 @@ export declare function userAgentOf(headers: Headers): string | null;
|
|
|
76
76
|
*/
|
|
77
77
|
export declare function callerContext(headers: Headers): TelemetryContext;
|
|
78
78
|
/**
|
|
79
|
-
* A seal below the edge refused a caller.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* it to a closed set.
|
|
79
|
+
* A seal below the edge refused a caller. `via` ({@link arrivedVia}) says which kind: `edge` is an
|
|
80
|
+
* edge rule wider than this server's floor and needs a look now; `tunnel` is a direct hit on the
|
|
81
|
+
* tunnel hostname and `local` a probe from this host, both refused as they should be (a public
|
|
82
|
+
* tunnel hostname is scanned daily). `Surface` is an open string: this module knows no game's
|
|
83
|
+
* surface names, so the app's own adapter narrows it to a closed set.
|
|
84
84
|
*/
|
|
85
85
|
export declare function reportSealRefused<Surface extends string>(surface: Surface, headers: Headers, path: string | null): void;
|
|
86
86
|
export interface FirstSeenOptions {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* scanner hammering the seal costs monitoring one row a minute, not one per request.
|
|
12
12
|
*/
|
|
13
13
|
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { arrivedVia } from "../lifecycle/busy.js";
|
|
14
15
|
/** What `report` does before boot installs a sink, and in every test that installs none. */
|
|
15
16
|
const NOOP = () => { };
|
|
16
17
|
let installed = NOOP;
|
|
@@ -148,14 +149,14 @@ export function callerContext(headers) {
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
/**
|
|
151
|
-
* A seal below the edge refused a caller.
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* it to a closed set.
|
|
152
|
+
* A seal below the edge refused a caller. `via` ({@link arrivedVia}) says which kind: `edge` is an
|
|
153
|
+
* edge rule wider than this server's floor and needs a look now; `tunnel` is a direct hit on the
|
|
154
|
+
* tunnel hostname and `local` a probe from this host, both refused as they should be (a public
|
|
155
|
+
* tunnel hostname is scanned daily). `Surface` is an open string: this module knows no game's
|
|
156
|
+
* surface names, so the app's own adapter narrows it to a closed set.
|
|
156
157
|
*/
|
|
157
158
|
export function reportSealRefused(surface, headers, path) {
|
|
158
|
-
report('seal-refused', { surface, path, ...callerContext(headers) });
|
|
159
|
+
report('seal-refused', { surface, path, via: arrivedVia(headers), ...callerContext(headers) });
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
161
162
|
* Middleware, mounted below the tier floor: the first request this server ever
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/service-kernel",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.32",
|
|
4
|
+
"gitHead": "103d8667e71b18c56446a9d5a884b551c079732c",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The server parts any game keeps: edge auth and the tier gate, base path and bundle check, health and the busy probe, lifecycle, the JSON logger, the state directory, telemetry and capacity, per-caller limits, the browser relays, the erase registry, and createGameServer, which boots a game from its config and plugins. Knows no game; the app binds its service id, prefix and env names. MIT; imports only node built-ins, express, socket.io and @wolffm/*.",
|