File Viewer: a workspace .env opens in the preview but can never be edited
When I open a .env from the Files panel, the preview shows the whole file, but the pencil never appears. Every other config file in the workspace gets one, and an edit=1 read or a PUT for the .env answers 403 "Editing this file is blocked".
The read and edit paths disagree about whether a dotenv file is sensitive:
isSensitivePath()(src/web/sensitive-path.ts) matches/.envand/.env.*, and the edit gate (assertEditableTarget()and theeditableflag infile-routes.ts) refuses anything it matches. The name allowlist insrc/config/file-editing.tsalso leavesenvout, because dotenv was sensitive-path blocked anyway (the v1 call indocs/file-viewer-edit-plan.md).- The plain preview (
GET /api/sessions/:id/file-content) andGET /api/sessions/:id/file-rawnever callisSensitivePath(), so the same file is served in full to the same user. Of the workspace routes, only/api/downloadrefuses it.
docs/security-architecture.md already describes the blocklist as defense in depth for downloads and attachments, with realpath containment as the control for the workspace routes. On the editor it protects nothing: whoever can open the editor has just read the secret in the preview, and the agent in that session can rewrite the file anyway. Its only effect is that .env is the one config file I have to leave the viewer to change.
Two ways to make this consistent:
- Let the editor open workspace dotenv files. PR #797 does this: the two edit-gate call sites pass
{ allowDotenv: true }throughisBlockedAttachmentPath()toisSensitivePath(), which then skips only the two dotenv patterns. Every other credential pattern still blocks editing, a dotenv file inside a sensitive tree (.ssh/.env,~/.codeman/backups/...) stays blocked, and Codeman's own data-dir.env(theCODEMAN_PASSWORDfallbackcodeman attachreads) gets a pattern of its own so it stays blocked even when a session's workspace is$HOME. The save already keeps the file's mode, so a 0600.envstays 0600. Downloads, attachments and the path picker are unchanged. - Make the preview and
file-rawhonour the blocklist too, so a dotenv file is neither shown nor edited in the viewer.
I prefer 1, since the file is the user's own and readable either way. If you want 2 instead, I'll close the PR and send that.
Seen on 1.49.0, git clone on Ubuntu under WSL2; the code is the same on master f62c1f7e (1.50.0). The refusal is server-side, so it shows in every browser and for every CLI mode.
Thanks for the careful report and for the PR.
I can confirm this on master (f62c1f7e, 1.50.0). For a file inside the session folder, the preview and file-raw rely on realpath containment and never consult the sensitive-path list. The edit gate does consult it, so a workspace .env is shown in full while edit=1 and PUT answer 403.
That refusal was deliberate in the first version of the editor. docs/file-viewer-edit-plan.md leaves env off the allowlist because dotenv was blocked anyway, and test/routes/file-write-routes.test.ts pins a workspace .env PUT as refused. So this would change a design decision rather than fix a regression.
PR #797 implements your option 1. Which way to go is a security-policy decision that is still open: let the editor open workspace dotenv files as #797 does, make the preview and file-raw honour the blocklist as in your option 2, or keep the current refusal.