Secure cc-switch database and backup file permissions#221
Conversation
|
Hi @feiyehua I'm doing a refactor for CI/CD. It will execute test cases on a sandbox (usually the directory will be set to Thanks |
Seems CC_SWITCH_CONFIG_DIR=/tmp will be rejected, as we should not change the permissions of system folders (or store database in system folder, especially public ones.). |
|
hi @feiyehua I don't think executing test cases under
env HOME="$(mktemp -d)" CC_SWITCH_CONFIG_DIR="$HOME/.cc-switch" CLAUDE_CONFIG_DIR="$HOME/.claude" CODEX_HOME="$HOME/.codex" XDG_CONFIG_HOME="$HOME/.config" XDG_RUNTIME_DIR="$HOME/.runtime" XDG_STATE_HOME="$HOME/.state"Therefore, I think |
This commit only rejects |
|
Pushed a new version that only checks permissions when app starts up. This ensures permission check runs only once and will not broke TUI. |
|
Thanks for the work here. The direction makes sense, but I do not think this PR is ready to merge yet. I found two blocking issues around the permission boundary. Blockers:
I reproduced this safely in a temporary directory: So the current check rejects literal
The PR description says validation happens before database initialization so library callers and non-CLI entry points also reject dangerous directories. In the current code, I verified this with a minimal external caller: There is also a CLI-internal bypass: This validation should live at the core DB/app-state initialization boundary, or every DB-opening entry point must be proven to go through the same guard. Non-blocking but worth fixing while here: existing backup files under I would hold merge until the two blockers above are fixed and covered by focused tests. |
…r when initializing db
|
@SaladDay fixed these problems. Now:
2 tests failing, seems caused by incorrectly dropping newly created temp test home: |
Description
This PR tightens permissions around the cc-switch application database and related backup files.
Changes
07000600CC_SWITCH_CONFIG_DIRbefore database initialization, so library callers and non-CLI entry points also reject dangerous system directories like/,/etc,/usr, and/tmp.ConfigService::create_backupare written under secure backup directories and chmodded to owner-only access.Limitations
All the permissions related code are for Unix. Permissions on Windows left onchanged (probably not a big problem?)