Changeset 167073 in webkit


Ignore:
Timestamp:
Apr 10, 2014 8:46:10 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[GStreamer] No CORS support for media elements
https://bugs.webkit.org/show_bug.cgi?id=99037

Patch by Youenn Fablet <youenn.fablet@crf.canon.fr> on 2014-04-10
Reviewed by Philippe Normand.

Source/WebCore:

Added CORS access control check to media sources when crossorigin attribute is set.

Added getter to CORS access control check status (used to compute whether the stream is tainted or not).
Related test is http/tests/security/video-cross-origin-readback.html.

Disabled access to cross-origin streams that fail CORS check when crossorigin attribute is set.
Related test is http/tests/security/video-cross-origin-accessfailure.html.

Tests: http/tests/security/video-cross-origin-accessfailure.html

http/tests/security/video-cross-origin-accesssameorigin.html

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:

(WebCore::MediaPlayerPrivateGStreamer::didPassCORSAccessCheck): Return whether media is cross-origin (tainted) or not by querying the gstreamer source layer.

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Added MediaPlayerPrivateGStreamer::didPassCORSAccessCheck declaration.
  • platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:

(webKitWebSrcStart): Passed CORS mode parameter to the streaming client. In case of CORS check failure, stop the resource loading.
(webKitSrcPassedCORSAccessCheck): Return whether CORS access control check was done and successful.
(StreamingClient::handleResponseReceived): Take a parameter to assign the CORS access control check result.
(CachedResourceStreamingClient::CachedResourceStreamingClient): Updated setting of the ResourceLoaderOptions according CORS mode.
(CachedResourceStreamingClient::responseReceived): Check CORS and pass result to handleResponseReceived.
(ResourceHandleStreamingClient::didReceiveResponse): No CORS check.

  • platform/graphics/gstreamer/WebKitWebSourceGStreamer.h: Added webKitSrcPassedCORSAccessCheck declaration.

LayoutTests:

http/tests/security/video-cross-origin-accessfailure.html verifies that cross-origin streams that fail CORS check
are not played when crossorigin attribute is set.

http/tests/security/video-cross-origin-accesssameorigin.html verifies that access to same-origin streams

are played when crossorigin attribute is set.

  • http/tests/security/video-cross-origin-accessfailure-expected.txt: Added.
  • http/tests/security/video-cross-origin-accessfailure.html: Added.
  • http/tests/security/video-cross-origin-accesssameorigin-expected.txt: Added.
  • http/tests/security/video-cross-origin-accesssameorigin.html: Added.
  • platform/efl/TestExpectations: Enabled http/tests/security/video-cross-origin-readback.html.
  • platform/gtk/TestExpectations: Ditto.
  • platform/mac/TestExpectations: Disabled http/tests/security/video-cross-origin-accessfailure.html.
Location:
trunk
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r167070 r167073  
     12014-04-10  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [GStreamer] No CORS support for media elements
     4        https://bugs.webkit.org/show_bug.cgi?id=99037
     5
     6        Reviewed by Philippe Normand.
     7
     8        http/tests/security/video-cross-origin-accessfailure.html verifies that cross-origin streams that fail CORS check
     9        are not played when crossorigin attribute is set.
     10         http/tests/security/video-cross-origin-accesssameorigin.html verifies that access to same-origin streams
     11        are played when crossorigin attribute is set.
     12
     13        * http/tests/security/video-cross-origin-accessfailure-expected.txt: Added.
     14        * http/tests/security/video-cross-origin-accessfailure.html: Added.
     15        * http/tests/security/video-cross-origin-accesssameorigin-expected.txt: Added.
     16        * http/tests/security/video-cross-origin-accesssameorigin.html: Added.
     17        * platform/efl/TestExpectations: Enabled http/tests/security/video-cross-origin-readback.html.
     18        * platform/gtk/TestExpectations: Ditto.
     19        * platform/mac/TestExpectations: Disabled http/tests/security/video-cross-origin-accessfailure.html.
     20
    1212014-04-09  Alexey Proskuryakov  <ap@apple.com>
    222
  • trunk/LayoutTests/platform/efl/TestExpectations

    r166930 r167073  
    302302# Pre-HMTL5 parser quirks only apply to the mac port for now.
    303303fast/parser/pre-html5-parser-quirks.html [ WontFix ]
    304 
    305 # No CORS support for media elements is implemented yet.
    306 Bug(EFL) http/tests/security/video-cross-origin-readback.html [ Failure ]
    307304
    308305# Perf tests are way too slow and some may fail due to timeout.
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r167012 r167073  
    304304webkit.org/b/79203 webaudio/mediastreamaudiodestinationnode.html [ Skip ]
    305305webkit.org/b/79203 webaudio/mediastreamaudiosourcenode.html [ Skip ]
    306 
    307 # No CORS support for media elements is implemented yet.
    308 webkit.org/b/99037 http/tests/security/video-cross-origin-readback.html [ Failure ]
    309306
    310307# New test infrastructure required -- need isolated worlds
  • trunk/LayoutTests/platform/mac/TestExpectations

    • Property svn:executable set to *
    r167070 r167073  
    504504# No CORS support for media elements is implemented yet.
    505505http/tests/security/video-cross-origin-readback.html
     506http/tests/security/video-cross-origin-accessfailure.html
    506507
    507508# media/audio-repaint.html sometimes fails on Lion Debug (Tests)
  • trunk/Source/WebCore/ChangeLog

    r167071 r167073  
     12014-04-10  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [GStreamer] No CORS support for media elements
     4        https://bugs.webkit.org/show_bug.cgi?id=99037
     5
     6        Reviewed by Philippe Normand.
     7
     8        Added CORS access control check to media sources when crossorigin attribute is set.
     9
     10        Added getter to CORS access control check status (used to compute whether the stream is tainted or not).
     11        Related test is http/tests/security/video-cross-origin-readback.html.
     12
     13        Disabled access to cross-origin streams that fail CORS check when crossorigin attribute is set.
     14        Related test is http/tests/security/video-cross-origin-accessfailure.html.
     15
     16        Tests: http/tests/security/video-cross-origin-accessfailure.html
     17               http/tests/security/video-cross-origin-accesssameorigin.html
     18
     19        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
     20        (WebCore::MediaPlayerPrivateGStreamer::didPassCORSAccessCheck): Return whether media is cross-origin (tainted) or not by querying the gstreamer source layer.
     21        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Added MediaPlayerPrivateGStreamer::didPassCORSAccessCheck declaration.
     22        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
     23        (webKitWebSrcStart): Passed CORS mode parameter to the streaming client. In case of CORS check failure, stop the resource loading.
     24        (webKitSrcPassedCORSAccessCheck): Return whether CORS access control check was done and successful.
     25        (StreamingClient::handleResponseReceived): Take a parameter to assign the CORS access control check result.
     26        (CachedResourceStreamingClient::CachedResourceStreamingClient): Updated setting of the ResourceLoaderOptions according CORS mode.
     27        (CachedResourceStreamingClient::responseReceived): Check CORS and pass result to handleResponseReceived.
     28        (ResourceHandleStreamingClient::didReceiveResponse): No CORS check.
     29        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.h: Added webKitSrcPassedCORSAccessCheck declaration.
     30
    1312014-04-10  Eva Balazsfalvi  <evab.u-szeged@partner.samsung.com>
    232
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

    r167025 r167073  
    18921892}
    18931893
     1894bool MediaPlayerPrivateGStreamer::didPassCORSAccessCheck() const
     1895{
     1896    if (m_source)
     1897        return webKitSrcPassedCORSAccessCheck(WEBKIT_WEB_SRC(m_source.get()));
     1898    return false;
     1899}
     1900
    18941901}
    18951902
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

    r167025 r167073  
    160160    virtual String engineDescription() const { return "GStreamer"; }
    161161    virtual bool isLiveStream() const { return m_isStreaming; }
     162    virtual bool didPassCORSAccessCheck() const;
    162163
    163164private:
  • trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp

    r166643 r167073  
    2828#include "CachedResourceLoader.h"
    2929#include "CachedResourceRequest.h"
     30#include "CrossOriginAccessControl.h"
    3031#include "GRefPtrGStreamer.h"
    3132#include "GStreamerUtilities.h"
     
    3637#include "ResourceRequest.h"
    3738#include "ResourceResponse.h"
     39#include "SecurityOrigin.h"
    3840#include "SharedBuffer.h"
    3941#include <gst/app/gstappsrc.h>
     
    4951using namespace WebCore;
    5052
     53enum CORSAccessCheckResult {
     54    CORSNoCheck,
     55    CORSSuccess,
     56    CORSFailure
     57};
     58
    5159class StreamingClient {
    5260    public:
     
    5967    protected:
    6068        char* createReadBuffer(size_t requestedSize, size_t& actualSize);
    61         void handleResponseReceived(const ResourceResponse&);
     69        void handleResponseReceived(const ResourceResponse&, CORSAccessCheckResult);
    6270        void handleDataReceived(const char*, int);
    6371        void handleNotifyFinished();
     
    6977    WTF_MAKE_NONCOPYABLE(CachedResourceStreamingClient); WTF_MAKE_FAST_ALLOCATED;
    7078    public:
    71         CachedResourceStreamingClient(WebKitWebSrc*, CachedResourceLoader*, const ResourceRequest&);
     79        CachedResourceStreamingClient(WebKitWebSrc*, CachedResourceLoader*, const ResourceRequest&, MediaPlayerClient::CORSMode);
    7280        virtual ~CachedResourceStreamingClient();
    7381
     
    8492
    8593        CachedResourceHandle<CachedRawResource> m_resource;
     94        RefPtr<SecurityOrigin> m_origin;
    8695};
    8796
     
    120129
    121130    StreamingClient* client;
     131
     132    CORSAccessCheckResult corsAccessCheck;
    122133
    123134    guint64 offset;
     
    438449    GMutexLocker locker(GST_OBJECT_GET_LOCK(src));
    439450
     451    priv->corsAccessCheck = CORSNoCheck;
     452
    440453    if (!priv->uri) {
    441454        GST_ERROR_OBJECT(src, "No URI provided");
     
    484497    if (priv->player) {
    485498        if (CachedResourceLoader* loader = priv->player->cachedResourceLoader())
    486             priv->client = new CachedResourceStreamingClient(src, loader, request);
     499            priv->client = new CachedResourceStreamingClient(src, loader, request, priv->player->mediaPlayerClient()->mediaPlayerCORSMode());
    487500    }
    488501
     
    754767}
    755768
     769bool webKitSrcPassedCORSAccessCheck(WebKitWebSrc* src)
     770{
     771    return src->priv->corsAccessCheck == CORSSuccess;
     772}
     773
    756774StreamingClient::StreamingClient(WebKitWebSrc* src)
    757775    : m_src(adoptGRef(static_cast<GstElement*>(gst_object_ref(src))))
     
    782800}
    783801
    784 void StreamingClient::handleResponseReceived(const ResourceResponse& response)
     802void StreamingClient::handleResponseReceived(const ResourceResponse& response, CORSAccessCheckResult corsAccessCheck)
    785803{
    786804    WebKitWebSrc* src = WEBKIT_WEB_SRC(m_src.get());
     
    789807    GST_DEBUG_OBJECT(src, "Received response: %d", response.httpStatusCode());
    790808
    791     if (response.httpStatusCode() >= 400) {
    792         // Received error code
    793         GST_ELEMENT_ERROR(src, RESOURCE, READ, ("Received %d HTTP error code", response.httpStatusCode()), (0));
     809    if (response.httpStatusCode() >= 400 || corsAccessCheck == CORSFailure) {
     810        // Received error code or CORS check failed
     811        if (corsAccessCheck == CORSFailure)
     812            GST_ELEMENT_ERROR(src, RESOURCE, READ, ("Cross-origin stream load denied by Cross-Origin Resource Sharing policy."), (nullptr));
     813        else
     814            GST_ELEMENT_ERROR(src, RESOURCE, READ, ("Received %d HTTP error code", response.httpStatusCode()), (nullptr));
    794815        gst_app_src_end_of_stream(priv->appsrc);
    795816        webKitWebSrcStop(src);
     
    798819
    799820    GMutexLocker locker(GST_OBJECT_GET_LOCK(src));
     821
     822    priv->corsAccessCheck = corsAccessCheck;
    800823
    801824    if (priv->seekSource.isActive()) {
     
    812835            // Range request completely failed.
    813836            locker.unlock();
    814             GST_ELEMENT_ERROR(src, RESOURCE, READ, ("Received unexpected %d HTTP status code", response.httpStatusCode()), (0));
     837            GST_ELEMENT_ERROR(src, RESOURCE, READ, ("Received unexpected %d HTTP status code", response.httpStatusCode()), (nullptr));
    815838            gst_app_src_end_of_stream(priv->appsrc);
    816839            webKitWebSrcStop(src);
     
    970993}
    971994
    972 CachedResourceStreamingClient::CachedResourceStreamingClient(WebKitWebSrc* src, CachedResourceLoader* resourceLoader, const ResourceRequest& request)
     995CachedResourceStreamingClient::CachedResourceStreamingClient(WebKitWebSrc* src, CachedResourceLoader* resourceLoader, const ResourceRequest& request, MediaPlayerClient::CORSMode corsMode)
    973996    : StreamingClient(src)
    974997{
    975998    DataBufferingPolicy bufferingPolicy = request.url().protocolIs("blob") ? BufferData : DoNotBufferData;
    976     CachedResourceRequest cacheRequest(request, ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, bufferingPolicy, DoNotAllowStoredCredentials, DoNotAskClientForCrossOriginCredentials, DoSecurityCheck, UseDefaultOriginRestrictionsForType));
     999    RequestOriginPolicy corsPolicy = corsMode != MediaPlayerClient::Unspecified ? PotentiallyCrossOriginEnabled : UseDefaultOriginRestrictionsForType;
     1000    StoredCredentials allowCredentials = corsMode == MediaPlayerClient::UseCredentials ? AllowStoredCredentials : DoNotAllowStoredCredentials;
     1001    ResourceLoaderOptions options(SendCallbacks, DoNotSniffContent, bufferingPolicy, allowCredentials, DoNotAskClientForCrossOriginCredentials, DoSecurityCheck, corsPolicy);
     1002
     1003    CachedResourceRequest cacheRequest(request, options);
     1004
     1005    if (corsMode != MediaPlayerClient::Unspecified) {
     1006        m_origin = resourceLoader->document() ? resourceLoader->document()->securityOrigin() : nullptr;
     1007        updateRequestForAccessControl(cacheRequest.mutableResourceRequest(), m_origin.get(), allowCredentials);
     1008    }
     1009
     1010    // TODO: Decide whether to use preflight mode for cross-origin requests (see http://wkbug.com/131484).
    9771011    m_resource = resourceLoader->requestRawResource(cacheRequest);
    9781012    if (m_resource)
     
    10041038}
    10051039
    1006 void CachedResourceStreamingClient::responseReceived(CachedResource*, const ResourceResponse& response)
    1007 {
    1008     handleResponseReceived(response);
     1040void CachedResourceStreamingClient::responseReceived(CachedResource* resource, const ResourceResponse& response)
     1041{
     1042    CORSAccessCheckResult corsAccessCheck = CORSNoCheck;
     1043    if (m_origin)
     1044        corsAccessCheck = (m_origin->canRequest(response.url()) || resource->passesAccessControlCheck(m_origin.get())) ? CORSSuccess : CORSFailure;
     1045    handleResponseReceived(response, corsAccessCheck);
    10091046}
    10101047
     
    10681105void ResourceHandleStreamingClient::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
    10691106{
    1070     handleResponseReceived(response);
     1107    handleResponseReceived(response, CORSNoCheck);
    10711108}
    10721109
  • trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.h

    r108524 r167073  
    4848GType webkit_web_src_get_type(void);
    4949void webKitWebSrcSetMediaPlayer(WebKitWebSrc*, WebCore::MediaPlayer*);
     50bool webKitSrcPassedCORSAccessCheck(WebKitWebSrc*);
    5051
    5152G_END_DECLS
Note: See TracChangeset for help on using the changeset viewer.