This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 4f78ae1adad4d3eb3a3b28ed6b46d39883e2a88e
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Thu Sep 17 22:10:19 2026 +0200
Commit:     michaelni <[email protected]>
CommitDate: Sat Sep 19 18:53:13 2026 +0000

    avformat/http: send cookies set without a Domain only back to their host
    
    A Set-Cookie response without a Domain attribute was stored without any
    host restriction, so a redirect, a keep-alive reuse or a multi-host
    HLS/DASH manifest replayed the cookie to every later host, leaking
    session cookies across origins. RFC 6265 section 5.3 makes such a cookie
    host-only: it is returned to the exact host that set it and nothing else.
    
    Fixes: cross-host cookie leak
    Fixes: u2ys08MO8oEF
    Found-by: Yazan Balawneh, Cystack.ps
---
 libavformat/http.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index bd28e7d191..9088fc5af9 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1119,12 +1119,14 @@ static int host_in_cookie_domain(const char *host, 
const char *domain)
            (!offset || host[offset - 1] == '.');
 }
 
-static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies)
+static int parse_cookie(HTTPContext *s, const char *p, const char *host,
+                        AVDictionary **cookies)
 {
     AVDictionary *new_params = NULL;
     const AVDictionaryEntry *e, *cookie_entry;
     const char *eql;
-    char *name;
+    char *name, *value;
+    int len;
 
     // ensure the cookie is parsable
     if (parse_set_cookie(p, &new_params)) {
@@ -1172,6 +1174,7 @@ static int parse_cookie(HTTPContext *s, const char *p, 
AVDictionary **cookies)
             }
         }
     }
+    int host_only = host && !cookie_domain(new_params);
     av_dict_free(&new_params);
 
     // duplicate the cookie name (dict will dupe the value)
@@ -1179,7 +1182,15 @@ static int parse_cookie(HTTPContext *s, const char *p, 
AVDictionary **cookies)
     if (!(name = av_strndup(p, eql - p))) return AVERROR(ENOMEM);
 
     // add the cookie to the dictionary
-    av_dict_set(cookies, name, eql, AV_DICT_DONT_STRDUP_KEY);
+    len = strlen(eql);
+    while (len && strchr(WHITESPACES, eql[len - 1]))
+        len--;
+    value = av_asprintf("%.*s%s%s", len, eql, host_only ? "; @hostonly=" : "", 
host_only ? host : "");
+    if (!value) {
+        av_free(name);
+        return AVERROR(ENOMEM);
+    }
+    av_dict_set(cookies, name, value, AV_DICT_DONT_STRDUP_KEY | 
AV_DICT_DONT_STRDUP_VAL);
 
     return 0;
 }
@@ -1377,7 +1388,7 @@ static int process_line(URLContext *h, char *line, int 
line_count, int *parsed_h
             av_free(s->mime_type);
             s->mime_type = av_get_token((const char **)&p, ";");
         } else if (!av_strcasecmp(tag, "Set-Cookie")) {
-            if (parse_cookie(s, p, &s->cookie_dict))
+            if (parse_cookie(s, p, s->host, &s->cookie_dict))
                 av_log(h, AV_LOG_WARNING, "Unable to parse '%s'\n", p);
         } else if (!av_strcasecmp(tag, "Icy-MetaInt")) {
             s->icy_metaint = strtoull(p, NULL, 10);
@@ -1442,7 +1453,7 @@ static int get_cookies(HTTPContext *s, char **cookies, 
const char *path)
 
         next = NULL;
         // store the cookie in a dict in case it is updated in the response
-        if (parse_cookie(s, cookie, &s->cookie_dict))
+        if (parse_cookie(s, cookie, NULL, &s->cookie_dict))
             av_log(s, AV_LOG_WARNING, "Unable to parse '%s'\n", cookie);
 
         // continue on to the next cookie if this one cannot be parsed
@@ -1468,6 +1479,9 @@ static int get_cookies(HTTPContext *s, char **cookies, 
const char *path)
         if (domain && !host_in_cookie_domain(s->host, domain))
             goto skip_cookie;
 
+        if ((e = av_dict_get(cookie_params, "@hostonly", NULL, 0)) && 
av_strcasecmp(e->value, s->host))
+            goto skip_cookie;
+
         // if a cookie path is provided, ensure the request path is within 
that path
         e = av_dict_get(cookie_params, "path", NULL, 0);
         if (e) {

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to