T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/extract_subtitles.py:103
- Finding
- Persistent Plaintext Export of Browser Session Cookies<![CDATA[ ## Vulnerability Details **File Location**: `scripts/extract_subtitles.py`, lines 103–119 **Vulnerability Type**: Predictable and persistent storage of sensitive authentication data **Risk Level**: High ### Vulnerable Code ```python # First export cookies to a file so we don't re-authenticate per attempt if cookies_browser and not cookies_file: cookies_file = "/tmp/yt-cookies-export.txt" subprocess.run( [sys.executable, "-m", "yt_dlp", "--cookies-from-browser", cookies_browser, "--cookies", cookies_file, "--skip-download", "-o", "/tmp/yt_cookie_export_dummy", "--quiet", url], capture_output=True ) cookie_args = [] if cookies_file and os.path.exists(cookies_file): cookie_args = ["--cookies", cookies_file] elif cookies_browser: cookie_args = ["--cookies-from-browser", cookies_browser] ``` ### Technical Analysis When browser-based authentication is requested, the script exports browser cookies to the fixed path `/tmp/yt-cookies-export.txt`. The exported file is outside the lifetime of either `TemporaryDirectory` used elsewhere in the function, and the script never removes it. The code also does not explicitly create a private directory, enforce mode `0600`, verify ownership, or reject an existing symbolic link at that predictable path. The actual permissions may depend on `yt-dlp`, the operating system, and the process umask, but the Skill itself does not guarantee safe handling. Browser cookies are reusable authentication material. Depending on what `yt-dlp` exports and the services represented in the browser cookie store, the file may contain active YouTube, Google, Bilibili, or related session data. Persisting such credentials exceeds the minimum privilege needed to retrieve subtitles because the exported copy is only required during the fallback attempt. The subprocess return code is also ignored. A stale cookie file at the same path may consequently be reused if export f ...[truncated 1329 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Avoid exporting browser cookies when direct `--cookies-from-browser` access is sufficient. 2. If an intermediate file is unavoidable, create it inside a private temporary directory: - Create the directory with mode `0700`. - Create the cookie file atomically with mode `0600`. - Use a cryptographically unpredictable filename. 3. Delete the cookie file in a `finally` block, including when `yt-dlp` fails or the process is interrupted. 4. Validate that the created file is a regular file owned by the current user before reuse. 5. Do not reuse a pre-existing fixed path or stale cookie file. 6. Check the export subprocess return code and fail closed if export is unsuccessful. 7. Document that browser-cookie access exposes authentication material and require explicit user consent. 8. Where possible, use a restricted cookie file containing only the minimum domains and accounts needed for the requested video. ]]>
