path_safety
azure_bootstrap.path_safety
¶
Filename + path sanitization.
Two-layered defense:
- :func:
sanitize_path_segmentfor filenames / single segments before they interpolate into blob paths, filesystem paths, email subjects, or log lines. - :func:
confine_to_rootfor resolved paths before opening files — refuses any escape from a configured root directory.
The bidi/zero-width regex is the live attack surface for visual-spoofing filename attacks (RLO injection in particular). Strip first, then everything else.
Functions:
| Name | Description |
|---|---|
sanitize_path_segment |
Normalize a single filename / path segment. |
confine_to_root |
Resolve |
sanitize_path_segment
¶
Normalize a single filename / path segment.
Order matters: bidi/zero-width chars are stripped BEFORE any other normalization so a visual-spoofing attack can't hide other transformations.
Source code in azure_bootstrap/path_safety/__init__.py
confine_to_root
¶
Resolve raw and assert it's under allowed_root.
Both inputs are canonicalized via Path.expanduser().resolve() before
comparison — protects against symlink escape and .. traversal.