Skip to content

Commit 614d83a

Browse files
authored
Fix path traversal vulnerability in purge_memory (#123)
Added _validate_fid call to sanitize incoming file IDs before executing file system operations like os.remove and os.path.join.
1 parent 06fede0 commit 614d83a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

.jules/sentinel.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@
3030
**Vulnerability:** Insecure Subprocess Call (Path Hijacking risk via unqualified `git` command)
3131
**Learning:** Subprocess calls without absolute paths allow malicious binaries injected into the PATH to be executed.
3232
**Prevention:** Always use `shutil.which` to resolve absolute paths of binaries and explicitly handle execution failure if the executable cannot be found before executing `subprocess.run` or `subprocess.Popen`.
33+
## 2024-05-30 - Fix Path Traversal in purge_memory
34+
**Vulnerability:** The `purge_memory` function in `src/ledgermind/core/stores/semantic.py` concatenated the `fid` parameter directly with `self.repo_path` without validation, allowing a potential path traversal risk.
35+
**Learning:** File identifiers (fids) should always be validated, even for deletion endpoints, as untrusted input can result in arbitrary file deletion outside the intended directory scope.
36+
**Prevention:** Always sanitize or canonicalize identifiers against the base directory by calling `_validate_fid` (or similar mechanisms) before passing them to file system operations like `os.path.join` and `os.remove`.

src/ledgermind/core/stores/semantic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ def list_decisions(self) -> List[str]:
558558
if should_lock: self._fs_lock.release()
559559

560560
def purge_memory(self, fid: str):
561+
fid = self._validate_fid(fid)
561562
should_lock = not self._in_transaction
562563
if should_lock: self._fs_lock.acquire(exclusive=True)
563564
try:

0 commit comments

Comments
 (0)