(app_name: str, filename: Optional[str])
| 222 | _walk(doc) |
| 223 | |
| 224 | def _parse_upload_filename(app_name: str, filename: Optional[str]) -> str: |
| 225 | if not filename: |
| 226 | raise ValueError("Upload filename is missing.") |
| 227 | filename = _normalize_relative_path(filename) |
| 228 | prefix = f"{app_name}/" |
| 229 | if filename.startswith(prefix): |
| 230 | rel_path = filename[len(prefix) :] |
| 231 | else: |
| 232 | rel_path = filename |
| 233 | if not rel_path: |
| 234 | raise ValueError(f"Invalid upload filename: {filename!r}") |
| 235 | if rel_path.startswith("/"): |
| 236 | raise ValueError(f"Absolute upload path rejected: {filename!r}") |
| 237 | if _has_parent_reference(rel_path): |
| 238 | raise ValueError(f"Path traversal rejected: {filename!r}") |
| 239 | ext = os.path.splitext(rel_path)[1].lower() |
| 240 | if ext not in _ALLOWED_EXTENSIONS: |
| 241 | raise ValueError( |
| 242 | f"File type not allowed: {rel_path!r}" |
| 243 | f" (allowed: {', '.join(sorted(_ALLOWED_EXTENSIONS))})" |
| 244 | ) |
| 245 | return rel_path |
| 246 | |
| 247 | def _parse_file_path(file_path: str) -> str: |
| 248 | file_path = _normalize_relative_path(file_path) |
nothing calls this directly
no test coverage detected