Skip to content

fix(gemini): ignore untrusted workspace settings - #3319

Closed
CmsChase wants to merge 2 commits into
morluto:mainfrom
CmsChase:fix/gemini-untrusted-workspace-settings
Closed

CmsChase wants to merge 2 commits into
morluto:mainfrom
CmsChase:fix/gemini-untrusted-workspace-settings

Conversation

@CmsChase

Copy link
Copy Markdown
Contributor

Summary

Fixes #3206. Ignore malformed settings in untrusted Gemini workspaces while preserving setup and doctor success when no workspace settings exist.

Problem and expected behavior

REA parsed workspace settings before checking trust, so malformed excluded settings blocked setup and marked a valid user registration invalid. Trust controls workspace-policy admission; an absent workspace settings file should not trigger an unrelated trustedFolders.json error. Present settings with unresolved or malformed trust must still be rejected.

Change and scope

Probe workspace settings metadata and omit that source only when ENOENT establishes absence. Otherwise retain the existing trust decision before reading or parsing content. Setup and registration diagnostics share this owner. Trust overrides, restricted-mode precedence, settings merge order, and the home-directory exclusion remain unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: GeminiClientSettings.readClientPolicyBlock, workspace policy admission.
  • Contribution scope fit and linked maintainer decision: routine fix within existing configuration boundaries; advance scope decision not applicable.
  • CLI and MCP/tool-catalog contract: corrected setup/doctor diagnostics; no schema or catalog changes.
  • Provider, bridge, target-format, or platform compatibility: no provider/bridge changes; Windows x64 CLI verification.
  • Evidence, artifact, provenance, or reconstruction contract: not applicable.
  • Target selection, authority, upstream behavior, and cleanup: no new execution or mutation capability. Workspace/trust files remain read-only; existing approved setup writes and test-owned cleanup are preserved.
  • Generated metadata, package, or installation impact: no metadata, dependency or package-layout change.

Expected effects of the existing setup workflow:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

The configuration effect is existing approved user registration/skill installation. This fix adds no target interaction.

Evidence and regression coverage

  • Five compiled CLI acceptance tests cover absent settings with valid/malformed trust, materializing settings with malformed trust, implicit/explicit distrust, restricted mode, and trusted malformed/excluded controls.

  • Original [Bug] Malformed settings in an untrusted Gemini workspace make setup and doctor fail #3206 regressions: 3 failed / 1 passed on unchanged production code, then 4 passed with trust-first admission.

  • Added compatibility regression: 1 failed / 4 passed before the absence correction, then all 5 passed.

  • Three-version replay made 75 real CLI calls. No-settings/malformed-trust setup and doctor changed from baseline exit 0 to exit 1 with unconditional trust evaluation, then returned to exit 0. Present-settings/malformed-trust calls retain exit 1; trusted exclusions and conflicting overrides remain rejected.

  • User, trust and workspace bytes were preserved. Unknown metadata errors are not treated as absence; that non-ENOENT branch was reviewed in source, not independently fault-injected.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Windows x64, Node 24.18.0/npm 11.16.0, locked dependencies:

  • npm run test:focused -- tests/acceptance/setup/geminiWorkspaceTrust.test.ts — 5 passed.
  • npm exec --no -- vitest run --project cli-boundary tests/boundary/cli/clientProfiles.test.ts -t Gemini — 10 passed; four unrelated OpenCode cases excluded by selection.
  • npm run check — passed: typecheck, format, lint (0 errors; one additional function-length warning at 101 lines versus 100), knip, metadata, module boundaries and architecture guards.
  • npm run verify:test-discovery — all 1253 test files discovered exactly once.

Previously observed packaging results, not rerun for the compatibility correction: npm pack --dry-run passed; the generic package verifier failed on both original and trust-first source at Windows spawn npm ENOENT; the Windows verifier required the absent source-checkout native manifest. Complete package verification remains unavailable in this environment. Previously recorded unrelated Windows symlink, launcher and OpenCode test failures remain outside this fix.

Compatibility, safety, and release

  • Breaking changes or migration: none intended; restores documented excluded-scope behavior and original no-settings compatibility.
  • Real Hopper/Ghidra, browser, or OS coverage: target-free Windows REA CLI; no native engine, installed Gemini client, POSIX host or live model API claim.
  • Package or release metadata impact: unchanged; full package/CI coverage is not claimed.
  • Security, privacy, process, or containment: no trust is granted. Metadata absence cannot authorize a content read; present or unresolved settings still require the existing trust decision.

Author readiness

Human owner: @CmsChase

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem.
  • The change stays within existing scope and authority boundaries.
  • The PR has one focused outcome and a conventional title.
  • The related issue is linked.
  • Tests cover changed behavior and meaningful failure paths.
  • Existing owning docs already describe the restored behavior; generated metadata is unchanged.
  • Representative CLI outcomes are recorded above.
  • The final diff was checked for secrets, unrelated cleanup, and unsupported claims.

Determine workspace trust before reading its settings so excluded malformed files cannot block setup or invalidate doctor registration checks. Preserve trusted policy failures and cover the public CLI with isolated configuration fixtures.
Check for known absence before evaluating workspace trust. Retain trust-first content admission for present or unresolved settings paths, and cover malformed trust files with public setup and doctor regressions.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; workspace settings remain behind the existing trust check.

Summary

This PR checks workspace trust before reading Gemini workspace settings. It skips the trust check when ENOENT establishes that settings are absent.

  • Gemini reads workspace settings only when they exist and pass trust checks.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read defaults, user, and system settings] --> B{Workspace equals home?}
  B -->|Yes| G[Check admitted policies]
  B -->|No| C[Probe workspace settings metadata]
  C -->|ENOENT| G
  C -->|Present or another error| D[Check workspace trust]
  D -->|Trust cannot be resolved| E[Return configuration error]
  D -->|Untrusted| G
  D -->|Trusted| F[Read and parse workspace settings]
  F -->|Read or parse fails| E
  F -->|Success| G
Loading

Reviews (1) · Last reviewed commit: "fix(gemini): preserve setup without work..." · Reviewed by Greptile

@morluto morluto added the bug Something isn't working label Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Treat only ENOENT as absence. Preserve unreadable metadata errors and ignore untrusted workspace content before parsing it.

Refs: #3206, #3319

Co-authored-by: haoran20100322 <[email protected]>
@CmsChase

Copy link
Copy Markdown
Contributor Author

Thanks for incorporating the Gemini workspace-trust fix in aade9bbc and preserving contributor credit. I verified main at 60c08802: all five Gemini regressions and ten existing Gemini profile tests pass, and the setup/doctor compatibility cases retain the intended outcomes.

The original CI failure was an unrelated JavaScript regression, addressed in dae1e553; the previously failing assertion also passes on the verified main revision.

Since the fix is included upstream, I'll leave the PR disposition to the maintainers. No further changes to this branch are needed from my side.

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering fix here is the right one: readClientPolicyBlock used to parse <workspace>/.gemini/settings.json before consulting trust, so a cloned repo shipping malformed (or unreadable) workspace settings could hard-fail rea setup/rea doctor with needs_human even in workspaces Gemini itself wouldn't trust. Moving the trust decision ahead of the read means untrusted workspace settings are never parsed at all.

Verified against the PR head:

  • Unlisted workspace (valid, empty trustedFolders.json) with { not json in <project>/.gemini/settings.json: setup exits 0, status ready, gemini registration aligned. The three acceptance scenarios (unlisted, GEMINI_CLI_TRUST_WORKSPACE=false, restricted mode with opt-in) all pass, including the assertions that no .rea.backup is created and the workspace file is left untouched.
  • GEMINI_CLI_TRUST_WORKSPACE=true with the same malformed file: setup exits 1, needs_human, remediation carries the Invalid JSON/JSONC diagnostic — trusted workspaces still surface real errors rather than silently ignoring the file.
  • Missing workspace settings + malformed trust file: setup exits 0. The trust file isn't consulted until something actually needs admitting.
  • Workspace settings present + malformed trust file: setup exits 1 and the remediation names the trust file ("...trust.json are malformed: ..."), not the workspace file. With both files malformed, the old order surfaced the workspace file's parse error first; pointing remediation at the trust file instead is the better attribution, since that's the one the user actually has to fix.

The "only ENOENT proves absence" comment is the right call: stat failures other than ENOENT (EACCES, EISDIR, ...) fall through to a trust decision instead of being read as absence, which fails closed. I also checked whether other clients need the same gating: the array-form configPath segments for cursor/windsurf/antigravity resolve via join(context.home, ...), so Gemini is the only client where rea reads a workspace-resident (cwd) settings source. The trust boundary scope looks right.

Two nits:

  • The cause instanceof Error && "code" in cause && cause.code === "ENOENT" predicate is now the third copy of this check in this area (ClientConfigPath.ts has a private isMissing, ClientConfigurationFiles.ts inlines the same shape). A shared isEnoent helper would keep them from drifting.
  • Each of these acceptance tests spawns ~10 CLI invocations, and two of the five exceeded vitest's 30s default testTimeout on a slow ARM host I test on (behavior verified correct via direct CLI runs). An explicit timeout argument on those cliTest calls would avoid false failures on slower machines.

@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main already has this change in aade9bb. The code is in src/application/GeminiClientSettings.ts, and Gemini setup and doctor ignore malformed settings in an explicitly untrusted workspace covers it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Superseded by the delivered change on main: aade9bbcb. Gemini workspace trust and file absence are checked before workspace settings are parsed, so an untrusted workspace cannot override the registration lookup. Closing this earlier proposal. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281.

@morluto morluto closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @CmsChase for catching the Gemini workspace-trust check occurring too late. Main checks trust before parsing the configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Malformed settings in an untrusted Gemini workspace make setup and doctor fail

4 participants