Bug 1018299 - Throw security error if principal check fails in MediaRecorder::Start(). r=jib, r=mt
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 19 Apr 2016 16:37:40 +0200
changeset 331901 3e00ab630419ec6696e92d6aef4dca1b788e0be8
parent 331900 d5a155608cc105cb52431c128b7788a51dc8c8a4
child 331902 fa4d407df25318173b500dea37441e1615296f58
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, mt
bugs1018299
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1018299 - Throw security error if principal check fails in MediaRecorder::Start(). r=jib, r=mt We ignore the check in case there are no tracks yet available in the MediaStream. There are legacy tests depending on track-less-stream-to-MediaRecorder working and the spec doesn't mention it. MozReview-Commit-ID: Ee5f5qGdlMf
dom/media/MediaRecorder.cpp
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -1046,16 +1046,36 @@ MediaRecorder::Start(const Optional<int3
     return;
   }
 
   if (GetSourceMediaStream()->IsFinished() || GetSourceMediaStream()->IsDestroyed()) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
+  nsTArray<RefPtr<MediaStreamTrack>> tracks;
+  if (mDOMStream) {
+    mDOMStream->GetTracks(tracks);
+  }
+  if (!tracks.IsEmpty()) {
+    // If there are tracks already available that we're not allowed
+    // to record, we should throw a security error.
+    bool subsumes = false;
+    nsPIDOMWindowInner* window;
+    nsIDocument* doc;
+    if (!(window = GetOwner()) ||
+        !(doc = window->GetExtantDoc()) ||
+        NS_FAILED(doc->NodePrincipal()->Subsumes(
+                    mDOMStream->GetPrincipal(), &subsumes)) ||
+        !subsumes) {
+      aResult.Throw(NS_ERROR_DOM_SECURITY_ERR);
+      return;
+    }
+  }
+
   int32_t timeSlice = 0;
   if (aTimeSlice.WasPassed()) {
     if (aTimeSlice.Value() < 0) {
       aResult.Throw(NS_ERROR_INVALID_ARG);
       return;
     }
 
     timeSlice = aTimeSlice.Value();