- Location
- youtube_upload.py:51
- Finding
- Missing Download Size Enforcement and Cleanup Permit Storage Exhaustion<![CDATA[
## Vulnerability Details
**File Location**: `youtube_upload.py:51-87` and `youtube_upload.py:103-145`
**Vulnerability Type**: Uncontrolled resource consumption and missing temporary-file cleanup
**Risk Level**: Medium
### Vulnerable Code
```python
download_cmd = [
"yt-dlp",
"-x", # Extract audio
"--audio-format", "mp3",
"--audio-quality", "192K",
"-o", output_template,
url
]
try:
result = subprocess.run(download_cmd, capture_output=True, text=True, timeout=300)
if result.returncode != 0:
return {"error": f"Download failed: {result.stderr}"}
# Find downloaded file
downloaded_files = list(Path(output_dir).glob("*.mp3"))
if not downloaded_files:
return {"error": "No audio file found after download"}
audio_file = downloaded_files[0]
file_size = audio_file.stat().st_size
file_size_mb = round(file_size / (1024 * 1024), 2)
```
The successful execution path returns the file information but performs no cleanup:
```python
output = {
"status": "success",
"message": f"Audio downloaded: {result['file_name']} ({result['file_size_mb']} MB)",
"video_info": {
"title": result["video_title"],
"id": result["video_id"],
"duration": result["video_duration"],
"url": result["video_url"],
},
"file_info": {
"path": result["file_path"],
"name": result["file_name"],
"size": result["file_size"],
"size_mb": result["file_size_mb"],
},
"next_steps": [
"1. Upload to Feishu cloud: feishu_drive_file (action=upload, file_path=<path>)",
"2. Send to user: feishu_im_user_message (msg_type=file, content={'file_key': <token>})",
]
}
print(json.dumps(output, indent=2, ensure_ascii=False))
```
### Technical Analysis
The Skill documentation declares a maximum file size of 100 MB and automatic cleanup, but the dispatched implementation enforces neither control.
The five-minute process timeout limits wall
...[truncated 1498 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Enforce the documented limit before downloading when metadata provides a reliable expected size.
2. Pass an explicit downloader limit such as `--max-filesize 100M`.
3. Apply a post-download size check because metadata may be absent or inaccurate.
4. Delete files that exceed the permitted limit before returning an error.
5. Use a per-invocation temporary directory and remove it in a `finally` block on success, failure, cancellation, and timeout.
6. Explicitly terminate and reap the complete downloader/converter process tree when timeouts occur.
7. Configure filesystem quotas and global concurrency limits as defense in depth.
8. Limit video duration in addition to output bytes, because conversion can also consume substantial CPU.
9. Ensure cleanup happens only after the Feishu upload has actually completed, rather than retaining files indefinitely for an unspecified downstream process.
10. Monitor temporary-directory usage and periodically remove abandoned invocation directories using a narrowly scoped cleanup policy.
Example downloader hardening:
```python
download_cmd = [
"yt-dlp",
"--max-filesize", "100M",
"-x",
"--audio-format", "mp3",
"--audio-quality", "192K",
"-o", output_template,
url,
]
```
After download, independently verify:
```python
max_size = 100 * 1024 * 1024
if audio_file.stat().st_size > max_size:
audio_file.unlink(missing_ok=True)
return {"error": "Downloaded audio exceeds the 100 MB limit"}
```
]]>