fix(security): add bws_cache.json to file_safety read guard - #34421
Merged
Conversation
The Bitwarden Secrets Manager disk cache introduced in #31968 stores plaintext secret values at <hermes_home>/cache/bws_cache.json to avoid re-fetching across back-to-back CLI invocations. The file was not added to get_read_block_error()'s credential_file_names list, leaving the agent able to read it directly via the read_file tool. Add os.path.join("cache", "bws_cache.json") to credential_file_names so both HERMES_HOME and the global root are covered, matching the existing pattern used for auth.json, .anthropic_oauth.json, etc. Other files under cache/ (images, documents, audio) are unaffected — the check is an exact-file match, not a prefix match. Verified: 11/11 exploit/regression scenarios pass; 38/38 existing file_safety tests pass.
Contributor
🔎 Lint report:
|
6 tasks
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.
Salvage of #32092 (@AhmetArif0). Clean cherry-pick — applies to current main.
What it fixes
PR #31968 added a disk-persistent Bitwarden Secrets cache at
<hermes_home>/cache/bws_cache.jsoncontaining plaintext secret values (API keys, DB passwords pulled from BSM projects). The file is chmod 0600, butagent/file_safety.get_read_block_error()was never updated to deny it — so the agent'sread_filetool could harvest decrypted secrets directly while sibling stores (.env,auth.json,.anthropic_oauth.json,mcp-tokens/) were guarded.Mechanism
Single exact-name entry appended to the
credential_file_namestuple inagent/file_safety.py. Matches the existing shape (auth/google_oauth.json,.env, etc.). Per-name loop builds(hd / name).resolve()against eachhermes_dir(HERMES_HOME + global root), exact path equality — othercache/*files (images, audio, documents) remain readable.Validation
test_file_safety.py+test_file_safety_credentials.py+test_file_safety_cross_profile.pyCloses #32092.