Buckets:

download
raw
878 Bytes
"""Path traversal guard."""
from __future__ import annotations
from pathlib import Path
from typing import Sequence
from mcp_server.core.errors import MCPError
from mcp_server.security.path_allowlist import path_within_allowed
class PathTraversalError(MCPError):
pass
class PathTraversalGuard:
def __init__(self, allowed_roots: Sequence[Path]) -> None:
self._roots = tuple(Path(r).resolve() for r in allowed_roots)
def normalize_and_check(self, p: str | Path) -> Path:
candidate = Path(p).resolve()
if not self._roots:
# No roots configured — deny everything (safe default).
raise PathTraversalError(f"no allowed roots configured; rejecting {p!r}")
if not path_within_allowed(candidate, self._roots):
raise PathTraversalError(f"path {p!r} escapes allowed roots")
return candidate

Xet Storage Details

Size:
878 Bytes
·
Xet hash:
0d9f2d899e1d099a4953d10309a63538d24e98eaead938eefa99b9f3b8d7eaef

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.