mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
fix(db): stop losing secrets and notes to the boot and migration paths
An unreadable or empty encryption-key file was treated the same as a missing one: regenerate and overwrite. That is the one case where regenerating is the worst possible move - every secret already at rest becomes undecryptable, permanently. Both now refuse to start and say which file to fix. The key-rotation script advertised re-encrypting all stored secrets while its hardcoded column lists had drifted: the AirTrail key, the per-user LLM key and the plugin OAuth tokens were never migrated, so they silently stopped decrypting after a rotation. The parity test now pins the full set against what the code actually encrypts, rather than two tables of it. The schema_version bump ran outside the migration's transaction, so a crash in between left the schema advanced and the version stale - the next boot replayed a non-idempotent step and exited, turning one crash into a boot loop. And the TICKETJSON receipt migration matched with LIKE, which SQLite treats case-insensitively, so a note somebody had typed starting 'ticketjson:' was cut up and its text dropped. Also: APP_VERSION was interpolated into migration SQL instead of bound, the capture-metadata backfill passed (photoId, userId) to a (userId, photoId) signature and its mock keyed on the wrong argument, TRUST_PROXY=0 was accepted and silently coerced to 1, demo-reset hardcoded the db path instead of honouring TREK_DB_FILE, and a demo instance with no DEMO_ADMIN_PASS set now says out loud that its admin password is the published default.
This commit is contained in:
@@ -108,7 +108,6 @@ The exemption list is enforced by the `no-restricted-syntax` ban on
|
||||
|
||||
- `numberOr` (`Number(x) || d`) treats `"0"` and negative-invalid values oddly:
|
||||
`PORT=0` silently becomes 3001, `TREK_PLUGIN_RPC_BURST=-5` stays -5.
|
||||
- `TRUST_PROXY=0` resolves to 1 hop (`parseInt || 1`).
|
||||
- APP_URL trailing-slash stripping differs per site (feeds strips one slash,
|
||||
notifications strips all).
|
||||
- `DEMO_ADMIN_EMAIL` defaults differ (demo-seed: admin@trek.app, demo-reset:
|
||||
|
||||
@@ -63,6 +63,9 @@ function resolveDefaultLanguage(raw: string | undefined): string {
|
||||
}
|
||||
|
||||
export function deriveHttp(raw: RawEnv) {
|
||||
// env.schema.ts accepts 0 as a valid hop count, so `|| 1` would quietly turn
|
||||
// "trust nothing" into "trust one hop" and let a forged X-Forwarded-For through.
|
||||
const trustProxyHops = Number.parseInt(raw.TRUST_PROXY ?? '', 10);
|
||||
return {
|
||||
allowedOriginsRaw: raw.ALLOWED_ORIGINS,
|
||||
/** globalMiddleware CORS variant: trim + drop empty entries. */
|
||||
@@ -70,7 +73,7 @@ export function deriveHttp(raw: RawEnv) {
|
||||
/** websocket variant: trim only — an empty entry stays (and can never match an Origin header). */
|
||||
wsOrigins: csvList(raw.ALLOWED_ORIGINS),
|
||||
trustProxyRaw: raw.TRUST_PROXY,
|
||||
trustProxy: Number.parseInt(raw.TRUST_PROXY ?? '') || 1,
|
||||
trustProxy: Number.isFinite(trustProxyHops) ? trustProxyHops : 1,
|
||||
forceHttps: parseBool(raw.FORCE_HTTPS) === true,
|
||||
hstsIncludeSubdomains: parseBool(raw.HSTS_INCLUDE_SUBDOMAINS) === true,
|
||||
/** COOKIE_SECURE is tri-state: an explicit falsy value disables secure cookies; anything else means auto-detect. */
|
||||
@@ -144,6 +147,8 @@ export function deriveDemo(raw: RawEnv) {
|
||||
/** Raw on purpose: demo-seed defaults to admin@trek.app, demo-reset to admin@nomad.app. */
|
||||
adminEmailRaw: raw.DEMO_ADMIN_EMAIL,
|
||||
adminPass: raw.DEMO_ADMIN_PASS || 'admin12345',
|
||||
/** False means the admin account is being created with the published default. */
|
||||
adminPassSet: !!raw.DEMO_ADMIN_PASS,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user