mixle.utils.paths moduleΒΆ

Containment for caller-supplied path segments under a declared root.

A deployment or registry name that comes from a caller is joined onto a root directory, and os.path.join / pathlib are both happy to leave that root: root / "tasks" / "../../escaped" traverses out of it, and an ABSOLUTE segment discards the root entirely (Path("registry") / "/tmp/x" is /tmp/x). Nothing about that is exotic – a name arrives from an API request, a config file, or a CLI argument – and the consequence is a write outside the artifact root the caller believes they scoped it to (MXR-080-1910).

safe_segment() refuses a segment that is not a single path component. contained_path() additionally resolves the result and re-checks it against the resolved root, which is what catches a pre-existing symlink inside the root pointing elsewhere – a check on the string alone cannot see that. mixle.inference.production.registry has enforced the same two rules on its own store since MXR-080-0264; this is that logic made shared rather than re-derived.

contained_path(root, *segments, kind='name')[source]

Join segments under root, refusing anything that escapes it.

Each segment is checked as a single component, and the resolved result is then re-checked against the resolved root so a symlink already inside the root cannot redirect the write outside it.

Parameters:
Return type:

Path

safe_segment(segment, *, kind='name')[source]

Return segment unchanged, or raise unless it is a single safe path component.

Parameters:
Return type:

str