fix(core): allow double-dot filenames while still blocking path traversal (#673)

Signed-off-by: Joe P <joe@basicmemory.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jope-bm
2026-03-16 07:47:49 -06:00
committed by GitHub
parent 1a6a65571e
commit a77b51a28e
4 changed files with 81 additions and 4 deletions
+5
View File
@@ -447,6 +447,11 @@ def sanitize_for_filename(text: str, replacement: str = "-") -> str:
# compress multiple, repeated replacements
text = re.sub(f"{re.escape(replacement)}+", replacement, text)
# Strip trailing periods — they cause "hi-everyone..md" double-dot filenames
# when ".md" is appended, which triggers path traversal false positives.
# Trailing periods are also invalid on Windows filesystems.
text = text.strip(".")
return text.strip(replacement)
+15 -4
View File
@@ -503,12 +503,23 @@ def valid_project_path_value(path: str):
if not path:
return True
# Check for obvious path traversal patterns first
if ".." in path or "~" in path:
# Check for tilde (home directory expansion)
if "~" in path:
return False
# Check for Windows-style path traversal (even on Unix systems)
if "\\.." in path or path.startswith("\\"):
# Check for ".." as a path segment (path traversal), not as a substring.
# Filenames like "hi-everyone..md" are legitimate and must not be blocked.
# Also block segments like ".. " and ".. ." because Windows normalizes
# trailing dots and spaces away, making them equivalent to "..".
segments = path.replace("\\", "/").split("/")
if any(
seg == ".." or (len(seg) > 2 and seg[:2] == ".." and all(c in ". " for c in seg[2:]))
for seg in segments
):
return False
# Check for Windows-style leading backslash
if path.startswith("\\"):
return False
# Block absolute paths (Unix-style starting with / or Windows-style with drive letters)