Expand description
URL path utilities for dev servers.
These helpers handle two concerns that every dev server needs:
- Strip an application
basePath(e.g./webui/) from incoming URLs on a segment boundary, so/webui-evil/xdoes NOT match/webui/. - Resolve the remaining path to a file inside an output directory
while rejecting traversal, percent-encoded
.., backslashes, NUL, and absolute markers in any segment.
Functions§
- normalize_
base_ path - Normalize a basePath to either
/or/<segments>/— exactly one leading and one trailing slash. Used to make matching deterministic. - resolve_
safe_ path - Resolve a URL path remainder (already base-stripped) to a filesystem
path inside
out_dir. ReturnsNonefor any input that would escapeout_diror that contains components forbidden for security reasons. - strip_
base_ path - Try to strip
base_pathfrom a URL path on a segment boundary.