pub fn validate_media_path(
path: &str,
repo_root: &Path,
static_folder: &str,
) -> Result<PathBuf, MbrError>Expand description
Validates a media path from a query parameter.
- URL-decodes the path
- Rejects paths containing “..” (directory traversal)
- Validates the path resolves within the repository root OR the static folder
§Arguments
path- The URL-encoded path from the query parameterrepo_root- The repository root directorystatic_folder- The static folder path (may be relative to repo_root, e.g., “../static”)
§Returns
Ok(PathBuf)- The validated, canonical path to the media fileErr(MbrError)- If the path is invalid or attempts directory traversal
§Security
When static_folder points outside repo_root (e.g., ../static), paths are validated
against BOTH directories. This allows serving assets from external static folders while
maintaining path traversal protection. Content root takes precedence if the file exists
in both locations.