Refuse a TRUST_PROXY the apps can't start with; Accounts reads loopback

A server configuration with TRUST_PROXY=TRUE made an Events install build for
minutes, then fail: Express threw "invalid IP address: TRUE" at startup.

- scripts/lib/envtpl.cjs: VALUE_RULES checked before any .env is written
  (exit 4, naming the value and the fix), for every release.
- Contracts 1.6.0: agent.checkEnvValue / agent.invalidValues, the same rules
  for the Hub.
- Accounts 1.0.1: TRUST_PROXY read as Events reads it; loopback used to
  turn proxy trust off.
- Docs: CHANGELOGs, WHATS-NEW, HANDOVER, AGENT-1.0-PLAN, ROLLOUT-1.0, READMEs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 10:23:49 +02:00
co-authored by Claude Opus 5.5
parent db2e544ed6
commit fd8f6c28b0
19 changed files with 220 additions and 16 deletions
+38
View File
@@ -318,3 +318,41 @@ export function missingRequired(template: EnvTemplate, layer: "server" | "defaul
}
return [...new Set(missing)];
}
// Values the apps check at startup, so a bad one is refused when it's entered instead of
// crashing the app after an install's build. Keep in step with VALUE_RULES in
// scripts/lib/envtpl.cjs (which checks again on the server, for any release).
const PROXY_NAME = /^(loopback|linklocal|uniquelocal)$/;
const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
const isIp = (s: string) => IPV4.test(s) || (s.includes(":") && /^[0-9A-Fa-f:.]+$/.test(s));
function proxyEntry(s: string): boolean {
if (PROXY_NAME.test(s)) return true;
const [ip, bits, extra] = s.split("/");
if (extra !== undefined || ip === undefined || !isIp(ip)) return false;
return bits === undefined || /^\d{1,3}$/.test(bits) || IPV4.test(bits);
}
const ENV_VALUE_RULES: Record<string, { ok: (v: string) => boolean; hint: string }> = {
// Events hands this to Express's "trust proxy" (apps/events/backend/src/app.js).
TRUST_PROXY: {
ok: (v) => v === "true" || v === "false" || /^\d+$/.test(v) || v.split(",").every((s) => proxyEntry(s.trim())),
hint: "Use loopback behind frp, a hop count such as 1, true or false (lowercase), or proxy IP addresses/CIDRs separated by commas.",
},
};
/** Why an app can't start with this value (a sentence for the person who entered it), or null when it can. */
export function checkEnvValue(name: string, value: string): string | null {
const rule = ENV_VALUE_RULES[name];
if (!rule || rule.ok(String(value).trim())) return null;
return `${name} can't be "${value}". ${rule.hint}`;
}
/** The problems with a layer's values ({ NAME: message }), empty when there are none (the Hub's check on save and before a job). */
export function invalidValues(values: Record<string, string | undefined>): Record<string, string> {
const out: Record<string, string> = {};
for (const [name, value] of Object.entries(values)) {
if (value === undefined || value === null || String(value) === "") continue;
const problem = checkEnvValue(name, String(value));
if (problem) out[name] = problem;
}
return out;
}