T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/maat_upload.py:281- Finding
Uploader Permits Transmission of Arbitrary Local Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/maat_upload.py:281-286, 333-337, 578-599, 670-678
Mirrored Location:Hopola-Skills/.trae/skills/Hopola/scripts/maat_upload.py:281-286, 333-337, 578-599, 670-678
Vulnerability Type: Missing local-path authorization and insufficient least-privilege enforcement
Risk Level: HighVulnerable Code
python def _normalize_local_path(path: str) -> str: cleaned = unicodedata.normalize("NFC", path).replace("\\", "/") collapsed = _collapse_path_slashes(cleaned) if not collapsed.startswith("/"): collapsed = os.path.abspath(collapsed) return os.path.normpath(collapsed)python def _normalize_session_reference(raw_value: str) -> str: candidates = _session_reference_candidates(raw_value) for candidate in candidates: if os.path.isfile(candidate): return candidatepython def _multipart_body(fields: Dict[str, str], file_path: str, mime_type: str) -> Tuple[bytes, str]: boundary = f"----maat-{uuid.uuid4().hex}" boundary_bytes = boundary.encode("utf-8") with open(file_path, "rb") as f: file_bytes = f.read() file_name = os.path.basename(file_path) chunks: List[bytes] = [] for name, value in fields.items(): chunks.extend( [ b"--" + boundary_bytes + b"\r\n", f'Content-Disposition: form-data; name="{name}"\r\n\r\n'.encode("utf-8"), str(value).encode("utf-8"), b"\r\n", ] )python def upload_local_file(file_path: str) -> str: normalized_file_path = _normalize_session_reference(file_path) suffix, mime_type = suffix_and_mime(normalized_file_path) raw_token = _request_upload_policy(suffix) token = _normalize_policy_token(raw_token) if _has_s3_token(token): cdn_url = _upload_via_s3(token, norm ...[truncated 2347 chars]- Remediation
View remediation
Remediation Suggestions
- Define an explicit set of permitted upload roots, preferably limited to directories dedicated to current-session attachments and generated assets.
- Resolve the candidate with
os.path.realpath()orPath.resolve(strict=True)before authorization. - Verify containment using
os.path.commonpath()orPath.is_relative_to()against every approved root. - Reject symlinks whose resolved targets leave an approved root.
- Reject arbitrary absolute paths and relative paths that resolve outside approved directories.
- Track attachment provenance and require the selected path to correspond to an actual user attachment or generated output.
- Require explicit user confirmation before uploading files outside the standard attachment directory.
- Open files only after authorization and, where supported, use no-follow semantics to reduce time-of-check/time-of-use and symlink risks.
- Apply the correction to both copies of
maat_upload.pyand add regression tests for absolute paths, traversal paths, symlink escapes, and valid session files.
