fix(config): harden backup file permissions and clean orphan .bak files#31718
Merged
steipete merged 2 commits intoopenclaw:mainfrom Mar 2, 2026
Merged
fix(config): harden backup file permissions and clean orphan .bak files#31718steipete merged 2 commits intoopenclaw:mainfrom
steipete merged 2 commits intoopenclaw:mainfrom
Conversation
Contributor
Greptile SummaryAddresses security vulnerability where config backup files persist with sensitive credentials in overly permissive modes or as orphaned files.
Confidence Score: 5/5
Last reviewed commit: ff791be |
Addresses openclaw#31699 — config .bak files persist with sensitive data. Changes: - Explicitly chmod 0o600 on all .bak files after creation, instead of relying on copyFile to preserve source permissions (not guaranteed on all platforms, e.g. Windows, NFS mounts). - Clean up orphan .bak files that fall outside the managed 5-deep rotation ring (e.g. PID-stamped leftovers from interrupted writes, manual backups like .bak.before-marketing). - Add tests for permission hardening and orphan cleanup. The backup ring itself is preserved — it's a valuable recovery mechanism. This PR hardens the security surface by ensuring backup files are always owner-only and stale copies don't accumulate indefinitely.
ff791be to
285575d
Compare
Contributor
|
Landed via temp rebase onto main.
Thanks @YUJIE2002! |
dawi369
pushed a commit
to dawi369/davis
that referenced
this pull request
Mar 3, 2026
OWALabuy
pushed a commit
to kcinzgg/openclaw
that referenced
this pull request
Mar 4, 2026
zooqueen
pushed a commit
to hanzoai/bot
that referenced
this pull request
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #31699 — config
.bakfiles persist indefinitely with sensitive data (API keys, tokens, credentials).Changes
1. Explicit permission hardening on
.bakfilescopyFiledoes not guarantee permission preservation on all platforms (Windows, some NFS mounts). After creating each backup, we now explicitlychmod 0o600all files in the rotation ring — belt-and-suspenders alongside the atomic write.2. Orphan
.bakcleanupInterrupted writes, PID-stamped temp files, and manual backups can leave stale
.bak.*files that persist indefinitely with full credentials. The rotation step now removes any.bak.*file whose suffix doesn't match the valid ring indices (.bak.1through.bak.4).Real-world example from my own server:
3. Tests
hardenBackupPermissions: verifies all backups get0o600even when created with permissive modecleanOrphanBackups: verifies orphans are removed while valid ring files and the main config are preservedWhat's preserved
The 5-deep backup ring is unchanged — it's a valuable recovery mechanism. This PR only hardens the security surface.
Verification