fix(v2): enforce repository safety failures
This commit is contained in:
@@ -29,10 +29,19 @@ def blob_digest(content: bytes) -> str:
|
||||
|
||||
|
||||
def _contained(root: Path, relative_path: str) -> Path:
|
||||
candidate = (root / relative_path).resolve()
|
||||
if not relative_path or Path(relative_path).is_absolute() or candidate == root:
|
||||
relative = Path(relative_path)
|
||||
if not relative_path or relative.is_absolute():
|
||||
raise RepositoryError("repository path must be a non-empty relative child")
|
||||
if root not in candidate.parents:
|
||||
lexical = root
|
||||
for part in relative.parts:
|
||||
lexical /= part
|
||||
if lexical.is_symlink():
|
||||
raise RepositoryError("repository path contains a symlink")
|
||||
candidate = lexical.resolve()
|
||||
resolved_root = root.resolve()
|
||||
if candidate == resolved_root:
|
||||
raise RepositoryError("repository path must be a non-empty relative child")
|
||||
if resolved_root not in candidate.parents:
|
||||
raise RepositoryError("repository path escapes configured roots")
|
||||
return candidate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user