fix(security): tighten conversation-history file perms to 0600#188
Merged
Conversation
Six of the ten provider conversation-history modules were writing the Q&A log world-readable (0644). The files routinely contain account IDs, ARNs, IPs, role names, and (in iam) entire policy fragments copied verbatim into the LLM answer — anything a non-owner on a shared host could grep. Add a tiny internal/secfile package that encapsulates three primitives — EnsurePrivateDir (0700), WritePrivate (0600), and ReadPrivate (open → fd-based chmod → ReadAll). The fd-based chmod removes the TOCTOU window that a path-based Chmod would leave open. All ten conversation.go modules (cloudflare, k8s, iam, flyio, railway, vercel, sentry, linear, notion, verda) now route Save / Load / MkdirAll through secfile. The chmod-on-load path also auto-repairs files installed by older 0644 binaries — users don't need to chmod the existing files manually. Lock the door behind us: a parse-based drift test walks the repo, finds every conversation.go, and fails the build if any of them calls os.WriteFile / os.ReadFile / os.MkdirAll directly. A tenth provider added next quarter cannot reintroduce this leak by copy-pasting the historic pattern. The test caught one mistake immediately — internal/verda/conversation.go was missed by the original audit and is now also patched. Mode bits are not meaningful on Windows; the Chmod calls inside secfile short-circuit there. Default ACLs already create owner-only on Windows. Closes #22
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
Six of the ten provider conversation-history modules were writing the Q&A log world-readable (
0644). The files routinely contain account IDs, ARNs, IPs, role names, and — foriam— entire policy fragments copied verbatim into the LLM answer.Approach
Files touched
Notes for reviewers
Test plan
Closes #22