History

avformat/hls: Check local file extensions

This reduces the attack surface of local file-system information leaking. It prevents the existing exploit leading to an information leak. As well as similar hypothetical attacks. Leaks of information from files and symlinks ending in common multimedia extensions are still possible. But files with sensitive information like private keys and passwords generally do not use common multimedia filename extensions. It does not stop leaks via remote addresses in the LAN. The existing exploit depends on a specific decoder as well. It does appear though that the exploit should be possible with any decoder. The problem is that as long as sensitive information gets into the decoder, the output of the decoder becomes sensitive as well. The only obvious solution is to prevent access to sensitive information. Or to disable hls or possibly some of its feature. More complex solutions like checking the path to limit access to only subdirectories of the hls path may work as an alternative. But such solutions are fragile and tricky to implement portably and would not stop every possible attack nor would they work with all valid hls files. Developers have expressed their dislike / objected to disabling hls by default as well as disabling hls with local files. There also where objections against restricting remote url file extensions. This here is a less robust but also lower inconvenience solution. It can be applied stand alone or together with other solutions. limiting the check to local files was suggested by nevcairiel This recommits the security fix without the author name joke which was originally requested by Nicolas. Found-by: Emil Lerner and Pavel Cheremushkin Reported-by: Thierry Foucu <tfoucu@google.com>

Michael Niedermayer committed 9 years ago

Commit 189ff421 parent c0702ab1 file · +17 −1Browse files

Unified · Split

libavformat/hls.c+17−1
@@ -204,6 +204,7 @@ typedef struct HLSContext { · 203 unmodified lines
204 char *http_proxy; ///< holds the address of the HTTP proxy server204 char *http_proxy; ///< holds the address of the HTTP proxy server
205 AVDictionary *avio_opts;205 AVDictionary *avio_opts;
206 int strict_std_compliance;206 int strict_std_compliance;
207 char *allowed_extensions;
207} HLSContext;208} HLSContext;
208 209
209static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)210static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
@@ -618,8 +619,19 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, · 408 unmodified lines
618 return AVERROR_INVALIDDATA;619 return AVERROR_INVALIDDATA;
619 620
620 // only http(s) & file are allowed621 // only http(s) & file are allowed
621 if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL))622 if (av_strstart(proto_name, "file", NULL)) {
623 if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
624 av_log(s, AV_LOG_ERROR,
625 "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"
626 "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
627 url);
628 return AVERROR_INVALIDDATA;
629 }
630 } else if (av_strstart(proto_name, "http", NULL)) {
631 ;
632 } else
622 return AVERROR_INVALIDDATA;633 return AVERROR_INVALIDDATA;
634
623 if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')635 if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
624 ;636 ;
625 else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')637 else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
@@ -2134,6 +2146,10 @@ static int hls_probe(AVProbeData *p) · 1508 unmodified lines
2134static const AVOption hls_options[] = {2146static const AVOption hls_options[] = {
2135 {"live_start_index", "segment index to start live streams at (negative values are from the end)",2147 {"live_start_index", "segment index to start live streams at (negative values are from the end)",
2136 OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS},2148 OFFSET(live_start_index), AV_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS},
2149 {"allowed_extensions", "List of file extensions that hls is allowed to access",
2150 OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
2151 {.str = "3gp,aac,avi,flac,mkv,m3u8,m4a,m4s,m4v,mpg,mov,mp2,mp3,mp4,mpeg,mpegts,ogg,ogv,oga,ts,vob,wav"},
2152 INT_MIN, INT_MAX, FLAGS},
2137 {NULL}2153 {NULL}
2138};2154};
2139 2155

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t