Media document sends incorrect referer header
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Aug 2014 17:24:34 +0000 (17:24 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Aug 2014 17:24:34 +0000 (17:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135839

Reviewed by Jer Noble.

Source/WebCore:

Test: http/tests/media/media-document-referer.html

* html/MediaDocument.cpp:
(WebCore::MediaDocumentParser::MediaDocumentParser): Stash referrer.
(WebCore::MediaDocumentParser::createDocumentStructure): Set outgoing referrer.
(WebCore::MediaDocument::MediaDocument): Stash referrer.
* html/MediaDocument.h:

LayoutTests:

* http/tests/media/media-document-referer-expected.txt: Added.
* http/tests/media/media-document-referer.html: Added.
* http/tests/media/resources/video-referer-check-referer.php: Take expected referer as a
    parameter instead of hard coding it.
* http/tests/media/video-referer.html: Pass referer to loader script.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172523 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/media/media-document-referer-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/media-document-referer.html [new file with mode: 0644]
LayoutTests/http/tests/media/resources/video-referer-check-referer.php
LayoutTests/http/tests/media/video-referer.html
Source/WebCore/ChangeLog
Source/WebCore/html/MediaDocument.cpp
Source/WebCore/html/MediaDocument.h

index 7564d88..ffae7d8 100644 (file)
@@ -1,3 +1,16 @@
+2014-08-13  Eric Carlson  <eric.carlson@apple.com>
+
+        Media document sends incorrect referer header
+        https://bugs.webkit.org/show_bug.cgi?id=135839
+
+        Reviewed by Jer Noble.
+
+        * http/tests/media/media-document-referer-expected.txt: Added.
+        * http/tests/media/media-document-referer.html: Added.
+        * http/tests/media/resources/video-referer-check-referer.php: Take expected referer as a
+            parameter instead of hard coding it.
+        * http/tests/media/video-referer.html: Pass referer to loader script.
+
 2014-08-13  Mihnea Ovidenie  <mihnea@adobe.com>
 
         [CSSRegions] Move scrolling tests under fast/regions/scrolling
diff --git a/LayoutTests/http/tests/media/media-document-referer-expected.txt b/LayoutTests/http/tests/media/media-document-referer-expected.txt
new file mode 100644 (file)
index 0000000..23e8ba4
--- /dev/null
@@ -0,0 +1,5 @@
+Tests that a media document has correct referer header.
+
+video loaded, referer was correct! OK
+END OF TEST
+
diff --git a/LayoutTests/http/tests/media/media-document-referer.html b/LayoutTests/http/tests/media/media-document-referer.html
new file mode 100644 (file)
index 0000000..21f3ac4
--- /dev/null
@@ -0,0 +1,49 @@
+<html>
+    <head>
+        <script src=../../media-resources/video-test.js></script>
+        <script src=../../media-resources/media-file.js></script>
+        <script>
+            var counter = 0;
+            var frame;
+
+            function videoTest()
+            {
+                var video = frame.contentDocument.getElementsByTagName('video')[0];
+
+                if (video.error) {
+                    failTest("video failed to load, referer was incorrect.");
+                    return;
+                }
+                
+                if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {
+                    logResult(true, "video loaded, referer was correct!");
+                    endTest();
+                    return;
+                }
+
+                if (++counter >= 10) {
+                    failTest("TIMEOUT: video failed to load without an error.");
+                    return;
+                }
+
+                setTimeout(videoTest, 100);
+            }
+
+            function loadMediaDocument()
+            {
+                var movie = findMediaFile('video', 'test');
+                var type = mimeTypeForExtension(movie.split('.').pop());
+                frame = document.createElement('iframe');
+
+                frame.width = "100%";
+                frame.height = "100%";
+                frame.onload = videoTest;
+                frame.src = 'http://127.0.0.1:8000/media/resources/video-referer-check-referer.php?referer=media-document-referer.html&name=' + movie + '&type=' + type;
+                document.body.appendChild(frame);
+            }
+        </script>
+    </head>
+    <body onload="loadMediaDocument()">
+        Tests that a media document has correct referer header.<br/>
+    </body>
+</html>
index 4210d38..fb1a628 100644 (file)
@@ -1,7 +1,8 @@
 <?php
 
-    $refer = $_SERVER["HTTP_REFERER"];
-    if (!isset($refer) || stripos($refer, "video-referer.html") === false)
+    $requiredReferer = $_GET["referer"];
+    $referHeader = $_SERVER["HTTP_REFERER"];
+    if (!isset($referHeader) || stripos($referHeader, $requiredReferer) === false)
         die;
 
     $fileName = $_GET["name"];
index 09077f8..2a9b0f1 100644 (file)
@@ -16,7 +16,7 @@
         frame.height = 0;
         frame.addEventListener('load', function () {
                 source = document.getElementById('source');
-                source.src = 'http://127.0.0.1:8000/media/resources/video-referer-check-referer.php?name=' + movie + '&type=' + type;
+                source.src = 'http://127.0.0.1:8000/media/resources/video-referer-check-referer.php?referer=video-referer.html&name=' + movie + '&type=' + type;
                 source.type = type;
 
                 waitForEventAndFail('error');
index 5f09b7c..1e9c77d 100644 (file)
@@ -1,3 +1,18 @@
+2014-08-13  Eric Carlson  <eric.carlson@apple.com>
+
+        Media document sends incorrect referer header
+        https://bugs.webkit.org/show_bug.cgi?id=135839
+
+        Reviewed by Jer Noble.
+
+        Test: http/tests/media/media-document-referer.html
+
+        * html/MediaDocument.cpp:
+        (WebCore::MediaDocumentParser::MediaDocumentParser): Stash referrer.
+        (WebCore::MediaDocumentParser::createDocumentStructure): Set outgoing referrer.
+        (WebCore::MediaDocument::MediaDocument): Stash referrer.
+        * html/MediaDocument.h:
+
 2014-08-13  Antti Koivisto  <antti@apple.com>
 
         Don't recurse into non-rendered subtrees when computing style
index 49e626a..c9b773b 100644 (file)
@@ -58,10 +58,11 @@ public:
     }
     
 private:
-    MediaDocumentParser(Document& document)
+    MediaDocumentParser(MediaDocument& document)
         : RawDataDocumentParser(document)
         , m_mediaElement(0)
     {
+        m_outgoingReferrer = document.outgoingReferrer();
     }
 
     virtual void appendBytes(DocumentWriter&, const char*, size_t) override;
@@ -69,6 +70,7 @@ private:
     void createDocumentStructure();
 
     HTMLMediaElement* m_mediaElement;
+    String m_outgoingReferrer;
 };
     
 void MediaDocumentParser::createDocumentStructure()
@@ -124,6 +126,7 @@ void MediaDocumentParser::createDocumentStructure()
         return;
 
     frame->loader().activeDocumentLoader()->setMainResourceDataBufferingPolicy(DoNotBufferData);
+    frame->loader().setOutgoingReferrer(frame->document()->completeURL(m_outgoingReferrer));
 }
 
 void MediaDocumentParser::appendBytes(DocumentWriter&, const char*, size_t)
@@ -141,6 +144,8 @@ MediaDocument::MediaDocument(Frame* frame, const URL& url)
 {
     setCompatibilityMode(DocumentCompatibilityMode::QuirksMode);
     lockCompatibilityMode();
+    if (frame)
+        m_outgoingReferrer = frame->loader().outgoingReferrer();
 }
 
 MediaDocument::~MediaDocument()
index 3e34747..57ccd51 100644 (file)
@@ -41,6 +41,7 @@ public:
     virtual ~MediaDocument();
 
     void mediaElementSawUnsupportedTracks();
+    String outgoingReferrer() const { return m_outgoingReferrer; }
 
 private:
     MediaDocument(Frame*, const URL&);
@@ -52,6 +53,7 @@ private:
     void replaceMediaElementTimerFired(Timer<MediaDocument>&);
 
     Timer<MediaDocument> m_replaceMediaElementTimer;
+    String m_outgoingReferrer;
 };
 
 inline bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }