T09 · Insecure Skill Coding Practices
- Location
scripts/upload_file.py:27- Finding
Unrestricted Local File Upload to an External Service
- Content
View full analysis
Vulnerability Details
File Location:
scripts/upload_file.py:27-38
Vulnerability Type: Unrestricted file access and external upload
Risk Level: MediumVulnerable Code
python def upload_file_with_token(file_path): """使用token上传文件""" url = f"{API_BASE_URL}{UPLOAD_ENDPOINT}" # 获取token token = get_token() headers = { "Authorization": f"Bearer {token}" } with open(os.path.expanduser(file_path), 'rb') as f: files = {'file': f} response = requests.post(url, files=files, headers=headers, timeout=60)Technical Analysis
The function accepts an arbitrary filesystem path, expands home-directory notation, opens the referenced file with the current process's permissions, and transmits its complete contents to
https://api.jiuma.com/console/aiApp/uploadOneFile.Uploading user-selected media is necessary for the Skill's declared functionality. However, the implementation does not restrict access to expected media directories or file types. It also lacks canonical-path validation, symbolic-link checks, MIME validation, file-size limits, sensitive-directory denial rules, and a separate confirmation before external transmission.
Consequently, the script's filesystem access exceeds the minimum privileges needed to upload media. Any file readable by the user running the Skill can potentially be selected, including configuration files, API credentials, SSH keys, environment files, private documents, or Agent state.
Attack Path
- An attacker supplies a malicious instruction, task parameter, or social-engineering request that identifies a sensitive local path.
- The Agent invokes
upload_file.pywith that path, for example through--file_path=~/.ssh/id_rsa. os.path.expanduser()resolves the path to the user's home directory.open(..., 'rb')reads the file using the current user's privileges.requests.post()sends ...[truncated 909 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict uploads to explicitly approved workspace or media directories.
- Resolve the canonical path with
Path.resolve()and verify that it remains beneath an approved root directory. - Reject symbolic links and paths targeting sensitive locations such as
.ssh,.aws,.config, keyring storage, browser profiles, and Agent configuration directories. - Allowlist supported media extensions and verify actual content using MIME detection or file signatures rather than trusting the extension alone.
- Enforce maximum file-size limits before opening or transmitting a file.
- Require explicit user confirmation that displays the canonical path, destination domain, file type, and file size before upload.
- Check that a valid token exists before constructing and sending the authorization header.
- Document that selected files are transmitted to and handled by an external service.
