Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
8.7 KB
Raw Blame

Key files: Security (continued)

Subsystem index · Previous entries. Read only the entries relevant to your change.

  • src/core/git-env.ts + src/core/hardened-git.ts — #7584, the operator's safe.directory in scrubbed Git environments: hardenedGitEnvironment still drops system and global config and every GIT_* variable, but carries the operator's safe.directory entries (system and global, read from / with git config --includes --show-scope and cached for 30 s, then GIT_CONFIG_*) as environment config, so a source repository owned by another user reads once the operator allows it. gitChildEnv carries the environment entries the same way (envSafeDirectories, safeDirectoryEnv). Every other key in those places stays out. gitChildEnv also drops Git's global pathspec switches (GIT_PATHSPEC_ENV_VARS: GIT_LITERAL_PATHSPECS, GIT_GLOB_PATHSPECS, GIT_NOGLOB_PATHSPECS, GIT_ICASE_PATHSPECS; extra can still set one). gbrain's writers and readers mark each path literal with literalPathspecs (:(literal)<path>; an empty path throws, since :(literal) alone matches the whole tree, #7793), never git --literal-pathspecs, which Git exports to every hook, textconv and filter helper as GIT_LITERAL_PATHSPECS=1, where a hook's glob pathspec then matches nothing; test/git-env-guard.test.ts rejects a global pathspec switch (flag or env) anywhere in src. GST-2331: NO_LAZY_FETCH_ENV (GIT_NO_LAZY_FETCH=1 and an empty GIT_ALLOW_PROTOCOL) is what a managed-sync read that runs under gitChildEnv adds beside HARDENED_GIT_ARGS, so a partial clone fetches nothing (Git before 2.45 ignores the first; the empty allowlist allows no transport on any Git): syncGit/syncGitAsync, every read in sync-blobs.ts, sync-delta.ts's text runner (a rename whose old blob the clone lacks fails the diff, diff_failed, and discovery walks the whole tree), sync-rename-identity.ts, sync-metafile-pages.ts, sync-origin-evidence.ts, sync-held-deletions.ts, unindexed-files.ts and pending-import.ts. Tests: test/hardened-git-safe-directory-7584.test.ts (ownership f... (line truncated to 2000 chars)

  • src/core/outside-content.ts — GBRA-221: neutralizeOutsideText(text), the one neutralizer for text a third party wrote before it lands in a page body (Gmail/Calendar/Contacts renders in google-render.ts, GitHub renderItemPage/renderRepoCard, chat transcripts in transcripts/render.ts, book-mirror chapter output). It escapes every gbrain<ws>:<ws><name> marker token to gbrain\:<name> (case-insensitive), [Source: to [Source\:, and backslash-prefixes each timeline sentinel, bare ## Timeline/## History heading, dated timeline row or heading, transcript message anchor and date heading, using the parsers' own predicates. Idempotent and readable; apply it per outside field (or a composed line holding one), never to a whole page that may hold gbrain's own fences or citations. Also owns escapeAnchorLines and MESSAGE_ANCHOR_RE (re-exported by transcripts/render.ts). New connectors use it.

  • src/core/function-search-path.ts — #7632 search_path hardening (#7688, #7785): PINNED_FUNCTION_NAMES (every gbrain function with a pinned search_path; scripts/check-search-path.sh fails one missing from it or a pinned path not ending in pg_temp), FUNCTION_SEARCH_PATH_HARDENING_SQL (the schema blob's last statement), and hardenFunctionSearchPaths (v277 and the end of every migration run: one transaction under the migration timeouts, a pg_proc row lock it cannot take becomes schema_lock_blocked, a concurrent pg_proc update is retried, returns the functions left or null when listing them failed; it first re-creates the purge and withdrawal guards its role owns, retrying a concurrent update, and a re-create failure other than SQLSTATE 42501 is thrown as LedgerGuardRecreateError after the hardening runs, which hardenFailureLine prints as a guards: line). Doctor checks: src/commands/doctor/checks/guard-ledger-checks.ts (guard_ledger_checks, Postgres only: names each guard missing its ledger check, from ledgerGuardsWithoutCheck in src/core/guard-ledger-checks.ts, with its owner) and src/commands/doctor/checks/function-search-path.ts (function_search_path: names any pinned function whose path does not end in pg_temp; the fix is gbrain apply-migrations --yes below v277, else the schema-qualified ALTER FUNCTION SQL (argument types only) in details.sql to run as the owner, with no runnable fix).

  • src/core/facts/private-fact-pages.ts + src/commands/auth-private-facts.ts + src/commands/auth-client-rows.ts — the per-credential private-facts axis (PrivateFactsGrant none | granted_sources in access_tokens.private_facts and oauth_clients.private_facts, migration v319 principal_private_facts, default none, never in the legacy permissions mirror; set only by the local gbrain auth rescope --token|--client --private-facts, refused for a credential with scope sources in src/core/access/attest-sources.ts). MCP dispatch puts the explicitly named sources (as for private pages, never the default floor) in privateFactSources() (src/core/search/private-visibility.ts) for remote reads only, never for mutating ops, context_pack or delta, an asserted audience, an attested actor, a scope read or an enforced member read; grantedPrivateFactSql (src/core/access/member-facts.ts) admits a private fact only in those sources and only while factPagesOpenSql holds: its holding, provenance (factProvenanceSlugSql) and entity pages are all open (not private, readable_by, folder-ruled, quarantined or a member page, factPageReasons), and it is not unpaged or in a transcript lane (unpagedFactSql). gbrain repair open-facts shares the same page predicate. The hot-memory cache (src/core/facts/meta-hook.ts) keys a granted read as <tier>+xpf=<sorted sources> and the query cache adds xpf= to its knobs hash, so a payload read under the grant never serves a credential without it. auth-private-facts.ts renders the setting, the rescope before/after lines and the warning; auth-client-rows.ts is gbrain auth clients' listing with a degrade ladder that drops private_facts, then private_pages, on older brains. Tests: test/private-facts-grant-8194.test.ts, test/e2e/private-facts-grant-postgres.test.ts, test/qm-scope-writes.test.ts, test/auth-private-pages-output.test.ts.

  • src/core/access/owner-only.ts — owner-only sources: a source of a kind in OWNER_ONLY_KINDS (imessage) or with owner_only: true in sources.config is read only by the local CLI and by a credential bound to the brain owner speaking for itself (CallerAccess.owner). Decided at read time from sources, so nothing is stored per page and no migration runs. ownerOnlyPageSql and ownerOnlyFactSql match a row in an owner-only source, a synthesized concept with a concept-provenance input there, or a row whose derivation_inputs (followed up to OWNER_ONLY_LINEAGE_DEPTH hops) reach a page, fact, take or timeline row there; each leads with one uncorrelated EXISTS over sources, so a brain with no owner-only source pays one InitPlan. src/core/search/private-visibility.ts appends them to the mandatory member-access part of the page and fact policies (no grant, hatch or lineage switch relaxes them), and src/core/persistence/page-visibility.ts refuses a remote write into an owner-only source from any credential but the owner's (page_not_found). ownerOnlySourcesPresent and sourceIsOwnerOnly fail closed. Tests: test/imessage-owner-only.test.ts (every caller class under each relaxation), test/e2e/imessage-source-postgres.test.ts.

  • src/core/imessage/ + src/core/apple/helper-client.ts — the imessage connector kind. helper-client.ts reads the GBrain Helper's /v1/imessage/threads and /v1/imessage/thread over 127.0.0.1 with a bearer token (config apple.helper.port; token from i_token_env, GBRAIN_CONNECTOR_IMESSAGE_TOKEN or ~/.gbrain/connectors/imessage.json) and maps the helper's problem codes to apple_helper_not_running, apple_helper_unauthorized, apple_full_disk_access_pending and apple_schema_mismatch, each of which stops the run. imessage-source.ts keeps a per-chat coverage window (connectors/api-source.ts) with a lookback that re-renders recent days, writes one type: imessage, visibility: private page per chat per day in the source's time zone (render.ts; the chat key is a hash, so no handle reaches a slug, the cursor or a log), always database-recorded and gated at the external-untrusted tier, and deletes a day whose messages were all unsent. source-add.ts is sources add --kind imessage (no --dir or --record). Tests: test/imessage-source.test.ts, test/helpers/imessage-helper-fixture.ts.