Commit c5245600 authored by Arthur Edelstein's avatar Arthur Edelstein Committed by Georg Koppen
Browse files

Bug 20043: Isolate SharedWorker script requests to first party

parent 94102f06
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -4396,6 +4396,25 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow,
                                        getter_AddRefs(loadInfo.mChannel));
    NS_ENSURE_SUCCESS(rv, rv);

    // If this is a SharedWorker and we have an isolation key, use it as the
    // DocumentURI for this channel. Ensures we get the right first-party domain.
    if ((aWorkerType == WorkerTypeShared || aWorkerType == WorkerTypeService) &&
        !loadInfo.mIsolationKey.IsEmpty()) {
      nsCOMPtr<nsIHttpChannelInternal> channelInternal(do_QueryInterface(loadInfo.mChannel));
      if (channelInternal) {
        nsCString documentURISpec("https://");
        documentURISpec.Append(loadInfo.mIsolationKey);
        nsCOMPtr<nsIURI> documentURI;
        nsresult rv = NS_NewURI(getter_AddRefs(documentURI), documentURISpec);
        if (NS_SUCCEEDED(rv)) {
          channelInternal->SetDocumentURI(documentURI);
        } else {
          NS_WARNING("Unable to set the documentURI for SharedWorker's "
                     "loading channel.");
        }
      }
    }

    rv = NS_GetFinalChannelURI(loadInfo.mChannel,
                               getter_AddRefs(loadInfo.mResolvedScriptURI));
    NS_ENSURE_SUCCESS(rv, rv);