After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 726314 - Add cookie jar to uridownloader
Add cookie jar to uridownloader
Status: RESOLVED DUPLICATE of bug 761099
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other All
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-03-14 09:49 UTC by David Waring
Modified: 2017-03-16 05:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
adaptivedemux: minimal HTTP context support (5.71 KB, patch)
2015-10-28 11:08 UTC, Philippe Normand
reviewed Details | Review
souphttpsrc: cookie jar and context query support (4.01 KB, patch)
2015-10-28 11:09 UTC, Philippe Normand
reviewed Details | Review

Description David Waring 2014-03-14 09:49:50 UTC
Uridownloader currently ignores cookies, this means that some elements such as hlsdemux and dashdemux may be denied access to media content because they are not presenting cookies set by the server when the session was started.

A cookie jar can be added to uridownloader to store cookies returned by requests and the relevant cookies can then be provided to the private urisrc element when a fetch is performed.
Comment 1 Sebastian Dröge (slomo) 2014-03-14 10:39:57 UTC
How would you get the cookies from the source that requested the playlist to the GstURIDownloader? They could probably be put as GstMeta on the source's buffers.

Also what about referer and other information one might want to pass to the HTTP request?
Comment 2 David Waring 2014-03-14 11:03:01 UTC
Good points. I suppose you could attach a GstMeta containing all the headers for the original HTTP response with the buffer. That way Set-Cookies and any other headers could be extracted as needed in downstream elements.

Although that wouldn't cope with multiple requests setting different cookies, so I suppose a GstMeta with a shared cookie jar object in it might also be a way to go.

Or both to get the best of both worlds.

I mainly flagged this because firefox, using gstreamer, failed to play back some HLS content from BBC iPlayer using a new CDN. The error message on the CDN server indicated that the cookie wasn't provided, and a quick check showed that uridownloader didn't do anything with cookies. Just thought it would be a good idea to flag this issue up.
Comment 3 Nicolas Dufresne (ndufresne) 2014-03-14 23:59:54 UTC
Yes, I remembered observing a similar issue with local broadcasting service in Québec Canada. Reportedly it's using The Platform framework with a Wowsa server. Basically it checks that cookies obtained when loading the web page are present when downloading the playlist (and also the fragments (though cross domain here)) as a best effort to prevent external player from playing the stream (hence preventing adds skip). I then forgot to file it, as this service has been blocked since for non Apple devices.
Comment 4 Sebastian Dröge (slomo) 2014-03-15 09:30:04 UTC
Ideally there would be a firefox HTTP source element that is using the firefox infrastructure, and uses that to get cookies, authentication information, etc. We did the same for webkit some years ago for this very reason.
Comment 5 Philippe Normand 2015-10-27 17:32:43 UTC
I've been experimenting with this approach:

- source element handles a "http" context query performed by uridownloader and adaptivedemux
- the context is set on adaptivedemux
- the context somehow stores the cookies. For now I'm reusing the GstCookieJar from bug 731170
- when downloading fragments adaptivedemux fetches the cookies from the context and set them on the source element if it has a cookies property

We could store more informations inside the context, like HTTP referer, user-agent, custom headers, I suppose.

With this approach I have here WebKit fetching the main playlist with the webkitwebsrc element, and uridownloader/adaptivedemux downloading fragments/manifests with cookies in http requests managed by souphttpsrc :)
Comment 6 Philippe Normand 2015-10-28 11:08:48 UTC
Created attachment 314301 [details] [review]
adaptivedemux: minimal HTTP context support

The uridownloader is now querying the source element for an HTTP
context, which stores session data (cookies only for now), and reusing
the data when fetching data over HTTP. Additionally the context is set
on adaptivedemux, which allows it to also properly use session data
when downloading fragments.
Comment 7 Philippe Normand 2015-10-28 11:09:03 UTC
Created attachment 314302 [details] [review]
souphttpsrc: cookie jar and context query support

Use a volatile Cookie jar to store cookies and handle the context
query so that session data can be shared with other elements (like
adaptivedemux).
Comment 8 Philippe Normand 2015-12-01 11:50:05 UTC
Any news about this? I think Thiago was playing around on this topic as well.
Comment 9 Thiago Sousa Santos 2015-12-01 11:53:27 UTC
Yes, I have some WIP patches but the server I was using for testing lifted the cookies requirement so I'm trying to find an alternative to testing this.

Any other known servers?
Comment 10 Philippe Normand 2015-12-01 11:58:41 UTC
The only one I know is private :/

But I suppose it shouldn't be too hard to build an HTTP server in Python that would check the cookies of the request before serving the video data.

There's a thing like that implemented in Perl in the WebKit layout test harness :)
Comment 11 Thiago Sousa Santos 2015-12-08 04:03:29 UTC
Hosted a small python flask-based server that simulates a cookies requirement: https://github.com/thiagoss/adaptive-test-server

Patches already work for DASH but fail for HLS because we still need to figure out how to share the context with uridownloader.
Comment 12 Philippe Normand 2015-12-08 11:41:15 UTC
With the 2 patches of this bug I have it working for HLS (in WebKit). If you have different changes can you please upload the patches?
Comment 13 Thiago Sousa Santos 2015-12-09 12:29:04 UTC
Latest work is kept here: http://cgit.freedesktop.org/~thiagoss/gst-plugins-good/log/?h=cookies

I've opted to sharing the cookie-jar directly because otherwise it is too complicated to keep cookies synchronized accross multiple elements. It works for HLS and DASH because the cookies are set on the first access and then just replicated but then new cookies set aren't synchronized anymore.

A generic GstCookieJar could be written that would listen and update different cookiejar implementations but it seems to me a bit overkill as long as we don't have pipeline with multiple different types of http sources working together. Usually there is only a single http source element involved.
Comment 14 Philippe Normand 2015-12-09 14:25:58 UTC
Ok I'll try this on my side but what about adaptivedemux/uridownloader? With your approach which element is querying the context?
Comment 15 Thiago Sousa Santos 2015-12-09 16:35:19 UTC
Just finished the uridownloader part:
http://cgit.freedesktop.org/~thiagoss/gst-plugins-bad/log/?h=cookies

There was also a bug about sharing the same user-agent and extra-headers IIRC. It would be nice to solve all of that in one go.
Comment 16 Philippe Normand 2015-12-11 07:43:10 UTC
The patches are not working here after implementing the need-context message support in WebKit :(
Comment 17 Sebastian Dröge (slomo) 2015-12-11 08:32:07 UTC
Review of attachment 314302 [details] [review]:

I think the approach is good, just one comment here (and we need to make sure the GstContext machinery works here properly)

::: ext/soup/gstsouphttpsrc.c
@@ +2039,3 @@
+          cookies[0] = cookie;
+          cookies[1] = NULL;
+          gst_structure_set (context_structure, "cookies", G_TYPE_STRV, cookies,

Is this really enough? Isn't a cookie usually stored together with the domain and where it can be used, to prevent arbitrary websites reading your cookies from elsewhere?
Comment 18 Sebastian Dröge (slomo) 2015-12-11 08:34:06 UTC
Comment on attachment 314301 [details] [review]
adaptivedemux: minimal HTTP context support

Shouldn't this also do something about the HAVE_CONTEXT and NEED_CONTEXT messages?

And should souphttpsrc also do those?
Comment 19 Thiago Sousa Santos 2015-12-11 12:23:43 UTC
(In reply to Philippe Normand from comment #16)
> The patches are not working here after implementing the need-context message
> support in WebKit :(

Did you check why it fails? Do you get the need-context messages in webkit?
Comment 20 Philippe Normand 2015-12-11 12:28:16 UTC
(In reply to Thiago Sousa Santos from comment #19)
> (In reply to Philippe Normand from comment #16)
> > The patches are not working here after implementing the need-context message
> > support in WebKit :(
> 
> Did you check why it fails? Do you get the need-context messages in webkit?

I do get and correctly handle the need-context messages in WebKit.
I haven't had time to debug this further yet but I suspect either:

- the uridownloader isn't using the cookies and/or hasn't the context set yet when requesting the fragments.
- or perhaps the cookie jar isn't storing the cookies for the right first-party domain. That would be an issue on WebKit side
Comment 21 Thiago Sousa Santos 2015-12-11 12:36:04 UTC
(In reply to Philippe Normand from comment #20)
> (In reply to Thiago Sousa Santos from comment #19)
> > (In reply to Philippe Normand from comment #16)
> > > The patches are not working here after implementing the need-context message
> > > support in WebKit :(
> > 
> > Did you check why it fails? Do you get the need-context messages in webkit?
> 
> I do get and correctly handle the need-context messages in WebKit.
> I haven't had time to debug this further yet but I suspect either:
> 
> - the uridownloader isn't using the cookies and/or hasn't the context set
> yet when requesting the fragments.
> - or perhaps the cookie jar isn't storing the cookies for the right
> first-party domain. That would be an issue on WebKit side

Did you handle those from a sync bus message handler? The context must be set before the handler returns (in sync with the element requesting it).
Comment 22 Philippe Normand 2015-12-14 12:55:52 UTC
Right on, Thiago :) It works now after moving the http context handling to a sync message handler.
Comment 23 Philippe Normand 2015-12-30 08:50:50 UTC
Are the patches ready for review Thiago? It would be nice if we can have them merged before 1.8.0 :)
Comment 24 Philippe Normand 2016-01-22 09:59:05 UTC
Have you sorted out the cookies issues? Please let me know if I can help.
Comment 25 Thiago Sousa Santos 2016-11-29 00:38:12 UTC
I believe those patches are ready to be merged:

https://cgit.freedesktop.org/~thiagoss/gst-plugins-base/log/?h=gstcookies
https://cgit.freedesktop.org/~thiagoss/gst-plugins-good/log/?h=gst-cookies

There are quite some patches, how do you prefer to review them?

Thanks to Philippe for all the help with this.
Comment 26 Philippe Normand 2016-11-29 08:17:29 UTC
These 2 patches as well?

https://cgit.freedesktop.org/~thiagoss/gst-plugins-bad/log/?h=cookies
Comment 27 Philippe Normand 2016-11-29 08:27:14 UTC
I think we should close this bug as dupe of #761099 and continue the discussion there :)
Comment 28 Tim-Philipp Müller 2016-11-29 09:46:42 UTC
Let's do that then :)

*** This bug has been marked as a duplicate of bug 761099 ***