@void/platform 1.11.0 → 1.12.1
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/ai-logging.d.mts +8 -12
- package/dist/ai-logging.mjs +7 -10
- package/dist/browser-page.mjs +2 -2
- package/dist/email-protocol.mjs +16 -14
- package/dist/index.d.mts +30 -4
- package/dist/index.mjs +120 -69
- package/dist/installer.d.mts +2 -0
- package/dist/installer.mjs +13 -13
- package/dist/plans.mjs +22 -10
- package/dist/runtime/api/assets/admin/client.js +51 -45
- package/dist/runtime/api/assets/admin/style.css +1 -1
- package/dist/runtime/api/index.js +3748 -329
- package/dist/runtime/dispatch/index.js +8 -8
- package/dist/runtime/drizzle/0065_security_audits.sql +313 -0
- package/dist/runtime/drizzle/compatibility.json +28 -0
- package/dist/runtime/drizzle/meta/_journal.json +7 -0
- package/dist/runtime/emailGateway/index.js +5 -5
- package/dist/runtime/manifest.json +51 -16
- package/dist/runtime/proxy/index.js +5 -5
- package/dist/security-local-check.d.mts +28 -0
- package/dist/security-local-check.mjs +140 -0
- package/dist/security-lockfile.d.mts +34 -0
- package/dist/security-lockfile.mjs +181 -0
- package/dist/security-models.d.mts +88 -0
- package/dist/security-models.mjs +186 -0
- package/dist/security-policy.d.mts +245 -0
- package/dist/security-policy.mjs +491 -0
- package/package.json +23 -6
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { DEFAULT_SECURITY_MODEL, SECURITY_MODEL_IDS, isSecurityModelId, isSecurityModelPriced, isThirdPartySecurityModel } from "./security-models.mjs";
|
|
2
|
+
import { n as isPrintableText, r as isRecord, s as record } from "./validate-CTKcW3Vp.mjs";
|
|
3
|
+
// src/security-policy.ts
|
|
4
|
+
/**
|
|
5
|
+
* The installation security audit policy (spec §5.3), shared by the platform API and the
|
|
6
|
+
* CLI. The API checks a new policy with the strict `parseSecurityPolicy` and reads the
|
|
7
|
+
* stored row with the lenient `readSecurityPolicy`.
|
|
8
|
+
*/
|
|
9
|
+
/** `platform_settings` key that holds the policy. */
|
|
10
|
+
const SECURITY_POLICY_SETTINGS_KEY = "securityAudits.policy";
|
|
11
|
+
const SECURITY_MODES = [
|
|
12
|
+
"disabled",
|
|
13
|
+
"public",
|
|
14
|
+
"all"
|
|
15
|
+
];
|
|
16
|
+
/** Names shown in the admin panel and CLI output. */
|
|
17
|
+
const SECURITY_MODE_LABELS = {
|
|
18
|
+
disabled: "Off",
|
|
19
|
+
public: "Public projects only",
|
|
20
|
+
all: "All projects"
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Allowed whole-number range and default of every limit. Concurrency and timeout come
|
|
24
|
+
* from the spec. The token and call ranges are ours: at their top, the most expensive
|
|
25
|
+
* priced model reserves $12 per scan.
|
|
26
|
+
*/
|
|
27
|
+
const SECURITY_LIMIT_RANGES = {
|
|
28
|
+
/** Running scans per installation. */
|
|
29
|
+
concurrency: {
|
|
30
|
+
min: 1,
|
|
31
|
+
max: 10,
|
|
32
|
+
default: 2
|
|
33
|
+
},
|
|
34
|
+
/** Wall clock per scan, the only timeout setting. */
|
|
35
|
+
timeoutMinutes: {
|
|
36
|
+
min: 5,
|
|
37
|
+
max: 60,
|
|
38
|
+
default: 20
|
|
39
|
+
},
|
|
40
|
+
maxInputTokens: {
|
|
41
|
+
min: 5e4,
|
|
42
|
+
max: 2e6,
|
|
43
|
+
default: 12e5
|
|
44
|
+
},
|
|
45
|
+
maxOutputTokens: {
|
|
46
|
+
min: 5e3,
|
|
47
|
+
max: 2e5,
|
|
48
|
+
default: 12e4
|
|
49
|
+
},
|
|
50
|
+
modelCallsPerScan: {
|
|
51
|
+
min: 10,
|
|
52
|
+
max: 200,
|
|
53
|
+
default: 80
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const SECURITY_LIMIT_KEYS = [
|
|
57
|
+
"concurrency",
|
|
58
|
+
"timeoutMinutes",
|
|
59
|
+
"maxInputTokens",
|
|
60
|
+
"maxOutputTokens",
|
|
61
|
+
"modelCallsPerScan"
|
|
62
|
+
];
|
|
63
|
+
/** Highest USD amount a cap may be set to. */
|
|
64
|
+
const SECURITY_MAX_MONTHLY_USD = 1e6;
|
|
65
|
+
const SECURITY_SWEEP_DAYS_RANGE = {
|
|
66
|
+
min: 7,
|
|
67
|
+
max: 90,
|
|
68
|
+
default: 30
|
|
69
|
+
};
|
|
70
|
+
/** A fresh probe is needed to leave `disabled` or to turn the public gate on. */
|
|
71
|
+
const SECURITY_ENTITLEMENT_MAX_AGE_MS = 864e5;
|
|
72
|
+
/**
|
|
73
|
+
* Error codes (the `error` field) the API returns for security audits, with their HTTP
|
|
74
|
+
* status. The CLI matches on these strings.
|
|
75
|
+
*/
|
|
76
|
+
const SECURITY_ERRORS = {
|
|
77
|
+
modelNotAllowed: {
|
|
78
|
+
code: "security model not allowed",
|
|
79
|
+
status: 422
|
|
80
|
+
},
|
|
81
|
+
providerNoticeNotAccepted: {
|
|
82
|
+
code: "provider notice not accepted",
|
|
83
|
+
status: 422
|
|
84
|
+
},
|
|
85
|
+
entitlementMissing: {
|
|
86
|
+
code: "security entitlement missing",
|
|
87
|
+
status: 409
|
|
88
|
+
},
|
|
89
|
+
findingChanged: {
|
|
90
|
+
code: "finding changed",
|
|
91
|
+
status: 409
|
|
92
|
+
},
|
|
93
|
+
budgetAbovePlatformLimit: {
|
|
94
|
+
code: "security budget above platform limit",
|
|
95
|
+
status: 422
|
|
96
|
+
},
|
|
97
|
+
publicGateNeedsZeroTrust: {
|
|
98
|
+
code: "security public gate needs zero trust",
|
|
99
|
+
status: 409
|
|
100
|
+
},
|
|
101
|
+
publicGateNeedsPolicy: {
|
|
102
|
+
code: "security public gate needs policy",
|
|
103
|
+
status: 409
|
|
104
|
+
},
|
|
105
|
+
publicGateOn: {
|
|
106
|
+
code: "security public gate on",
|
|
107
|
+
status: 409
|
|
108
|
+
},
|
|
109
|
+
noPublicRequest: {
|
|
110
|
+
code: "no public request",
|
|
111
|
+
status: 409
|
|
112
|
+
},
|
|
113
|
+
publicRequestClosed: {
|
|
114
|
+
code: "public request closed",
|
|
115
|
+
status: 409
|
|
116
|
+
},
|
|
117
|
+
publicRequestHasUrgentFindings: {
|
|
118
|
+
code: "security public request has urgent findings",
|
|
119
|
+
status: 409
|
|
120
|
+
},
|
|
121
|
+
scanBypassReasonRequired: {
|
|
122
|
+
code: "scan bypass reason required",
|
|
123
|
+
status: 422
|
|
124
|
+
},
|
|
125
|
+
policyUnreadable: {
|
|
126
|
+
code: "security policy unreadable",
|
|
127
|
+
status: 503
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function defaultSecurityBudgets() {
|
|
131
|
+
return {
|
|
132
|
+
platformCapOn: false,
|
|
133
|
+
platformMonthlyUsd: 1e3,
|
|
134
|
+
projectCapsOn: false,
|
|
135
|
+
projectDefaultMonthlyUsd: 100
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function wholeInRange(value, range, label) {
|
|
139
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < range.min || value > range.max) throw new Error(`${label} must be a whole number from ${range.min} to ${range.max}.`);
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
/** `sweeps.everyDays`: a whole number of days in `SECURITY_SWEEP_DAYS_RANGE`. */
|
|
143
|
+
function parseSecuritySweepDays(value) {
|
|
144
|
+
return wholeInRange(value, SECURITY_SWEEP_DAYS_RANGE, "sweeps.everyDays");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The sweep setting; a row saved before sweeps existed reads as Off. The lenient reader
|
|
148
|
+
* clamps the days and reads anything else as Off, so bad data never starts paid scans.
|
|
149
|
+
*/
|
|
150
|
+
function parseSweeps(value, strict) {
|
|
151
|
+
const off = {
|
|
152
|
+
on: false,
|
|
153
|
+
everyDays: SECURITY_SWEEP_DAYS_RANGE.default
|
|
154
|
+
};
|
|
155
|
+
if (value === void 0) return off;
|
|
156
|
+
if (strict) {
|
|
157
|
+
const input = record(value, "sweeps");
|
|
158
|
+
return {
|
|
159
|
+
on: parseBoolean(input.on, "sweeps.on"),
|
|
160
|
+
everyDays: parseSecuritySweepDays(input.everyDays)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const input = isRecord(value) ? value : {};
|
|
164
|
+
const days = input.everyDays;
|
|
165
|
+
if (typeof input.on !== "boolean" || typeof days !== "number" || !Number.isSafeInteger(days)) return off;
|
|
166
|
+
const range = SECURITY_SWEEP_DAYS_RANGE;
|
|
167
|
+
return {
|
|
168
|
+
on: input.on,
|
|
169
|
+
everyDays: Math.min(range.max, Math.max(range.min, days))
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* An on/off setting added after the first release; a missing one reads as Off. The
|
|
174
|
+
* lenient reader reads a bad value as Off, so bad data never starts paid scans or mail.
|
|
175
|
+
*/
|
|
176
|
+
function parseAddedFlag(value, label, strict) {
|
|
177
|
+
if (value === void 0 || !strict && typeof value !== "boolean") return false;
|
|
178
|
+
return parseBoolean(value, label);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The security webhook URL (spec §20): `https` only, no user name or password (the body
|
|
182
|
+
* is signed instead), at most 2048 characters. Returns the normalized URL.
|
|
183
|
+
*/
|
|
184
|
+
function parseSecurityWebhookUrl(value) {
|
|
185
|
+
const max = 2048;
|
|
186
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max) throw new Error(`The webhook URL must be an https URL of at most ${max} characters.`);
|
|
187
|
+
let url;
|
|
188
|
+
try {
|
|
189
|
+
url = new URL(value);
|
|
190
|
+
} catch {
|
|
191
|
+
throw new Error("The webhook URL must be an https URL.");
|
|
192
|
+
}
|
|
193
|
+
if (url.protocol !== "https:" || url.hostname === "") throw new Error("The webhook URL must be an https URL.");
|
|
194
|
+
if (url.username !== "" || url.password !== "") throw new Error("The webhook URL must not hold a user name or password.");
|
|
195
|
+
if (url.hash !== "") throw new Error("The webhook URL must not have a #fragment.");
|
|
196
|
+
return url.href;
|
|
197
|
+
}
|
|
198
|
+
/** The policy of an installation that never saved one: Off, nothing accepted or probed. */
|
|
199
|
+
function defaultSecurityPolicy() {
|
|
200
|
+
return {
|
|
201
|
+
mode: "disabled",
|
|
202
|
+
defaultModel: DEFAULT_SECURITY_MODEL,
|
|
203
|
+
blockedModels: [],
|
|
204
|
+
thirdPartyNotice: null,
|
|
205
|
+
limits: limitsFrom({}, false),
|
|
206
|
+
budgets: defaultSecurityBudgets(),
|
|
207
|
+
entitlement: null,
|
|
208
|
+
publicGate: false,
|
|
209
|
+
sweeps: parseSweeps(void 0, true),
|
|
210
|
+
fallbackToCf: false,
|
|
211
|
+
digest: false,
|
|
212
|
+
revision: 0
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function isSecurityMode(value) {
|
|
216
|
+
return SECURITY_MODES.some((mode) => mode === value);
|
|
217
|
+
}
|
|
218
|
+
function parseModelId(value, label) {
|
|
219
|
+
if (!isSecurityModelId(value)) throw new Error(`${label} must be one of: ${SECURITY_MODEL_IDS.join(", ")}.`);
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Every limit, each in range. The lenient reader clamps a limit into today's range and
|
|
224
|
+
* gives a limit the row lacks its default.
|
|
225
|
+
*/
|
|
226
|
+
function limitsFrom(value, strict) {
|
|
227
|
+
const input = record(value, "Security limits");
|
|
228
|
+
const read = (key) => {
|
|
229
|
+
const range = SECURITY_LIMIT_RANGES[key];
|
|
230
|
+
const limit = input[key];
|
|
231
|
+
if (strict) return wholeInRange(limit, range, key);
|
|
232
|
+
if (limit === void 0) return range.default;
|
|
233
|
+
if (typeof limit !== "number" || !Number.isSafeInteger(limit)) throw new Error(`${key} must be a whole number.`);
|
|
234
|
+
return Math.min(range.max, Math.max(range.min, limit));
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
concurrency: read("concurrency"),
|
|
238
|
+
timeoutMinutes: read("timeoutMinutes"),
|
|
239
|
+
maxInputTokens: read("maxInputTokens"),
|
|
240
|
+
maxOutputTokens: read("maxOutputTokens"),
|
|
241
|
+
modelCallsPerScan: read("modelCallsPerScan")
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** A change to some limits. Unknown keys are refused so a typo is not silently ignored. */
|
|
245
|
+
function parseSecurityLimitsPatch(value) {
|
|
246
|
+
const input = record(value, "Security limits");
|
|
247
|
+
const patch = {};
|
|
248
|
+
for (const [key, limit] of Object.entries(input)) {
|
|
249
|
+
const known = SECURITY_LIMIT_KEYS.find((candidate) => candidate === key);
|
|
250
|
+
if (!known) throw new Error(`Unknown security limit: ${key}.`);
|
|
251
|
+
patch[known] = wholeInRange(limit, SECURITY_LIMIT_RANGES[known], known);
|
|
252
|
+
}
|
|
253
|
+
return patch;
|
|
254
|
+
}
|
|
255
|
+
/** A USD amount for a monthly cap: 0 to `SECURITY_MAX_MONTHLY_USD`, whole cents. */
|
|
256
|
+
function parseSecurityUsd(value, label) {
|
|
257
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1e6 || Math.round(value * 100) / 100 !== value) throw new Error(`${label} must be a USD amount from 0 to ${SECURITY_MAX_MONTHLY_USD} with at most two decimals.`);
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
function parseBoolean(value, label) {
|
|
261
|
+
if (typeof value !== "boolean") throw new Error(`${label} must be true or false.`);
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
264
|
+
function parseBudgets(value) {
|
|
265
|
+
const input = record(value, "Security budgets");
|
|
266
|
+
return {
|
|
267
|
+
platformCapOn: parseBoolean(input.platformCapOn, "platformCapOn"),
|
|
268
|
+
platformMonthlyUsd: parseSecurityUsd(input.platformMonthlyUsd, "platformMonthlyUsd"),
|
|
269
|
+
projectCapsOn: parseBoolean(input.projectCapsOn, "projectCapsOn"),
|
|
270
|
+
projectDefaultMonthlyUsd: parseSecurityUsd(input.projectDefaultMonthlyUsd, "projectDefaultMonthlyUsd")
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/** A timestamp written by `Date.prototype.toISOString`. */
|
|
274
|
+
function parseIsoTimestamp(value, label) {
|
|
275
|
+
const time = typeof value === "string" ? Date.parse(value) : NaN;
|
|
276
|
+
if (!Number.isFinite(time) || new Date(time).toISOString() !== value) throw new Error(`${label} must be an ISO 8601 timestamp.`);
|
|
277
|
+
return String(value);
|
|
278
|
+
}
|
|
279
|
+
function parseNotice(value) {
|
|
280
|
+
if (value === null) return null;
|
|
281
|
+
const input = record(value, "thirdPartyNotice");
|
|
282
|
+
if (!isPrintableText(input.acceptedByUserId, 200)) throw new Error("thirdPartyNotice.acceptedByUserId must be a user ID.");
|
|
283
|
+
const acceptedAt = parseIsoTimestamp(input.acceptedAt, "thirdPartyNotice.acceptedAt");
|
|
284
|
+
const version = input.version;
|
|
285
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1) throw new Error("thirdPartyNotice.version must be a positive whole number.");
|
|
286
|
+
return {
|
|
287
|
+
acceptedByUserId: input.acceptedByUserId,
|
|
288
|
+
acceptedAt,
|
|
289
|
+
version
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function parseEntitlement(value) {
|
|
293
|
+
if (value === null) return null;
|
|
294
|
+
const input = record(value, "entitlement");
|
|
295
|
+
if (!Array.isArray(input.missing) || input.missing.length > 20 || !input.missing.every((name) => isPrintableText(name, 64))) throw new Error("entitlement.missing must list at most 20 check names.");
|
|
296
|
+
const ok = parseBoolean(input.ok, "entitlement.ok");
|
|
297
|
+
if (ok !== (input.missing.length === 0)) throw new Error("entitlement.ok must be true exactly when no check is missing.");
|
|
298
|
+
const hosts = record(input.hosts, "entitlement.hosts");
|
|
299
|
+
return {
|
|
300
|
+
checkedAt: parseIsoTimestamp(input.checkedAt, "entitlement.checkedAt"),
|
|
301
|
+
ok,
|
|
302
|
+
missing: input.missing.slice(),
|
|
303
|
+
hosts: {
|
|
304
|
+
openai: parseBoolean(hosts.openai, "entitlement.hosts.openai"),
|
|
305
|
+
anthropic: parseBoolean(hosts.anthropic, "entitlement.hosts.anthropic")
|
|
306
|
+
},
|
|
307
|
+
...!ok && input.failingSince !== void 0 ? { failingSince: parseIsoTimestamp(input.failingSince, "entitlement.failingSince") } : {}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** Each id once. The lenient reader drops ids a later release added. */
|
|
311
|
+
function blockedModelsFrom(value, strict) {
|
|
312
|
+
if (!Array.isArray(value)) throw new Error("blockedModels must be a list of model IDs.");
|
|
313
|
+
const blocked = [];
|
|
314
|
+
for (const entry of value) if (strict) {
|
|
315
|
+
const id = parseModelId(entry, "Each blocked model");
|
|
316
|
+
if (blocked.includes(id)) throw new Error(`Blocked model listed twice: ${id}.`);
|
|
317
|
+
blocked.push(id);
|
|
318
|
+
} else if (isSecurityModelId(entry) && !blocked.includes(entry)) blocked.push(entry);
|
|
319
|
+
return blocked;
|
|
320
|
+
}
|
|
321
|
+
function canBeDefaultModel(id, blocked, notice) {
|
|
322
|
+
return !blocked.includes(id) && isSecurityModelPriced(id) && (notice !== null || !isThirdPartySecurityModel(id));
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The stored default if this release can still run it, else the first non-blocked,
|
|
326
|
+
* priced model (spec §8.2, edge case 23). `SECURITY_MODEL_IDS` lists `@cf` models first,
|
|
327
|
+
* so a third-party model is only reached when every `@cf` model is blocked.
|
|
328
|
+
*/
|
|
329
|
+
function readDefaultModel(value, blocked, notice) {
|
|
330
|
+
if (isSecurityModelId(value) && canBeDefaultModel(value, blocked, notice)) return value;
|
|
331
|
+
const fallback = SECURITY_MODEL_IDS.find((id) => canBeDefaultModel(id, blocked, notice));
|
|
332
|
+
if (!fallback) throw new Error("No model can run: every priced model is blocked.");
|
|
333
|
+
return fallback;
|
|
334
|
+
}
|
|
335
|
+
/** The rules that tie policy fields together; the API checks runtime conditions itself. */
|
|
336
|
+
function assertConsistent(policy) {
|
|
337
|
+
if (policy.blockedModels.includes(policy.defaultModel)) throw new Error(`The default model ${policy.defaultModel} is blocked.`);
|
|
338
|
+
if (!isSecurityModelPriced(policy.defaultModel)) throw new Error(`The default model ${policy.defaultModel} has no price yet.`);
|
|
339
|
+
if (isThirdPartySecurityModel(policy.defaultModel) && policy.thirdPartyNotice === null) throw new Error(`The default model ${policy.defaultModel} is third-party and needs the accepted provider notice.`);
|
|
340
|
+
if (policy.publicGate && policy.mode === "disabled") throw new Error("Scan before public needs the policy to be public or all.");
|
|
341
|
+
return policy;
|
|
342
|
+
}
|
|
343
|
+
function policyFrom(value, strict) {
|
|
344
|
+
const input = record(value, "Security policy");
|
|
345
|
+
const revision = input.revision;
|
|
346
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) throw new Error("Security policy revision must be a nonnegative whole number.");
|
|
347
|
+
if (!isSecurityMode(input.mode)) throw new Error("Security audit mode must be disabled, public or all.");
|
|
348
|
+
const asked = strict ? parseModelId(input.defaultModel, "defaultModel") : null;
|
|
349
|
+
const blockedModels = blockedModelsFrom(input.blockedModels, strict);
|
|
350
|
+
const thirdPartyNotice = parseNotice(input.thirdPartyNotice);
|
|
351
|
+
return assertConsistent({
|
|
352
|
+
mode: input.mode,
|
|
353
|
+
defaultModel: asked ?? readDefaultModel(input.defaultModel, blockedModels, thirdPartyNotice),
|
|
354
|
+
blockedModels,
|
|
355
|
+
thirdPartyNotice,
|
|
356
|
+
limits: limitsFrom(input.limits, strict),
|
|
357
|
+
budgets: parseBudgets(input.budgets),
|
|
358
|
+
entitlement: parseEntitlement(input.entitlement),
|
|
359
|
+
publicGate: parseBoolean(input.publicGate, "publicGate"),
|
|
360
|
+
sweeps: parseSweeps(input.sweeps, strict),
|
|
361
|
+
fallbackToCf: parseAddedFlag(input.fallbackToCf, "fallbackToCf", strict),
|
|
362
|
+
digest: parseAddedFlag(input.digest, "digest", strict),
|
|
363
|
+
revision
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Strict check of a policy about to be written: every known field present and valid,
|
|
368
|
+
* and the fields agree. Unknown fields are ignored.
|
|
369
|
+
*/
|
|
370
|
+
function parseSecurityPolicy(value) {
|
|
371
|
+
return policyFrom(value, true);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Reader of the stored policy row. Data another release could have written still reads:
|
|
375
|
+
* unknown blocked models are dropped, a default this release cannot run falls back,
|
|
376
|
+
* limits are clamped. Anything else the strict parser refuses throws here too.
|
|
377
|
+
*/
|
|
378
|
+
function readSecurityPolicy(value) {
|
|
379
|
+
return policyFrom(value, false);
|
|
380
|
+
}
|
|
381
|
+
/** The last probe passed checks 1–4 less than 24 hours before `now` (ms). */
|
|
382
|
+
function isSecurityEntitlementFresh(entitlement, now) {
|
|
383
|
+
if (!entitlement || !entitlement.ok) return false;
|
|
384
|
+
const age = now - Date.parse(entitlement.checkedAt);
|
|
385
|
+
return age >= 0 && age < 864e5;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* `platform_settings` key of the per-plan monthly scan caps (M27). Kept out of
|
|
389
|
+
* `plans:catalog`: an older API rebuilds the catalog from known keys on every write, so
|
|
390
|
+
* a cap stored there would be lost after a rollback (same as `plans:ai-logging`).
|
|
391
|
+
*/
|
|
392
|
+
const PLAN_SECURITY_CAPS_SETTING = "plans:security-caps";
|
|
393
|
+
function isPlanSecurityCapCents(value) {
|
|
394
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 1e8;
|
|
395
|
+
}
|
|
396
|
+
/** One stored entry as a plan cap; `undefined` when it is neither whole cents nor `null`. */
|
|
397
|
+
function readStoredPlanSecurityCap(entry) {
|
|
398
|
+
if (entry === null) return "none";
|
|
399
|
+
return isPlanSecurityCapCents(entry) ? entry : void 0;
|
|
400
|
+
}
|
|
401
|
+
/** A plan ID: a lowercase letter, then lowercase letters, digits or hyphens, at most 64. */
|
|
402
|
+
function isPlanKey(key) {
|
|
403
|
+
if (key.length === 0 || key.length > 64 || key[0] < "a" || key[0] > "z") return false;
|
|
404
|
+
return Array.from(key).every((char) => char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-");
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Reads a stored caps row. Lenient: an entry that is not a plan ID with whole cents or
|
|
408
|
+
* `null` is left out (that plan inherits) and counted in `dropped`, so one bad entry
|
|
409
|
+
* never stops plan edits or scans. A row that is not an object reads as empty.
|
|
410
|
+
*/
|
|
411
|
+
function readPlanSecurityCaps(value) {
|
|
412
|
+
if (value === null || value === void 0) return {
|
|
413
|
+
caps: {},
|
|
414
|
+
dropped: 0
|
|
415
|
+
};
|
|
416
|
+
if (!isRecord(value)) return {
|
|
417
|
+
caps: {},
|
|
418
|
+
dropped: 1
|
|
419
|
+
};
|
|
420
|
+
const caps = {};
|
|
421
|
+
let dropped = 0;
|
|
422
|
+
for (const [key, entry] of Object.entries(value)) if (isPlanKey(key) && (entry === null || isPlanSecurityCapCents(entry))) caps[key] = entry;
|
|
423
|
+
else dropped++;
|
|
424
|
+
return {
|
|
425
|
+
caps,
|
|
426
|
+
dropped
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/** The cap of one plan in a caps row. */
|
|
430
|
+
function planSecurityCap(caps, planId) {
|
|
431
|
+
if (!Object.hasOwn(caps, planId)) return "inherit";
|
|
432
|
+
return caps[planId] ?? "none";
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Reads a plan change's `securityCap` field: a USD amount (whole cents), `none` or
|
|
436
|
+
* `inherit`. `undefined` keeps the plan's current cap. An amount comes back in cents.
|
|
437
|
+
*/
|
|
438
|
+
function parsePlanSecurityCapInput(value) {
|
|
439
|
+
if (value === void 0 || value === "none" || value === "inherit") return value;
|
|
440
|
+
if (typeof value === "number") return Math.round(parseSecurityUsd(value, "securityCap") * 100);
|
|
441
|
+
throw new Error(`securityCap must be a USD amount from 0 to ${SECURITY_MAX_MONTHLY_USD}, "none" or "inherit".`);
|
|
442
|
+
}
|
|
443
|
+
/** A caps row with one plan's cap changed; `inherit` leaves the plan out. */
|
|
444
|
+
function withPlanSecurityCap(caps, planId, cap) {
|
|
445
|
+
const next = {};
|
|
446
|
+
for (const [key, entry] of Object.entries(caps)) if (key !== planId) next[key] = entry;
|
|
447
|
+
if (cap !== "inherit") next[planId] = cap === "none" ? null : cap;
|
|
448
|
+
return next;
|
|
449
|
+
}
|
|
450
|
+
/** `$50.00 / month`, `no cap` or `policy default`, for the CLI and the admin panel. */
|
|
451
|
+
function formatPlanSecurityCap(cap) {
|
|
452
|
+
if (cap === "inherit") return "policy default";
|
|
453
|
+
if (cap === "none") return "no cap";
|
|
454
|
+
const cents = String(cap % 100).padStart(2, "0");
|
|
455
|
+
return `$${Math.floor(cap / 100).toLocaleString("en-US")}.${cents} / month`;
|
|
456
|
+
}
|
|
457
|
+
/** `text` as a whole number written with 1 to `maxDigits` ASCII digits, else `null`. */
|
|
458
|
+
function parseSecurityDigits(text, maxDigits) {
|
|
459
|
+
if (text.length === 0 || text.length > maxDigits) return null;
|
|
460
|
+
return Array.from(text).every((char) => char >= "0" && char <= "9") ? Number(text) : null;
|
|
461
|
+
}
|
|
462
|
+
/** A finding label as the page prints it (`F-12`): its number, else `null`. */
|
|
463
|
+
function parseSecurityFindingLabel(text) {
|
|
464
|
+
return text.startsWith("F-") ? parseSecurityDigits(text.slice(2), 9) : null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* A finding trace of `{ file, line, note }` steps as `file:line note` lines, as the CLI
|
|
468
|
+
* and the project page print it; `null` for another shape. Callers clean the text.
|
|
469
|
+
*/
|
|
470
|
+
function securityTraceLines(value) {
|
|
471
|
+
if (!Array.isArray(value) || value.length === 0) return null;
|
|
472
|
+
const lines = [];
|
|
473
|
+
for (const step of value) {
|
|
474
|
+
if (!isRecord(step) || typeof step.file !== "string" || typeof step.note !== "string") return null;
|
|
475
|
+
lines.push(`${step.file}${typeof step.line === "number" ? `:${step.line}` : ""} ${step.note}`);
|
|
476
|
+
}
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* A dollar amount typed in a budget form, such as `50`, `12.50` or `$12.50`. Empty text
|
|
481
|
+
* is `null` (no cap of its own); text that is not an amount is `undefined`.
|
|
482
|
+
*/
|
|
483
|
+
function parseSecurityUsdText(text) {
|
|
484
|
+
let amount = text.trim();
|
|
485
|
+
if (amount === "") return null;
|
|
486
|
+
if (amount.startsWith("$")) amount = amount.slice(1);
|
|
487
|
+
const [whole = "", fraction, ...extra] = amount.split(".");
|
|
488
|
+
if (extra.length > 0 || parseSecurityDigits(whole, 7) === null || fraction !== void 0 && parseSecurityDigits(fraction, 2) === null) return;
|
|
489
|
+
return Number(amount);
|
|
490
|
+
}
|
|
491
|
+
export { PLAN_SECURITY_CAPS_SETTING, SECURITY_ENTITLEMENT_MAX_AGE_MS, SECURITY_ERRORS, SECURITY_LIMIT_KEYS, SECURITY_LIMIT_RANGES, SECURITY_MAX_MONTHLY_USD, SECURITY_MODES, SECURITY_MODE_LABELS, SECURITY_POLICY_SETTINGS_KEY, defaultSecurityBudgets, defaultSecurityPolicy, formatPlanSecurityCap, isSecurityEntitlementFresh, isSecurityMode, parsePlanSecurityCapInput, parseSecurityDigits, parseSecurityFindingLabel, parseSecurityLimitsPatch, parseSecurityPolicy, parseSecuritySweepDays, parseSecurityUsd, parseSecurityUsdText, parseSecurityWebhookUrl, planSecurityCap, readPlanSecurityCaps, readSecurityPolicy, readStoredPlanSecurityCap, securityTraceLines, withPlanSecurityCap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/platform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Packaged runtime and installation contracts for self-hosted Void platforms.",
|
|
5
5
|
"homepage": "https://void.cloud",
|
|
6
6
|
"bugs": {
|
|
@@ -40,25 +40,42 @@
|
|
|
40
40
|
"./browser-page": {
|
|
41
41
|
"types": "./dist/browser-page.d.mts",
|
|
42
42
|
"import": "./dist/browser-page.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./security-models": {
|
|
45
|
+
"types": "./dist/security-models.d.mts",
|
|
46
|
+
"import": "./dist/security-models.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./security-policy": {
|
|
49
|
+
"types": "./dist/security-policy.d.mts",
|
|
50
|
+
"import": "./dist/security-policy.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./security-local-check": {
|
|
53
|
+
"types": "./dist/security-local-check.d.mts",
|
|
54
|
+
"import": "./dist/security-local-check.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./security-lockfile": {
|
|
57
|
+
"types": "./dist/security-lockfile.d.mts",
|
|
58
|
+
"import": "./dist/security-lockfile.mjs"
|
|
43
59
|
}
|
|
44
60
|
},
|
|
45
61
|
"publishConfig": {
|
|
46
62
|
"access": "public"
|
|
47
63
|
},
|
|
48
64
|
"dependencies": {
|
|
49
|
-
"@void/deploy-core": "1.
|
|
65
|
+
"@void/deploy-core": "1.12.1",
|
|
50
66
|
"pathslash": "^0.1.0"
|
|
51
67
|
},
|
|
52
68
|
"devDependencies": {
|
|
53
69
|
"@types/node": "^26.6.6",
|
|
54
|
-
"@void/isr": "1.
|
|
70
|
+
"@void/isr": "1.12.1",
|
|
71
|
+
"tsrs": "7.1.0-beta.tsrs4",
|
|
55
72
|
"typescript": "7.0.2",
|
|
56
|
-
"vite-plus": "1.
|
|
57
|
-
"wrangler": "^4.
|
|
73
|
+
"vite-plus": "1.8.0",
|
|
74
|
+
"wrangler": "^4.168.0"
|
|
58
75
|
},
|
|
59
76
|
"scripts": {
|
|
60
77
|
"build": "vp pack && vp run build:runtime && vp run build:stamp",
|
|
61
78
|
"dev": "vp pack --watch",
|
|
62
|
-
"typecheck": "
|
|
79
|
+
"typecheck": "tsrs --noEmit"
|
|
63
80
|
}
|
|
64
81
|
}
|