MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _safe_doc_path

Function _safe_doc_path

codewiki/mcp/tools/doc_writer.py:32–40  ·  view source on GitHub ↗

Resolve *filename* within session.output_dir, guarding against traversal.

(session: SessionState, filename: str)

Source from the content-addressed store, hash-verified

30
31
32def _safe_doc_path(session: SessionState, filename: str) -> Path | None:
33 """Resolve *filename* within session.output_dir, guarding against traversal."""
34 if not filename.endswith(".md"):
35 filename += ".md"
36 output_base = Path(session.output_dir).resolve()
37 doc_path = (output_base / filename).resolve()
38 if not _is_within(doc_path, output_base):
39 return None
40 return doc_path
41
42
43def _ensure_parent_dirs(path: Path) -> None:

Callers 2

handle_write_doc_fileFunction · 0.85
handle_edit_doc_fileFunction · 0.85

Calls 2

_is_withinFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected