Codeman icon indicating copy to clipboard operation
Codeman copied to clipboard

File Viewer: a workspace .env opens in the preview but can never be edited

Open JDProfresh opened this issue 3 weeks ago • 1 comments

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 /.env and /.env.*, and the edit gate (assertEditableTarget() and the editable flag in file-routes.ts) refuses anything it matches. The name allowlist in src/config/file-editing.ts also leaves env out, because dotenv was sensitive-path blocked anyway (the v1 call in docs/file-viewer-edit-plan.md).
  • The plain preview (GET /api/sessions/:id/file-content) and GET /api/sessions/:id/file-raw never call isSensitivePath(), so the same file is served in full to the same user. Of the workspace routes, only /api/download refuses 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:

  1. Let the editor open workspace dotenv files. PR #797 does this: the two edit-gate call sites pass { allowDotenv: true } through isBlockedAttachmentPath() to isSensitivePath(), 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 (the CODEMAN_PASSWORD fallback codeman attach reads) 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 .env stays 0600. Downloads, attachments and the path picker are unchanged.
  2. Make the preview and file-raw honour 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.

JDProfresh avatar Nov 09 '26 21:11 JDProfresh

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.

Ark0N avatar Nov 09 '26 22:11 Ark0N