mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-07-22 09:27:11 +00:00
Validate and escape values in --write-link output
See https://github.com/yt-dlp/yt-dlp/security/advisories/GHSA-6v4j-43gg-vj32 Authored by: bashonly
This commit is contained in:
+17
-1
@@ -4631,8 +4631,21 @@ LINK_TEMPLATES = {
|
||||
'webloc': DOT_WEBLOC_LINK_TEMPLATE,
|
||||
}
|
||||
|
||||
# Ref: https://specifications.freedesktop.org/desktop-entry/latest/value-types.html
|
||||
_DESKTOP_ENTRY_TRANS = str.maketrans({
|
||||
' ': R'\s',
|
||||
'\n': R'\n',
|
||||
'\t': R'\t',
|
||||
'\r': R'\r',
|
||||
'\\': R'\\',
|
||||
})
|
||||
|
||||
def iri_to_uri(iri):
|
||||
|
||||
def _desktop_entry_localestring(s):
|
||||
return s.translate(_DESKTOP_ENTRY_TRANS)
|
||||
|
||||
|
||||
def iri_to_uri(iri, *, allowed_schemes=('http', 'https')):
|
||||
"""
|
||||
Converts an IRI (Internationalized Resource Identifier, allowing Unicode characters) to a URI (Uniform Resource Identifier, ASCII-only).
|
||||
|
||||
@@ -4641,6 +4654,9 @@ def iri_to_uri(iri):
|
||||
|
||||
iri_parts = urllib.parse.urlparse(iri)
|
||||
|
||||
if iri_parts.scheme not in allowed_schemes:
|
||||
raise ValueError(f'"{iri_parts.scheme}" is not in allowed_schemes: {", ".join(allowed_schemes)}')
|
||||
|
||||
if '[' in iri_parts.netloc:
|
||||
raise ValueError('IPv6 URIs are not, yet, supported.')
|
||||
# Querying `.netloc`, when there's only one bracket, also raises a ValueError.
|
||||
|
||||
Reference in New Issue
Block a user