nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Files whose names start with ".." (for example "..env") are treated as outside the workspace

Open addyCooks opened this issue 1 month ago • 2 comments

Summary

Several containment checks use relative.startsWith('..'). That also matches a normal file called ..env, so checkpoints and the timeline skip it.

Steps to reproduce

  1. Create a workspace containing ..env and ok.txt.
  2. Run new FileSnapshotService(root).captureFiles(['..env', 'ok.txt']).
  3. Run new TimelineManager(root, 's1').toRelativePath('..env').

Expected behaviour

..env is captured, and toRelativePath returns '..env'.

Actual behaviour

snapshots: [ 'ok.txt' ]  skipped: [ { path: '..env', reason: 'Outside the workspace' } ]
toRelativePath('..env')  -> null

Two specs fail (snapshots is missing '..env', and - null + '..env'). A checkpoint or undo will not restore such a file.

Environment

Windows 11, Node v22.22.3, Nanocoder 1.31.0 (main at 948a4e74)

Suggested fix

Replace relative.startsWith('..') with relative === '..' || relative.startsWith('..' + path.sep) in:

  • source/services/file-snapshot.ts:63
  • source/services/timeline-manager.ts:158
  • source/services/lifecycle-hooks.ts:296
  • source/skills/install.ts:480
  • source/init/initializer.ts:35
  • source/storage/diagnostics.ts:209 and :590

A small shared helper would avoid repeating it.

addyCooks avatar Nov 02 '26 16:11 addyCooks

I'd like to take this — will tighten the containment checks so a file named ..env is treated as in-workspace (prefix ../ / exact ..), not as parent-path escape via startsWith('..').

ShahadatTest avatar Nov 02 '26 16:11 ShahadatTest

Hi @ShahadatTest, thanks for the PR! I've assigned this issue to you, so you're good to go this time. From next time, please ask to be assigned on the issue first and wait for a maintainer to assign it before opening a PR.

addyCooks avatar Nov 03 '26 06:11 addyCooks