Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS03OXc3LXZoM2gtOGc0as4AA9dz

yt-dlp File system modification and RCE through improper file-extension sanitization

Summary

yt-dlp does not limit the extensions of downloaded files, which could lead to arbitrary filenames being created in the download folder (and path traversal on Windows). Since yt-dlp also reads config from the working directory (and on Windows executables will be executed from the yt-dlp directory) this could lead to arbitrary code being executed.

Patches

yt-dlp version 2024.07.01 fixes this issue by whitelisting the allowed extensions.
This means some very uncommon extensions might not get downloaded; however, it will also limit the possible exploitation surface.

Workarounds

It is recommended to upgrade yt-dlp to version 2024.07.01 as soon as possible, always have .%(ext)s at the end of the output template, and make sure you trust the websites that you are downloading from. Also, make sure to never download to a directory within PATH or other sensitive locations like your user directory, system32, or other binaries locations.

For users not able to upgrade:

Details

One potential exploitation might look like this:

From a mimetype we do not know, we default to trimming the leading bit and using the remainder. Given a webpage that contains

<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "ffmpeg",
    "encodingFormat": "video/exe",
    "contentUrl": "https://example.com/video.mp4"
}
</script>

this will try and download a file called ffmpeg.exe (-o "%(title)s.%(ext)s).
ffmpeg.exe will be searched for in the current directory, and so upon the next run arbitrary code can be executed.

Alternatively, when engineering a file called yt-dlp.conf to be created, the config file could contain --exec ... and so would also execute arbitrary code.

Acknowledgement

A big thanks to @JarLob for independently finding a new application of the same underlying issue.
More can be read about on the dedicated GitHub Security Lab disclosure here: Path traversal saving subtitles (GHSL-2024-090)

References

Permalink: https://github.com/advisories/GHSA-79w7-vh3h-8g4j
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS03OXc3LXZoM2gtOGc0as4AA9dz
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 2 months ago
Updated: 2 months ago


CVSS Score: 7.8
CVSS vector: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Identifiers: GHSA-79w7-vh3h-8g4j, CVE-2024-38519
References: Repository: https://github.com/yt-dlp/yt-dlp
Blast Radius: 27.7

Affected Packages

pypi:yt-dlp
Dependent packages: 251
Dependent repositories: 3,540
Downloads: 2,204,548 last month
Affected Version Ranges: < 2024.07.01
Fixed in: 2024.07.01
All affected versions: 2021.1.15, 2021.1.16, 2021.1.20, 2021.1.24, 2021.1.29, 2021.2.4, 2021.2.9, 2021.2.15, 2021.2.19, 2021.2.24, 2021.3.1, 2021.3.3, 2021.3.7, 2021.3.15, 2021.3.21, 2021.3.24, 2021.4.3, 2021.4.11, 2021.4.22, 2021.5.11, 2021.5.20, 2021.6.1, 2021.6.8, 2021.6.9, 2021.6.23, 2021.7.7, 2021.7.21, 2021.7.24, 2021.8.2, 2021.8.10, 2021.9.1, 2021.9.2, 2021.9.25, 2021.10.9, 2021.10.10, 2021.10.22, 2021.11.10, 2021.12.1, 2021.12.25, 2021.12.27, 2022.1.21, 2022.2.3, 2022.2.4, 2022.3.8, 2022.4.8, 2022.5.18, 2022.6.22, 2022.6.29, 2022.7.17, 2022.7.18, 2022.8.8, 2022.8.14, 2022.8.19, 2022.9.1, 2022.10.4, 2022.11.11, 2023.1.2, 2023.1.6, 2023.2.17, 2023.3.3, 2023.3.4, 2023.6.21, 2023.6.22, 2023.7.6, 2023.9.24, 2023.10.7, 2023.10.13, 2023.11.14, 2023.11.16, 2023.12.30, 2024.3.10, 2024.4.9, 2024.5.26, 2024.5.27
All unaffected versions: 2024.7.1, 2024.7.2, 2024.7.7, 2024.7.8, 2024.7.9, 2024.7.16, 2024.7.25, 2024.8.1, 2024.8.6