UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

162 lines (161 loc) • 4.98 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { i as stripPluginModelCatalogCredentials } from "./plugin-model-catalog-repair-B3GKtPvY.mjs"; //#region src/state/secret-state-tables.ts /** Redaction policy surface: Git snapshots may omit these credential-bearing tables. */ const STATE_SECRET_TABLE_NAMES = [ "audit_identity_keys", "apns_registrations", "channel_ingress_events", "channel_pairing_requests", "clawhub_promotion_claims", "config_revision_keys", "device_auth_tokens", "device_bootstrap_tokens", "device_identities", "device_pairing_join_codes", "device_pairing_paired", "gateway_origin_device_tokens", "mcp_oauth_pending_authorizations", "mcp_oauth_stores", "native_hook_relay_bridges", "secret_store_entries", "web_push_approval_deliveries", "web_push_subscriptions", "worker_environment_credentials" ]; /** Secret-redacted Git backups must never carry machine-state values under these prefixes. */ const STATE_SECRET_CONFIG_STATE_KEY_PREFIXES = [ "authProfiles.", "nodeHost.", "webPush.vapidKeys" ]; /** Omit bundled plugin credentials without discarding unrelated durable plugin state. */ const STATE_SECRET_PLUGIN_SCOPES = [ { pluginId: "discord", namespace: /^activities-(?:sessions|doc-tokens)$/u }, { pluginId: "discord", namespace: /^thread-bindings$/u, jsonFields: ["webhookToken"] }, { pluginId: "google-meet", namespace: /^oauth-credential$/u }, { pluginId: "matrix", namespace: /^(?:credentials|recovery-key|idb-snapshot)$/u }, { pluginId: "mcp-events", namespace: /^subscriptions-v1$/u }, { pluginId: "mcp-relay", namespace: /^mcp-relay-authority$/u, entryKey: "identity" }, { pluginId: "msteams", namespace: /^(?:delegated-token|sso-tokens)(?:-[a-f0-9]{64})?$/u }, { pluginId: "reef", namespace: /^identity$/u }, { pluginId: "reef", namespace: /^registration$/u, entryKey: "setup-session" }, { pluginId: "sms", namespace: /^hosted-outbound-media-[a-f0-9]{16}$/u }, { pluginId: "synology-chat", namespace: /^hosted-outbound-media-[a-f0-9]{16}$/u }, { pluginId: "twitch", namespace: /^oauth-/u }, { pluginId: "x", namespace: /^x\.oauth$/u }, { pluginId: "zalo", namespace: /^hosted-outbound-media$/u }, { pluginId: "zalouser", namespace: /^credentials$/u } ]; /** Redaction policy surface for credential-bearing per-agent database tables. */ const AGENT_SECRET_TABLE_NAMES = [ "auth_profile_state", "auth_profile_store", "session_suggestions" ]; //#endregion //#region src/snapshot/git-backup-sanitizer.ts const modelCatalogScopes = ["plugin-model-catalog-v1", "plugin-model-catalog-migration-v1"]; function resolveRedactionIdentity(e, t) { return { role: t === "state" ? "global" : t === "agent" ? "agent" : e.role }; } function gitBackupRedaction(e, t, n, r) { const i = resolveRedactionIdentity(e, r); const a = i.role === "global" ? STATE_SECRET_TABLE_NAMES : AGENT_SECRET_TABLE_NAMES; return { excludedTables: n ? a.filter((e) => t.has(e)).toSorted() : [], excludedConfigStateKeyPrefixes: n && i.role === "global" && t.has("config_machine_state") ? [...STATE_SECRET_CONFIG_STATE_KEY_PREFIXES] : [] }; } /** Shared by serialized SQLite rows and the portable PostgreSQL image. */ function redactGitBackupRow(e, t, n, r) { if (e === "plugin_state_entries" || e === "plugin_blob_entries") { if (typeof t.namespace !== "string") return false; const n = t.namespace.replace(/^@retained\./u, ""); const r = STATE_SECRET_PLUGIN_SCOPES.find((e) => e.pluginId === t.plugin_id && e.namespace.test(n) && (e.entryKey === void 0 || e.entryKey === t.entry_key)); if (!r) return true; if (!r.jsonFields || e === "plugin_blob_entries") return false; t.value_json = redactPluginJsonFields(t.value_json, r.jsonFields); return t.value_json !== null; } if (e === "config_machine_state" && r.length > 0) { const e = t.state_key; if (typeof e !== "string" || r.some((t) => e.startsWith(t))) return false; } if (n.role === "agent" && e === "cache_entries" && modelCatalogScopes.some((e) => t.scope === e) && typeof t.value_json === "string") { t.value_json = stripPluginModelCatalogCredentials(t.value_json); return t.value_json !== null; } return true; } function redactPluginJsonFields(e, t) { if (typeof e !== "string") return null; try { const n = JSON.parse(e); if (!isRecord(n)) return null; for (const e of t) delete n[e]; return JSON.stringify(n); } catch { return null; } } /** Redact before materialization so credential bytes never enter the portable image. */ function createGitBackupRowTransform(e, t, n) { const r = resolveRedactionIdentity(e, t); const i = gitBackupRedaction(r, n, true); const a = new Set(i.excludedTables); return (e, t) => { if (a.has(e) || !redactGitBackupRow(e, t, r, i.excludedConfigStateKeyPrefixes)) return; return t; }; } //#endregion export { gitBackupRedaction as n, redactGitBackupRow as r, createGitBackupRowTransform as t };