Skip to content

Commit 3903d35

Browse files
jope-bmclaude
andcommitted
fix(core): harden traversal check against Windows dot/space normalization
Block segments like ".. " and ".. ." that Windows normalizes to "..", preventing path traversal on Windows filesystems. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Joe P <joe@basicmemory.com>
1 parent 2b7689a commit 3903d35

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/basic_memory/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,13 @@ def valid_project_path_value(path: str):
509509

510510
# Check for ".." as a path segment (path traversal), not as a substring.
511511
# Filenames like "hi-everyone..md" are legitimate and must not be blocked.
512+
# Also block segments like ".. " and ".. ." because Windows normalizes
513+
# trailing dots and spaces away, making them equivalent to "..".
512514
segments = path.replace("\\", "/").split("/")
513-
if any(seg == ".." for seg in segments):
515+
if any(
516+
seg == ".." or (len(seg) > 2 and seg[:2] == ".." and all(c in ". " for c in seg[2:]))
517+
for seg in segments
518+
):
514519
return False
515520

516521
# Check for Windows-style leading backslash

tests/utils/test_validate_project_path.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def test_actual_traversal_still_blocked(self, tmp_path):
227227
"notes/../../etc/passwd",
228228
"foo/../../../bar",
229229
"..\\Windows\\System32",
230+
# Windows normalizes trailing dots/spaces to ".."
231+
".. /file.md",
232+
".. ./file.md",
233+
"notes/.. /etc/passwd",
230234
]
231235

232236
for path in attack_paths:

0 commit comments

Comments
 (0)