Skip to content

fix(macos): protect gateway auth config writes - #75815

Closed
Fuma2013 wants to merge 6 commits into
openclaw:mainfrom
Fuma2013:codee/configwriter-auth-guard
Closed

Fuma2013 wants to merge 6 commits into
openclaw:mainfrom
Fuma2013:codee/configwriter-auth-guard

Conversation

@Fuma2013

@Fuma2013 Fuma2013 commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Protect the macOS config save path from accidentally clobbering persisted Gateway auth/mode when a Gateway config write is rejected as stale/invalid/auth-related.

This is a focused guard for the App + Dashboard coexistence failure mode: a rejected Gateway write should not silently fall back to a direct full-file write that drops gateway.auth or gateway.mode.

Changes

  • Prevent ConfigStore.save(_:) from falling back to direct local writes after stale/invalid/auth-like Gateway save failures.
  • Harden OpenClawConfigFile.saveDict(_:):
    • preserve existing gateway.auth when a generic direct write omits it
    • reject destructive gateway.mode removal and large suspicious size drops
    • write rejected payloads to .rejected.<timestamp> and audit the rejection
    • return Bool so high-risk call sites can detect rejection
  • Make user-visible direct save call sites notice rejections:
    • AppState.syncGatewayConfigNow() logs and stops on rejected writes
    • DebugSettings.saveSessionStorePath() surfaces a save error
  • Add focused Swift tests for stale Gateway rejection, auth preservation, mode-removal rejection, and AppState auth preservation across mode changes.

Scope / non-scope

Validation

Local validation run from apps/macos:

swift test --filter ConfigStoreTests --filter OpenClawConfigFileTests --filter AppStateRemoteConfigTests

Result:

Test run with 21 tests in 3 suites passed

Also run:

git diff --check

Result: no errors.

Note: the local pre-commit hook could not complete on this host because swiftlint is not installed on PATH; the focused Swift tests above and git diff --check were run manually.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call app: macos App: macos gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling extensions: openai extensions: qa-lab extensions: codex size: XL labels May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR updates macOS config persistence to block stale/auth-like Gateway fallback writes, reject destructive direct config snapshots with private rejected artifacts, surface rejected saves, add changelog coverage, and add Swift regression tests.

Reproducibility: yes. from source inspection. Current main’s local ConfigStore.save path falls back to a direct config write after saveToGateway throws, and #64973/#74890 provide matching stale config.set and gateway.mode clobber symptoms.

Next step before merge
No repair job is needed because the open PR already contains the focused implementation and I found no actionable diff bug for automation.

Security
Cleared: The latest diff no longer has a concrete security or supply-chain issue; rejected secret-bearing snapshots are created with explicit 0o600 permissions.

Review details

Best possible solution:

Land this focused guard after normal maintainer review and CI, then track the broader config.patch and structured-error-code migration separately.

Do we have a high-confidence way to reproduce the issue?

Yes, from source inspection. Current main’s local ConfigStore.save path falls back to a direct config write after saveToGateway throws, and #64973/#74890 provide matching stale config.set and gateway.mode clobber symptoms.

Is this the best way to solve the issue?

Yes for the scoped fix. The latest PR blocks the high-risk fallback path, rejects destructive direct snapshots before replacement, preserves private permissions for rejected artifacts, and leaves the broader config.patch migration as follow-up work.

What I checked:

Likely related people:

  • BunsDev: Auth-preservation behavior on current main came from merged PR fix(macos): preserve gateway auth config writes #75953, which touched the same macOS ConfigStore/OpenClawConfigFile path and is directly referenced by this PR’s history. (role: recent adjacent maintainer; confidence: high; commits: d7fa1ebfeb7a, 679c516952e7; files: apps/macos/Sources/OpenClaw/ConfigStore.swift, apps/macos/Sources/OpenClaw/OpenClawConfigFile.swift, apps/macos/Tests/OpenClawIPCTests/OpenClawConfigFileTests.swift)
  • Vincent Koc: The shallow local checkout blames the central macOS config files to commit 188c3b7, so this is only a broad current-main ownership hint rather than feature-specific provenance. (role: recent maintainer signal; confidence: low; commits: 188c3b74badc; files: apps/macos/Sources/OpenClaw/AppState.swift, apps/macos/Sources/OpenClaw/ConfigStore.swift, apps/macos/Sources/OpenClaw/OpenClawConfigFile.swift)

Remaining risk / open question:

  • I did not run the Swift tests because this was a read-only review and test execution can create artifacts; validation here is source/diff based plus the author’s reported focused test run.
  • The Gateway error classifier remains string-based because structured Gateway error codes are not surfaced to macOS yet; that is a known scope limitation, not a new diff bug.

Codex review notes: model gpt-5.5, reasoning high; reviewed against ae87f7800b2a.

@Fuma2013
Fuma2013 force-pushed the codee/configwriter-auth-guard branch from 8ed0981 to f9cf803 Compare May 1, 2026 21:05
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation channel: discord Channel integration: discord channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling extensions: openai extensions: qa-lab labels May 1, 2026
Thomas Furtmair added 3 commits May 2, 2026 20:08
…th-guard

# Conflicts:
#	apps/macos/Sources/OpenClaw/ConfigStore.swift
#	apps/macos/Sources/OpenClaw/OpenClawConfigFile.swift
@BunsDev

BunsDev commented May 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the focused fix here. I landed the same guard behavior adapted onto current main in #79326, which merged as f6a54056588b5e97b5ae8ad368a184cfeed773be.

That replacement preserves gateway auth/mode, rejects destructive fallback snapshots before local replacement, and keeps rejected payloads as private audit artifacts. Closing this PR as superseded by the merged replacement.

@BunsDev BunsDev closed this May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants