@buffcore/config 0.8.47 → 0.8.48
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/debug-options.d.ts +55 -0
- package/dist/debug-options.js +63 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/product.d.ts +6 -0
- package/dist/product.js +5 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.js +29 -0
- package/package.json +2 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hardening` in `buffcore.config.ts`: a product that holds a secret in a process's memory for a
|
|
3
|
+
* moment can ask that nobody attach a debugger to its server and processes or make them write
|
|
4
|
+
* their memory to a file (a heap snapshot, a report, a core dump). Off by default, except the
|
|
5
|
+
* core-file limit of 0 that production and staging compose files carry unless turned off.
|
|
6
|
+
*/
|
|
7
|
+
export interface Hardening {
|
|
8
|
+
/**
|
|
9
|
+
* Default `false`. On: the API and each declared Node process refuse to start when Node's
|
|
10
|
+
* debugging or dump options reach them, on the command line or in `NODE_OPTIONS`
|
|
11
|
+
* (`DEBUG_OPTION`). `ape dev` and `ape server setup` refuse them before starting anything, since
|
|
12
|
+
* `--inspect-brk` and `--inspect-wait` pause Node before any code runs.
|
|
13
|
+
*/
|
|
14
|
+
refuseDebugOptions?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Default `false`: on a server, the API and each declared process run with a core-file limit
|
|
17
|
+
* of 0, so a crash writes no core dump of its memory. `true` keeps Docker's default, for a
|
|
18
|
+
* product that needs core files.
|
|
19
|
+
*/
|
|
20
|
+
coreDumps?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Node's options that attach a debugger or write the process's memory or state to a file:
|
|
24
|
+
* `--inspect*` (`--inspect-brk`, `--inspect-wait`, `--inspect-port`), `--debug-port`, the heap
|
|
25
|
+
* snapshot ones, `--diagnostic-dir` and `--report-*`. Node reads `_` as `-` in an option's name.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEBUG_OPTION: RegExp;
|
|
28
|
+
/**
|
|
29
|
+
* The words of a `NODE_OPTIONS` value, split on spaces and kept as they are. Node reads `"`
|
|
30
|
+
* anywhere in a word as a quote and `\` as an escape (`--in"spect"` is `--inspect`), so a word
|
|
31
|
+
* holding either is refused whole (`debugOptionsIn`) rather than parsed a second way here.
|
|
32
|
+
*/
|
|
33
|
+
export declare const nodeOptionsWords: (value: string | undefined) => string[];
|
|
34
|
+
/**
|
|
35
|
+
* The debugging and dump options among Node's arguments and a `NODE_OPTIONS` value, and any
|
|
36
|
+
* `NODE_OPTIONS` word with a quote or a backslash (it may spell one).
|
|
37
|
+
*/
|
|
38
|
+
export declare function debugOptionsIn(args: readonly string[], nodeOptions?: string): string[];
|
|
39
|
+
/** Why a process refuses to start, naming what it was given. */
|
|
40
|
+
export declare const refusedMessage: (found: readonly string[]) => string;
|
|
41
|
+
/**
|
|
42
|
+
* The module the API and each declared Node process import before their entry
|
|
43
|
+
* (`node --import=<this> <entry>`): it needs no file and no package, so the same text works in
|
|
44
|
+
* any image. It exits 1 with `refusedMessage` when its command line or `NODE_OPTIONS` carries a
|
|
45
|
+
* debugging or dump option (or a quoted word), and when one is on all the same: the inspector
|
|
46
|
+
* listening, or a report set to be written. Otherwise it does nothing and the entry runs.
|
|
47
|
+
*/
|
|
48
|
+
export declare function refuseDebugImport(): string;
|
|
49
|
+
/**
|
|
50
|
+
* What a start (`ape dev`, `ape server setup`) refuses before starting anything when the product
|
|
51
|
+
* turns `refuseDebugOptions` on: the debugging and dump options in a `NODE_OPTIONS` it would
|
|
52
|
+
* pass on (the shell's, a settings file's), since Node reads it before any code runs. The caller
|
|
53
|
+
* says so in its own words.
|
|
54
|
+
*/
|
|
55
|
+
export declare function debugStartOptions(hardening: Hardening | undefined, nodeOptions: readonly (string | undefined)[]): string[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's options that attach a debugger or write the process's memory or state to a file:
|
|
3
|
+
* `--inspect*` (`--inspect-brk`, `--inspect-wait`, `--inspect-port`), `--debug-port`, the heap
|
|
4
|
+
* snapshot ones, `--diagnostic-dir` and `--report-*`. Node reads `_` as `-` in an option's name.
|
|
5
|
+
*/
|
|
6
|
+
export const DEBUG_OPTION = /^--(inspect[a-z-]*|debug-port|heap-?snapshot[a-z-]*|diagnostic-dir|report-[a-z-]+)(=.*)?$/;
|
|
7
|
+
/** The option's name with Node's `_` read as `-`, its value left as it is. */
|
|
8
|
+
const named = (arg) => arg.replace(/^[^=]+/, (name) => name.replaceAll('_', '-'));
|
|
9
|
+
/**
|
|
10
|
+
* The words of a `NODE_OPTIONS` value, split on spaces and kept as they are. Node reads `"`
|
|
11
|
+
* anywhere in a word as a quote and `\` as an escape (`--in"spect"` is `--inspect`), so a word
|
|
12
|
+
* holding either is refused whole (`debugOptionsIn`) rather than parsed a second way here.
|
|
13
|
+
*/
|
|
14
|
+
export const nodeOptionsWords = (value) => (value ?? '').split(SPACES).filter(Boolean);
|
|
15
|
+
const SPACES = /\s+/;
|
|
16
|
+
/** A `NODE_OPTIONS` word Node would read differently from how it is written. */
|
|
17
|
+
const QUOTED = /["\\]/;
|
|
18
|
+
/**
|
|
19
|
+
* The debugging and dump options among Node's arguments and a `NODE_OPTIONS` value, and any
|
|
20
|
+
* `NODE_OPTIONS` word with a quote or a backslash (it may spell one).
|
|
21
|
+
*/
|
|
22
|
+
export function debugOptionsIn(args, nodeOptions) {
|
|
23
|
+
const words = nodeOptionsWords(nodeOptions);
|
|
24
|
+
return [
|
|
25
|
+
...args.filter((arg) => DEBUG_OPTION.test(named(arg))),
|
|
26
|
+
...words.filter((word) => QUOTED.test(word) || DEBUG_OPTION.test(named(word))),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
/** Why a process refuses to start, naming what it was given. */
|
|
30
|
+
export const refusedMessage = (found) => `buffcore.config.ts turns hardening.refuseDebugOptions on, so this process does not start with Node's debugging or dump options, or a NODE_OPTIONS word with a quote or a backslash (${found.join(', ')}). Remove them from the command line and NODE_OPTIONS.`;
|
|
31
|
+
/**
|
|
32
|
+
* The module the API and each declared Node process import before their entry
|
|
33
|
+
* (`node --import=<this> <entry>`): it needs no file and no package, so the same text works in
|
|
34
|
+
* any image. It exits 1 with `refusedMessage` when its command line or `NODE_OPTIONS` carries a
|
|
35
|
+
* debugging or dump option (or a quoted word), and when one is on all the same: the inspector
|
|
36
|
+
* listening, or a report set to be written. Otherwise it does nothing and the entry runs.
|
|
37
|
+
*/
|
|
38
|
+
export function refuseDebugImport() {
|
|
39
|
+
const code = [
|
|
40
|
+
`import{url}from'node:inspector';`,
|
|
41
|
+
`const o=${DEBUG_OPTION};const q=${QUOTED};`,
|
|
42
|
+
`const n=(a)=>a.replace(/^[^=]+/,(s)=>s.replaceAll('_','-'));`,
|
|
43
|
+
`const w=(process.env.NODE_OPTIONS??'').split(${SPACES}).filter(Boolean);`,
|
|
44
|
+
`const f=[...process.execArgv.filter((a)=>o.test(n(a))),...w.filter((a)=>q.test(a)||o.test(n(a)))];`,
|
|
45
|
+
`const r=process.report??{};`,
|
|
46
|
+
`if(url())f.push('inspector '+url());`,
|
|
47
|
+
`for(const k of['reportOnSignal','reportOnFatalError','reportOnUncaughtException'])if(r[k])f.push('process.report.'+k);`,
|
|
48
|
+
`if(r.directory)f.push('process.report.directory');`,
|
|
49
|
+
`if(f.length){console.error(${JSON.stringify(refusedMessage(['%s']))}.replace('%s',f.join(', ')));process.exit(1);}`,
|
|
50
|
+
].join('');
|
|
51
|
+
return `data:text/javascript,${encodeURIComponent(code)}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a start (`ape dev`, `ape server setup`) refuses before starting anything when the product
|
|
55
|
+
* turns `refuseDebugOptions` on: the debugging and dump options in a `NODE_OPTIONS` it would
|
|
56
|
+
* pass on (the shell's, a settings file's), since Node reads it before any code runs. The caller
|
|
57
|
+
* says so in its own words.
|
|
58
|
+
*/
|
|
59
|
+
export function debugStartOptions(hardening, nodeOptions) {
|
|
60
|
+
if (hardening?.refuseDebugOptions !== true)
|
|
61
|
+
return [];
|
|
62
|
+
return nodeOptions.flatMap((value) => debugOptionsIn([], value));
|
|
63
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { AgentLimits } from './agents.ts';
|
|
2
|
+
export { DEBUG_OPTION, debugOptionsIn, debugStartOptions, type Hardening, nodeOptionsWords, refuseDebugImport, refusedMessage, } from './debug-options.ts';
|
|
2
3
|
export { type CoreEnv, coreEnvSchema, defineEnv, ENVIRONMENTS, EnvError, productionSetup, } from './env.ts';
|
|
3
4
|
export { isUploadKind, uploadKindsFit } from './extension-grants.ts';
|
|
4
5
|
export { type ContainerProcess, DEFAULT_PROCESS_SIZE, isContainer, type NodeProcess, type ProcessSize, type ProductProcess, } from './processes.ts';
|
|
5
6
|
export { CATALOG_KEY, type ConnectConfig, defineProduct, type ExtensionGrant, FEATURES, type Feature, isEnabled, LEAKED_PASSWORDS, type LeakedPasswords, OPERATOR_PASSKEYS, type OperatorPasskeys, PLATFORMS, type Platform, type ProductConfig, ProductConfigError, type PrototypeConfig, type SessionLength, SIGN_IN_METHODS, type SignInConfig, type SignInMethod, sessionHours, signInSettings, } from './product.ts';
|
|
6
7
|
export { defineScenes, type Flow, FRAME_SIZES, FRAMES, type Frame, type FrameSize, frameSizes, type LayoutException, type Scene, type SceneInput, type Scenes, ScenesError, type SceneViews, SURFACES, type Surface, sceneUrl, } from './scenes.ts';
|
|
8
|
+
export { type ServerConfig, SYSTEM_PACKAGE, serverProblems } from './server.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { DEBUG_OPTION, debugOptionsIn, debugStartOptions, nodeOptionsWords, refuseDebugImport, refusedMessage, } from './debug-options.js';
|
|
1
2
|
export { coreEnvSchema, defineEnv, ENVIRONMENTS, EnvError, productionSetup, } from './env.js';
|
|
2
3
|
export { isUploadKind, uploadKindsFit } from './extension-grants.js';
|
|
3
4
|
export { DEFAULT_PROCESS_SIZE, isContainer, } from './processes.js';
|
|
4
5
|
export { CATALOG_KEY, defineProduct, FEATURES, isEnabled, LEAKED_PASSWORDS, OPERATOR_PASSKEYS, PLATFORMS, ProductConfigError, SIGN_IN_METHODS, sessionHours, signInSettings, } from './product.js';
|
|
5
6
|
export { defineScenes, FRAME_SIZES, FRAMES, frameSizes, ScenesError, SURFACES, sceneUrl, } from './scenes.js';
|
|
7
|
+
export { SYSTEM_PACKAGE, serverProblems } from './server.js';
|
package/dist/product.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type AgentLimits } from './agents.ts';
|
|
2
|
+
import type { Hardening } from './debug-options.ts';
|
|
2
3
|
import { type ExtensionGrant } from './extension-grants.ts';
|
|
3
4
|
import { type ProductProcess } from './processes.ts';
|
|
5
|
+
import { type ServerConfig } from './server.ts';
|
|
4
6
|
export type { ExtensionGrant } from './extension-grants.ts';
|
|
5
7
|
export declare const PLATFORMS: readonly ['web', 'ios', 'android'];
|
|
6
8
|
export type Platform = (typeof PLATFORMS)[number];
|
|
@@ -168,6 +170,8 @@ export interface ProductConfig {
|
|
|
168
170
|
signIn?: SignInConfig;
|
|
169
171
|
/** What runs beside the API: Node processes (a worker) and containers (`processes.ts`). */
|
|
170
172
|
processes?: readonly ProductProcess[];
|
|
173
|
+
/** Debugging and dump options refused at start, and core dumps on a server (`debug-options.ts`). */
|
|
174
|
+
hardening?: Hardening;
|
|
171
175
|
/** What machines (API keys, MCP clients) and agents may receive (CONNECT.md). */
|
|
172
176
|
connect?: ConnectConfig;
|
|
173
177
|
/**
|
|
@@ -188,6 +192,8 @@ export interface ProductConfig {
|
|
|
188
192
|
agents?: AgentLimits;
|
|
189
193
|
/** How the prototype shows its scenes (PROTOTYPE.md). */
|
|
190
194
|
prototype?: PrototypeConfig;
|
|
195
|
+
/** What the server image holds beyond BuffCore's own: Debian system packages (`server.ts`). */
|
|
196
|
+
server?: ServerConfig;
|
|
191
197
|
}
|
|
192
198
|
export interface PrototypeConfig {
|
|
193
199
|
/**
|
package/dist/product.js
CHANGED
|
@@ -6,6 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import { agentProblems } from './agents.js';
|
|
7
7
|
import { grantProblems } from './extension-grants.js';
|
|
8
8
|
import { processProblems } from './processes.js';
|
|
9
|
+
import { serverProblems } from './server.js';
|
|
9
10
|
export const PLATFORMS = ['web', 'ios', 'android'];
|
|
10
11
|
/** The feature catalog: what each needs, and the BuffCore release that brings it. */
|
|
11
12
|
export const FEATURES = {
|
|
@@ -177,12 +178,16 @@ export function defineProduct(config) {
|
|
|
177
178
|
problems.push(`${kind} sessions need a length above zero`);
|
|
178
179
|
}
|
|
179
180
|
problems.push(...processProblems(config.processes ?? []));
|
|
181
|
+
for (const [key, value] of Object.entries(config.hardening ?? {}))
|
|
182
|
+
if (typeof value !== 'boolean')
|
|
183
|
+
problems.push(`hardening.${key} is true or false`);
|
|
180
184
|
problems.push(...grantProblems(config.extensions ?? {}));
|
|
181
185
|
problems.push(...catalogProblems(config.catalog));
|
|
182
186
|
problems.push(...proxyProblems(config.trustedProxies));
|
|
183
187
|
if (config.agents)
|
|
184
188
|
problems.push(...agentProblems(config.agents));
|
|
185
189
|
problems.push(...prototypeProblems(config.prototype));
|
|
190
|
+
problems.push(...serverProblems(config.server));
|
|
186
191
|
if (problems.length > 0) {
|
|
187
192
|
throw new ProductConfigError(`buffcore.config.ts:\n${problems.map((p) => ` ${p}`).join('\n')}`);
|
|
188
193
|
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `server` in `buffcore.config.ts`: what the product's server image holds beyond BuffCore's own.
|
|
3
|
+
*
|
|
4
|
+
* `systemPackages` are Debian package names (`openssh-client`, `poppler-utils`) for programs the
|
|
5
|
+
* API starts itself, with a fixed argument list. `ape deploy` and `ape build server` install them
|
|
6
|
+
* in the image's last stage, as root, before it drops to the API's user, and record the versions
|
|
7
|
+
* installed beside the image. A changed list is a changed image.
|
|
8
|
+
*/
|
|
9
|
+
export interface ServerConfig {
|
|
10
|
+
systemPackages?: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A Debian package name: lowercase letters, digits and `+ . -`, starting with a letter or digit,
|
|
14
|
+
* never ending in `-` or `.` (apt-get reads a trailing `-` as remove). A trailing `+` (`g++`) is a
|
|
15
|
+
* real name; the build's exact-name check catches one apt-get read otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SYSTEM_PACKAGE: RegExp;
|
|
18
|
+
/** What is wrong with the list, one line each; never a name that could reach a shell unchecked. */
|
|
19
|
+
export declare function serverProblems(server: unknown): string[];
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Debian package name: lowercase letters, digits and `+ . -`, starting with a letter or digit,
|
|
3
|
+
* never ending in `-` or `.` (apt-get reads a trailing `-` as remove). A trailing `+` (`g++`) is a
|
|
4
|
+
* real name; the build's exact-name check catches one apt-get read otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export const SYSTEM_PACKAGE = /^[a-z0-9][a-z0-9+.-]{0,61}[a-z0-9+]$/;
|
|
7
|
+
/** What is wrong with the list, one line each; never a name that could reach a shell unchecked. */
|
|
8
|
+
export function serverProblems(server) {
|
|
9
|
+
if (server === undefined)
|
|
10
|
+
return [];
|
|
11
|
+
if (typeof server !== 'object' || server === null || Array.isArray(server))
|
|
12
|
+
return ['server: must be an object, e.g. { systemPackages: [] }'];
|
|
13
|
+
const list = server.systemPackages;
|
|
14
|
+
if (list === undefined)
|
|
15
|
+
return [];
|
|
16
|
+
if (!Array.isArray(list))
|
|
17
|
+
return ['server.systemPackages: must be a list of Debian package names'];
|
|
18
|
+
const problems = [];
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
for (const [index, name] of list.entries()) {
|
|
21
|
+
if (typeof name !== 'string' || !SYSTEM_PACKAGE.test(name))
|
|
22
|
+
problems.push(`server.systemPackages[${index}] (${JSON.stringify(name)}): not a Debian package name (lowercase letters, digits and + . -, 2 to 63 characters, starting with a letter or digit, not ending in - or .)`);
|
|
23
|
+
else if (seen.has(name))
|
|
24
|
+
problems.push(`server.systemPackages lists ${name} twice`);
|
|
25
|
+
else
|
|
26
|
+
seen.add(name);
|
|
27
|
+
}
|
|
28
|
+
return problems;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buffcore/config",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.48",
|
|
4
4
|
"description": "TypeScript, Biome and Vitest presets, the environment schema helper and `defineProduct` for BuffCore products.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "BuffApe",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"zod": "4.6.5",
|
|
32
|
-
"@buffcore/tokens": "0.8.
|
|
32
|
+
"@buffcore/tokens": "0.8.48"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "node ../../scripts/build-package.mjs",
|