Attachment #615924: CheckMayLoad changes to allow sandboxed workers to load blob and data URIs for bug #341604

View | Details | Raw Unified | Return to bug 341604
Collapse All | Expand All

(-)a/caps/idl/nsIPrincipal.idl (-2 / +12 lines)
Line     Link Here 
 Lines 206-238   interface nsIPrincipal : nsISerializable Link Here 
206
     */
206
     */
207
    boolean subsumesIgnoringDomain(in nsIPrincipal other);
207
    boolean subsumesIgnoringDomain(in nsIPrincipal other);
208
208
209
    /**
209
    /**
210
     * Checks whether this principal is allowed to load the network resource
210
     * Checks whether this principal is allowed to load the network resource
211
     * located at the given URI under the same-origin policy. This means that
211
     * located at the given URI under the same-origin policy. This means that
212
     * codebase principals are only allowed to load resources from the same
212
     * codebase principals are only allowed to load resources from the same
213
     * domain, the system principal is allowed to load anything, and null
213
     * domain, the system principal is allowed to load anything, and null
214
     * principals are not allowed to load anything.
214
     * principals are not allowed to load anything. This is changed slightly
215
     * by the optional flag allowIfInheritsPrincipal (which defaults to false)
216
     * which allows the load of a data: URI (which inherits the principal of
217
     * its loader) or a URI with the same principal as its loader (eg. a 
218
     * Blob URI).
219
     * In these cases, with allowIfInheritsPrincipal set to true, the URI can
220
     * be loaded by a null principal.
215
     *
221
     *
216
     * If the load is allowed this function does nothing. If the load is not
222
     * If the load is allowed this function does nothing. If the load is not
217
     * allowed the function throws NS_ERROR_DOM_BAD_URI.
223
     * allowed the function throws NS_ERROR_DOM_BAD_URI.
218
     *
224
     *
219
     * NOTE: Other policies might override this, such as the Access-Control
225
     * NOTE: Other policies might override this, such as the Access-Control
220
     *       specification.
226
     *       specification.
221
     * NOTE: The 'domain' attribute has no effect on the behaviour of this
227
     * NOTE: The 'domain' attribute has no effect on the behaviour of this
222
     *       function.
228
     *       function.
223
     *
229
     *
224
     *
230
     *
225
     * @param uri    The URI about to be loaded.
231
     * @param uri    The URI about to be loaded.
226
     * @param report If true, will report a warning to the console service
232
     * @param report If true, will report a warning to the console service
227
     *               if the load is not allowed.
233
     *               if the load is not allowed.
234
     * @param allowIfInheritsPrincipal   If true, the load is allowed if the
235
     *                                   loadee inherits the principal of the
236
     *                                   loader.
228
     * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
237
     * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
229
     */
238
     */
230
    void checkMayLoad(in nsIURI uri, in boolean report);
239
    void checkMayLoad(in nsIURI uri, in boolean report,
240
                      in boolean allowIfInheritsPrincipal);
231
241
232
    /**
242
    /**
233
     * The subject name for the certificate.  This actually identifies the
243
     * The subject name for the certificate.  This actually identifies the
234
     * subject of the certificate.  This may well not be a string that would
244
     * subject of the certificate.  This may well not be a string that would
235
     * mean much to a typical user on its own (e.g. it may have a number of
245
     * mean much to a typical user on its own (e.g. it may have a number of
236
     * different names all concatenated together with some information on what
246
     * different names all concatenated together with some information on what
237
     * they mean in between).
247
     * they mean in between).
238
     *
248
     *
(-)a/caps/src/nsNullPrincipal.cpp (-1 / +28 lines)
Line     Link Here 
 Lines 342-359   nsNullPrincipal::Subsumes(nsIPrincipal * Link Here 
342
342
343
NS_IMETHODIMP
343
NS_IMETHODIMP
344
nsNullPrincipal::SubsumesIgnoringDomain(nsIPrincipal *aOther, bool *aResult)
344
nsNullPrincipal::SubsumesIgnoringDomain(nsIPrincipal *aOther, bool *aResult)
345
{
345
{
346
  return Subsumes(aOther, aResult);
346
  return Subsumes(aOther, aResult);
347
}
347
}
348
348
349
NS_IMETHODIMP
349
NS_IMETHODIMP
350
nsNullPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport)
350
nsNullPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
351
{
351
{
352
  if (aAllowIfInheritsPrincipal) {
353
    // If the caller specified to allow loads of URIs that inherit
354
    // our (null) principal, allow the load if the loadee URI has
355
    // the URI_INHERITS_SECURITY_CONTEXT flag set.
356
    bool doesInheritSecurityContext;
357
    nsresult rv =
358
    NS_URIChainHasFlags(aURI,
359
                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
360
                        &doesInheritSecurityContext);
361
362
    if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) {
363
      return NS_OK;
364
    }
365
366
    // Also allow the load if the principal of the URI being checked is exactly
367
    // us ie this.
368
    nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
369
    if (uriPrinc) {
370
      nsCOMPtr<nsIPrincipal> principal;
371
      uriPrinc->GetPrincipal(getter_AddRefs(principal));
372
373
      if (principal && principal == this) {
374
        return NS_OK;
375
      }
376
    }
377
  }
378
352
  if (aReport) {
379
  if (aReport) {
353
    nsScriptSecurityManager::ReportError(
380
    nsScriptSecurityManager::ReportError(
354
      nsnull, NS_LITERAL_STRING("CheckSameOriginError"), mURI, aURI);
381
      nsnull, NS_LITERAL_STRING("CheckSameOriginError"), mURI, aURI);
355
  }
382
  }
356
383
357
  return NS_ERROR_DOM_BAD_URI;
384
  return NS_ERROR_DOM_BAD_URI;
358
}
385
}
359
386
(-)a/caps/src/nsPrincipal.cpp (-1 / +28 lines)
Line     Link Here 
 Lines 387-404   URIIsLocalFile(nsIURI *aURI) Link Here 
387
387
388
  return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
388
  return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
389
                                nsIProtocolHandler::URI_IS_LOCAL_FILE,
389
                                nsIProtocolHandler::URI_IS_LOCAL_FILE,
390
                                &isFile)) &&
390
                                &isFile)) &&
391
         isFile;
391
         isFile;
392
}
392
}
393
393
394
NS_IMETHODIMP
394
NS_IMETHODIMP
395
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport)
395
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
396
{
396
{
397
   if (aAllowIfInheritsPrincipal) {
398
    // If the caller specified to allow loads of URIs that inherit
399
    // our principal, allow the load if the loadee URI has
400
    // the URI_INHERITS_SECURITY_CONTEXT flag set.
401
    bool doesInheritSecurityContext;
402
    nsresult rv =
403
    NS_URIChainHasFlags(aURI,
404
                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
405
                        &doesInheritSecurityContext);
406
407
    if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) {
408
      return NS_OK;
409
    }
410
411
    // Also allow the load if the principal of the URI being checked is exactly
412
    // us ie this.
413
    nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
414
    if (uriPrinc) {
415
      nsCOMPtr<nsIPrincipal> principal;
416
      uriPrinc->GetPrincipal(getter_AddRefs(principal));
417
418
      if (principal && principal == this) {
419
        return NS_OK;
420
      }
421
    }
422
  }
423
397
  if (!nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
424
  if (!nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
398
    if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
425
    if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
399
        URIIsLocalFile(aURI)) {
426
        URIIsLocalFile(aURI)) {
400
      nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(aURI));
427
      nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(aURI));
401
428
402
      if (!URIIsLocalFile(mCodebase)) {
429
      if (!URIIsLocalFile(mCodebase)) {
403
        // If the codebase is not also a file: uri then forget it
430
        // If the codebase is not also a file: uri then forget it
404
        // (don't want resource: principals in a file: doc)
431
        // (don't want resource: principals in a file: doc)
(-)a/caps/src/nsScriptSecurityManager.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1492-1508   nsScriptSecurityManager::CheckLoadURIWit Link Here 
1492
    // Check for uris that are only loadable by principals that subsume them
1492
    // Check for uris that are only loadable by principals that subsume them
1493
    bool hasFlags;
1493
    bool hasFlags;
1494
    rv = NS_URIChainHasFlags(targetBaseURI,
1494
    rv = NS_URIChainHasFlags(targetBaseURI,
1495
                             nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS,
1495
                             nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS,
1496
                             &hasFlags);
1496
                             &hasFlags);
1497
    NS_ENSURE_SUCCESS(rv, rv);
1497
    NS_ENSURE_SUCCESS(rv, rv);
1498
1498
1499
    if (hasFlags) {
1499
    if (hasFlags) {
1500
        return aPrincipal->CheckMayLoad(targetBaseURI, true);
1500
        return aPrincipal->CheckMayLoad(targetBaseURI, true, false);
1501
    }
1501
    }
1502
1502
1503
    //-- get the source scheme
1503
    //-- get the source scheme
1504
    nsCAutoString sourceScheme;
1504
    nsCAutoString sourceScheme;
1505
    rv = sourceBaseURI->GetScheme(sourceScheme);
1505
    rv = sourceBaseURI->GetScheme(sourceScheme);
1506
    if (NS_FAILED(rv)) return rv;
1506
    if (NS_FAILED(rv)) return rv;
1507
1507
1508
    if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
1508
    if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
(-)a/caps/src/nsSystemPrincipal.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 141-157   nsSystemPrincipal::Subsumes(nsIPrincipal Link Here 
141
NS_IMETHODIMP
141
NS_IMETHODIMP
142
nsSystemPrincipal::SubsumesIgnoringDomain(nsIPrincipal *other, bool *result)
142
nsSystemPrincipal::SubsumesIgnoringDomain(nsIPrincipal *other, bool *result)
143
{
143
{
144
    *result = true;
144
    *result = true;
145
    return NS_OK;
145
    return NS_OK;
146
}
146
}
147
147
148
NS_IMETHODIMP
148
NS_IMETHODIMP
149
nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport)
149
nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
150
{
150
{
151
    return NS_OK;
151
    return NS_OK;
152
}
152
}
153
153
154
NS_IMETHODIMP
154
NS_IMETHODIMP
155
nsSystemPrincipal::GetHashValue(PRUint32 *result)
155
nsSystemPrincipal::GetHashValue(PRUint32 *result)
156
{
156
{
157
    *result = NS_PTR_TO_INT32(this);
157
    *result = NS_PTR_TO_INT32(this);
(-)a/content/base/src/nsContentSink.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1042-1058   nsContentSink::ProcessOfflineManifest(co Link Here 
1042
    nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(manifestURI),
1042
    nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(manifestURI),
1043
                                              aManifestSpec, mDocument,
1043
                                              aManifestSpec, mDocument,
1044
                                              mDocumentURI);
1044
                                              mDocumentURI);
1045
    if (!manifestURI) {
1045
    if (!manifestURI) {
1046
      return;
1046
      return;
1047
    }
1047
    }
1048
1048
1049
    // Documents must list a manifest from the same origin
1049
    // Documents must list a manifest from the same origin
1050
    rv = mDocument->NodePrincipal()->CheckMayLoad(manifestURI, true);
1050
    rv = mDocument->NodePrincipal()->CheckMayLoad(manifestURI, true, false);
1051
    if (NS_FAILED(rv)) {
1051
    if (NS_FAILED(rv)) {
1052
      action = CACHE_SELECTION_RESELECT_WITHOUT_MANIFEST;
1052
      action = CACHE_SELECTION_RESELECT_WITHOUT_MANIFEST;
1053
    }
1053
    }
1054
    else {
1054
    else {
1055
      // Only continue if the document has permission to use offline APIs.
1055
      // Only continue if the document has permission to use offline APIs.
1056
      if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
1056
      if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
1057
        return;
1057
        return;
1058
      }
1058
      }
(-)a/content/base/src/nsContentUtils.cpp (-5 / +5 lines)
Line     Link Here 
 Lines 4441-4457   nsContentUtils::CheckSecurityBeforeLoad( Link Here 
4441
4441
4442
  // Same Origin
4442
  // Same Origin
4443
  if ((aAllowData && SchemeIs(aURIToLoad, "data")) ||
4443
  if ((aAllowData && SchemeIs(aURIToLoad, "data")) ||
4444
      ((aCheckLoadFlags & nsIScriptSecurityManager::ALLOW_CHROME) &&
4444
      ((aCheckLoadFlags & nsIScriptSecurityManager::ALLOW_CHROME) &&
4445
       SchemeIs(aURIToLoad, "chrome"))) {
4445
       SchemeIs(aURIToLoad, "chrome"))) {
4446
    return NS_OK;
4446
    return NS_OK;
4447
  }
4447
  }
4448
4448
4449
  return aLoadingPrincipal->CheckMayLoad(aURIToLoad, true);
4449
  return aLoadingPrincipal->CheckMayLoad(aURIToLoad, true, false);
4450
}
4450
}
4451
4451
4452
bool
4452
bool
4453
nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
4453
nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
4454
{
4454
{
4455
  bool isSystem;
4455
  bool isSystem;
4456
  nsresult rv = sSecurityManager->IsSystemPrincipal(aPrincipal, &isSystem);
4456
  nsresult rv = sSecurityManager->IsSystemPrincipal(aPrincipal, &isSystem);
4457
  return NS_SUCCEEDED(rv) && isSystem;
4457
  return NS_SUCCEEDED(rv) && isSystem;
 Lines 5543-5561   nsContentUtils::CheckSameOrigin(nsIChann Link Here 
5543
5543
5544
  nsCOMPtr<nsIURI> newURI;
5544
  nsCOMPtr<nsIURI> newURI;
5545
  aNewChannel->GetURI(getter_AddRefs(newURI));
5545
  aNewChannel->GetURI(getter_AddRefs(newURI));
5546
  nsCOMPtr<nsIURI> newOriginalURI;
5546
  nsCOMPtr<nsIURI> newOriginalURI;
5547
  aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
5547
  aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
5548
5548
5549
  NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
5549
  NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
5550
5550
5551
  nsresult rv = oldPrincipal->CheckMayLoad(newURI, false);
5551
  nsresult rv = oldPrincipal->CheckMayLoad(newURI, false, false);
5552
  if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
5552
  if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
5553
    rv = oldPrincipal->CheckMayLoad(newOriginalURI, false);
5553
    rv = oldPrincipal->CheckMayLoad(newOriginalURI, false, false);
5554
  }
5554
  }
5555
5555
5556
  return rv;
5556
  return rv;
5557
}
5557
}
5558
5558
5559
NS_IMPL_ISUPPORTS2(nsSameOriginChecker,
5559
NS_IMPL_ISUPPORTS2(nsSameOriginChecker,
5560
                   nsIChannelEventSink,
5560
                   nsIChannelEventSink,
5561
                   nsIInterfaceRequestor)
5561
                   nsIInterfaceRequestor)
 Lines 5722-5738   nsContentUtils::GetDocumentFromScriptCon Link Here 
5722
/* static */
5722
/* static */
5723
bool
5723
bool
5724
nsContentUtils::CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel)
5724
nsContentUtils::CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel)
5725
{
5725
{
5726
  nsCOMPtr<nsIURI> channelURI;
5726
  nsCOMPtr<nsIURI> channelURI;
5727
  nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
5727
  nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
5728
  NS_ENSURE_SUCCESS(rv, false);
5728
  NS_ENSURE_SUCCESS(rv, false);
5729
5729
5730
  return NS_SUCCEEDED(aPrincipal->CheckMayLoad(channelURI, false));
5730
  return NS_SUCCEEDED(aPrincipal->CheckMayLoad(channelURI, false, false));
5731
}
5731
}
5732
5732
5733
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
5733
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
5734
  : mString(aString), mService(nsnull)
5734
  : mString(aString), mService(nsnull)
5735
{
5735
{
5736
  CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
5736
  CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
5737
}
5737
}
5738
5738
 Lines 6471-6487   nsContentUtils::SetUpChannelOwner(nsIPri Link Here 
6471
  // file: uri special-casing
6471
  // file: uri special-casing
6472
  //
6472
  //
6473
  // If this is a file: load opened from another file: then it may need
6473
  // If this is a file: load opened from another file: then it may need
6474
  // to inherit the owner from the referrer so they can script each other.
6474
  // to inherit the owner from the referrer so they can script each other.
6475
  // If we don't set the owner explicitly then each file: gets an owner
6475
  // If we don't set the owner explicitly then each file: gets an owner
6476
  // based on its own codebase later.
6476
  // based on its own codebase later.
6477
  //
6477
  //
6478
  if (URIIsLocalFile(aURI) && aLoadingPrincipal &&
6478
  if (URIIsLocalFile(aURI) && aLoadingPrincipal &&
6479
      NS_SUCCEEDED(aLoadingPrincipal->CheckMayLoad(aURI, false)) &&
6479
      NS_SUCCEEDED(aLoadingPrincipal->CheckMayLoad(aURI, false, false)) &&
6480
      // One more check here.  CheckMayLoad will always return true for the
6480
      // One more check here.  CheckMayLoad will always return true for the
6481
      // system principal, but we do NOT want to inherit in that case.
6481
      // system principal, but we do NOT want to inherit in that case.
6482
      !IsSystemPrincipal(aLoadingPrincipal)) {
6482
      !IsSystemPrincipal(aLoadingPrincipal)) {
6483
    aChannel->SetOwner(aLoadingPrincipal);
6483
    aChannel->SetOwner(aLoadingPrincipal);
6484
    return true;
6484
    return true;
6485
  }
6485
  }
6486
6486
6487
  return false;
6487
  return false;
(-)a/content/base/src/nsCrossSiteListenerProxy.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 770-789   nsCORSListenerProxy::UpdateChannel(nsICh Link Here 
770
  if (originalURI != uri) {
770
  if (originalURI != uri) {
771
    rv = nsContentUtils::GetSecurityManager()->
771
    rv = nsContentUtils::GetSecurityManager()->
772
      CheckLoadURIWithPrincipal(mRequestingPrincipal, originalURI,
772
      CheckLoadURIWithPrincipal(mRequestingPrincipal, originalURI,
773
                                nsIScriptSecurityManager::STANDARD);
773
                                nsIScriptSecurityManager::STANDARD);
774
    NS_ENSURE_SUCCESS(rv, rv);
774
    NS_ENSURE_SUCCESS(rv, rv);
775
  }
775
  }
776
776
777
  if (!mHasBeenCrossSite &&
777
  if (!mHasBeenCrossSite &&
778
      NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(uri, false)) &&
778
      NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(uri, false, false)) &&
779
      (originalURI == uri ||
779
      (originalURI == uri ||
780
       NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(originalURI,
780
       NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(originalURI,
781
                                                       false)))) {
781
                                                       false, false)))) {
782
    return NS_OK;
782
    return NS_OK;
783
  }
783
  }
784
784
785
  // It's a cross site load
785
  // It's a cross site load
786
  mHasBeenCrossSite = true;
786
  mHasBeenCrossSite = true;
787
787
788
  nsCString userpass;
788
  nsCString userpass;
789
  uri->GetUserPass(userpass);
789
  uri->GetUserPass(userpass);
(-)a/content/base/src/nsDocument.cpp (-10 / +7 lines)
Line     Link Here 
 Lines 1100-1127   nsExternalResourceMap::PendingLoad::Star Link Here 
1100
1100
1101
  nsIPrincipal* requestingPrincipal = aRequestingNode->NodePrincipal();
1101
  nsIPrincipal* requestingPrincipal = aRequestingNode->NodePrincipal();
1102
1102
1103
  nsresult rv = nsContentUtils::GetSecurityManager()->
1103
  nsresult rv = nsContentUtils::GetSecurityManager()->
1104
    CheckLoadURIWithPrincipal(requestingPrincipal, aURI,
1104
    CheckLoadURIWithPrincipal(requestingPrincipal, aURI,
1105
                              nsIScriptSecurityManager::STANDARD);
1105
                              nsIScriptSecurityManager::STANDARD);
1106
  NS_ENSURE_SUCCESS(rv, rv);
1106
  NS_ENSURE_SUCCESS(rv, rv);
1107
  
1107
  
1108
  // Allow data URIs (let them skip the CheckMayLoad call), since we want
1108
  // Allow data URIs and other URI's that inherit their principal by passing
1109
  // true as the 3rd argument of CheckMayLoad, since we want
1109
  // to allow external resources from data URIs regardless of the difference
1110
  // to allow external resources from data URIs regardless of the difference
1110
  // in URI scheme.
1111
  // in URI scheme.
1111
  bool doesInheritSecurityContext;
1112
1112
  rv =
1113
  // REVIEW : is it really ok to allow javascript: URI's here ??
1113
    NS_URIChainHasFlags(aURI,
1114
1114
                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1115
  rv = requestingPrincipal->CheckMayLoad(aURI, true, true);
1115
                        &doesInheritSecurityContext);
1116
  NS_ENSURE_SUCCESS(rv, rv);
1116
  if (NS_FAILED(rv) || !doesInheritSecurityContext) {
1117
    rv = requestingPrincipal->CheckMayLoad(aURI, true);
1118
    NS_ENSURE_SUCCESS(rv, rv);
1119
  }
1120
1117
1121
  PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
1118
  PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
1122
  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER,
1119
  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER,
1123
                                 aURI,
1120
                                 aURI,
1124
                                 requestingPrincipal,
1121
                                 requestingPrincipal,
1125
                                 aRequestingNode,
1122
                                 aRequestingNode,
1126
                                 EmptyCString(), //mime guess
1123
                                 EmptyCString(), //mime guess
1127
                                 nsnull,         //extra
1124
                                 nsnull,         //extra
(-)a/content/base/src/nsXMLHttpRequest.cpp (+8 lines)
Line     Link Here 
 Lines 1744-1759   nsXMLHttpRequest::CheckChannelForCrossSi Link Here 
1744
    return NS_OK;
1744
    return NS_OK;
1745
  }
1745
  }
1746
1746
1747
  // ...or if this is a same-origin request.
1747
  // ...or if this is a same-origin request.
1748
  if (nsContentUtils::CheckMayLoad(mPrincipal, aChannel)) {
1748
  if (nsContentUtils::CheckMayLoad(mPrincipal, aChannel)) {
1749
    return NS_OK;
1749
    return NS_OK;
1750
  }
1750
  }
1751
1751
1752
  // REVIEW: since the check above is on the channel and the one
1753
  // below is on the final channel URI, I'm not sure we want to
1754
  // pass true for aAllowIfInheritsPrincipal to CheckMayLoad above
1755
  // the below could be replaced with a call to CheckMayLoad for
1756
  // channelURI passing true for aAllowIfInheritsPrincipal though,
1757
  // if we wanted to allow other URI's that inherit the principal of
1758
  // their creator as well as data URIs.
1759
1752
  // exempt data URIs from the same origin check.
1760
  // exempt data URIs from the same origin check.
1753
  nsCOMPtr<nsIURI> channelURI;
1761
  nsCOMPtr<nsIURI> channelURI;
1754
  bool dataScheme = false;
1762
  bool dataScheme = false;
1755
  if (NS_SUCCEEDED(NS_GetFinalChannelURI(aChannel,
1763
  if (NS_SUCCEEDED(NS_GetFinalChannelURI(aChannel,
1756
                                         getter_AddRefs(channelURI))) &&
1764
                                         getter_AddRefs(channelURI))) &&
1757
      NS_SUCCEEDED(channelURI->SchemeIs("data", &dataScheme)) &&
1765
      NS_SUCCEEDED(channelURI->SchemeIs("data", &dataScheme)) &&
1758
      dataScheme) {
1766
      dataScheme) {
1759
    return NS_OK;
1767
    return NS_OK;
(-)a/content/xbl/src/nsXBLService.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 977-993   nsXBLService::LoadBindingDocumentInfo(ns Link Here 
977
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
977
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
978
978
979
    if (!IsSystemOrChromeURLPrincipal(aOriginPrincipal)) {
979
    if (!IsSystemOrChromeURLPrincipal(aOriginPrincipal)) {
980
      // Also make sure that we're same-origin with the bound document
980
      // Also make sure that we're same-origin with the bound document
981
      // except if the stylesheet has the system principal.
981
      // except if the stylesheet has the system principal.
982
      if (!(gAllowDataURIs && SchemeIs(aBindingURI, "data")) &&
982
      if (!(gAllowDataURIs && SchemeIs(aBindingURI, "data")) &&
983
          !SchemeIs(aBindingURI, "chrome")) {
983
          !SchemeIs(aBindingURI, "chrome")) {
984
        rv = aBoundDocument->NodePrincipal()->CheckMayLoad(aBindingURI,
984
        rv = aBoundDocument->NodePrincipal()->CheckMayLoad(aBindingURI,
985
                                                           true);
985
                                                           true, false);
986
        NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
986
        NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
987
      }
987
      }
988
988
989
      // Finally check if this document is allowed to use XBL at all.
989
      // Finally check if this document is allowed to use XBL at all.
990
      NS_ENSURE_TRUE(aBoundDocument->AllowXULXBL(),
990
      NS_ENSURE_TRUE(aBoundDocument->AllowXULXBL(),
991
                     NS_ERROR_XBL_BLOCKED);
991
                     NS_ERROR_XBL_BLOCKED);
992
    }
992
    }
993
  }
993
  }
(-)a/content/xml/document/src/nsXMLDocument.cpp (-1 / +5 lines)
Line     Link Here 
 Lines 362-378   nsXMLDocument::Load(const nsAString& aUr Link Here 
362
  // that we don't end up in a case where code with elevated privileges is
362
  // that we don't end up in a case where code with elevated privileges is
363
  // calling us and changing the principal of this document.
363
  // calling us and changing the principal of this document.
364
364
365
  // Enforce same-origin even for chrome loaders to avoid someone accidentally
365
  // Enforce same-origin even for chrome loaders to avoid someone accidentally
366
  // using a document that content has a reference to and turn that into a
366
  // using a document that content has a reference to and turn that into a
367
  // chrome document.
367
  // chrome document.
368
  nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
368
  nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
369
  if (!nsContentUtils::IsSystemPrincipal(principal)) {
369
  if (!nsContentUtils::IsSystemPrincipal(principal)) {
370
    rv = principal->CheckMayLoad(uri, false);
370
    // REVIEW : it might be desirable to pass true as the
371
    // 3rd param here and allow loading of URIs that inherit
372
    // the principal of their creator. Not sure about javascript:
373
    // though.
374
    rv = principal->CheckMayLoad(uri, false, false);
371
    NS_ENSURE_SUCCESS(rv, rv);
375
    NS_ENSURE_SUCCESS(rv, rv);
372
376
373
    PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
377
    PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
374
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
378
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
375
                                   uri,
379
                                   uri,
376
                                   principal,
380
                                   principal,
377
                                   callingDoc ? callingDoc.get() :
381
                                   callingDoc ? callingDoc.get() :
378
                                     static_cast<nsIDocument*>(this),
382
                                     static_cast<nsIDocument*>(this),
(-)a/content/xul/document/src/nsXULDocument.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 2700-2716   nsXULDocument::LoadOverlayInternal(nsIUR Link Here 
2700
2700
2701
    // Chrome documents are allowed to load overlays from anywhere.
2701
    // Chrome documents are allowed to load overlays from anywhere.
2702
    // In all other cases, the overlay is only allowed to load if
2702
    // In all other cases, the overlay is only allowed to load if
2703
    // the master document and prototype document have the same origin.
2703
    // the master document and prototype document have the same origin.
2704
2704
2705
    bool documentIsChrome = IsChromeURI(mDocumentURI);
2705
    bool documentIsChrome = IsChromeURI(mDocumentURI);
2706
    if (!documentIsChrome) {
2706
    if (!documentIsChrome) {
2707
        // Make sure we're allowed to load this overlay.
2707
        // Make sure we're allowed to load this overlay.
2708
        rv = NodePrincipal()->CheckMayLoad(aURI, true);
2708
        rv = NodePrincipal()->CheckMayLoad(aURI, true, false);
2709
        if (NS_FAILED(rv)) {
2709
        if (NS_FAILED(rv)) {
2710
            *aFailureFromContent = true;
2710
            *aFailureFromContent = true;
2711
            return rv;
2711
            return rv;
2712
        }
2712
        }
2713
    }
2713
    }
2714
2714
2715
    // Look in the prototype cache for the prototype document with
2715
    // Look in the prototype cache for the prototype document with
2716
    // the specified overlay URI. Only use the cache if the containing
2716
    // the specified overlay URI. Only use the cache if the containing
(-)a/content/xul/templates/src/nsXULTemplateBuilder.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1372-1388   nsXULTemplateBuilder::LoadDataSourceUrls Link Here 
1372
1372
1373
        nsCOMPtr<nsIURI> uri;
1373
        nsCOMPtr<nsIURI> uri;
1374
        rv = NS_NewURI(getter_AddRefs(uri), uriStr);
1374
        rv = NS_NewURI(getter_AddRefs(uri), uriStr);
1375
        if (NS_FAILED(rv) || !uri)
1375
        if (NS_FAILED(rv) || !uri)
1376
            continue; // Necko will barf if our URI is weird
1376
            continue; // Necko will barf if our URI is weird
1377
1377
1378
        // don't add the uri to the list if the document is not allowed to
1378
        // don't add the uri to the list if the document is not allowed to
1379
        // load it
1379
        // load it
1380
        if (!isTrusted && NS_FAILED(docPrincipal->CheckMayLoad(uri, true)))
1380
        if (!isTrusted && NS_FAILED(docPrincipal->CheckMayLoad(uri, true, false)))
1381
          continue;
1381
          continue;
1382
1382
1383
        uriList->AppendElement(uri, false);
1383
        uriList->AppendElement(uri, false);
1384
    }
1384
    }
1385
1385
1386
    nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(mRoot);
1386
    nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(mRoot);
1387
    rv = mQueryProcessor->GetDatasource(uriList,
1387
    rv = mQueryProcessor->GetDatasource(uriList,
1388
                                        rootNode,
1388
                                        rootNode,
(-)a/docshell/base/nsDocShell.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 9809-9825   nsDocShell::AddState(nsIVariant *aData, Link Here 
9809
9809
9810
            if (!docScriptObj) {
9810
            if (!docScriptObj) {
9811
                return NS_ERROR_DOM_SECURITY_ERR;
9811
                return NS_ERROR_DOM_SECURITY_ERR;
9812
            }
9812
            }
9813
9813
9814
            nsCOMPtr<nsIPrincipal> principal = docScriptObj->GetPrincipal();
9814
            nsCOMPtr<nsIPrincipal> principal = docScriptObj->GetPrincipal();
9815
9815
9816
            if (!principal ||
9816
            if (!principal ||
9817
                NS_FAILED(principal->CheckMayLoad(newURI, true))) {
9817
                NS_FAILED(principal->CheckMayLoad(newURI, true, false))) {
9818
9818
9819
                return NS_ERROR_DOM_SECURITY_ERR;
9819
                return NS_ERROR_DOM_SECURITY_ERR;
9820
            }
9820
            }
9821
        }
9821
        }
9822
9822
9823
        mCurrentURI->Equals(newURI, &equalURIs);
9823
        mCurrentURI->Equals(newURI, &equalURIs);
9824
9824
9825
    } // end of same-origin check
9825
    } // end of same-origin check
(-)a/dom/workers/ScriptLoader.cpp (-8 / +9 lines)
Line     Link Here 
 Lines 329-349   public: Link Here 
329
      // If this script loader is being used to make a new worker then we need
329
      // If this script loader is being used to make a new worker then we need
330
      // to do a same-origin check. Otherwise we need to clear the load with the
330
      // to do a same-origin check. Otherwise we need to clear the load with the
331
      // security manager.
331
      // security manager.
332
      if (mIsWorkerScript) {
332
      if (mIsWorkerScript) {
333
        nsCString scheme;
333
        nsCString scheme;
334
        rv = uri->GetScheme(scheme);
334
        rv = uri->GetScheme(scheme);
335
        NS_ENSURE_SUCCESS(rv, rv);
335
        NS_ENSURE_SUCCESS(rv, rv);
336
336
337
        // We exempt data URLs from the same origin check.
337
        // We pass true as the 3rd argument to checkMayLoad here.
338
        if (!scheme.EqualsLiteral("data")) {
338
        // This allows workers in sandboxed documents to load data URLs
339
          rv = principal->CheckMayLoad(uri, false);
339
        // (and other URLs that inherit their principal from their
340
          NS_ENSURE_SUCCESS(rv, rv);
340
        // creator.)
341
        }
341
        rv = principal->CheckMayLoad(uri, false, true);
342
        NS_ENSURE_SUCCESS(rv, rv);
342
      }
343
      }
343
      else {
344
      else {
344
        rv = secMan->CheckLoadURIWithPrincipal(principal, uri, 0);
345
        rv = secMan->CheckLoadURIWithPrincipal(principal, uri, 0);
345
        NS_ENSURE_SUCCESS(rv, rv);
346
        NS_ENSURE_SUCCESS(rv, rv);
346
      }
347
      }
347
348
348
      // We need to know which index we're on in OnStreamComplete so we know
349
      // We need to know which index we're on in OnStreamComplete so we know
349
      // where to put the result.
350
      // where to put the result.
 Lines 516-534   public: Link Here 
516
          return NS_ERROR_DOM_BAD_URI;
517
          return NS_ERROR_DOM_BAD_URI;
517
        }
518
        }
518
      }
519
      }
519
      else  {
520
      else  {
520
        nsCString scheme;
521
        nsCString scheme;
521
        rv = finalURI->GetScheme(scheme);
522
        rv = finalURI->GetScheme(scheme);
522
        NS_ENSURE_SUCCESS(rv, rv);
523
        NS_ENSURE_SUCCESS(rv, rv);
523
524
524
        // We exempt data urls again.
525
        // We exempt data urls and other URI's that inherit their
525
        if (!scheme.EqualsLiteral("data") &&
526
        // principal again.
526
            NS_FAILED(loadPrincipal->CheckMayLoad(finalURI, false))) {
527
        if (NS_FAILED(loadPrincipal->CheckMayLoad(finalURI, false, true))) {
527
          return NS_ERROR_DOM_BAD_URI;
528
          return NS_ERROR_DOM_BAD_URI;
528
        }
529
        }
529
      }
530
      }
530
531
531
      mWorkerPrivate->SetPrincipal(channelPrincipal);
532
      mWorkerPrivate->SetPrincipal(channelPrincipal);
532
    }
533
    }
533
534
534
    return NS_OK;
535
    return NS_OK;
(-)a/layout/style/Loader.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1568-1584   Loader::LoadSheet(SheetLoadData* aLoadDa Link Here 
1568
  if (aLoadData->mLoaderPrincipal) {
1568
  if (aLoadData->mLoaderPrincipal) {
1569
    bool inherit;
1569
    bool inherit;
1570
    rv = NS_URIChainHasFlags(aLoadData->mURI,
1570
    rv = NS_URIChainHasFlags(aLoadData->mURI,
1571
                             nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1571
                             nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1572
                             &inherit);
1572
                             &inherit);
1573
    if ((NS_SUCCEEDED(rv) && inherit) ||
1573
    if ((NS_SUCCEEDED(rv) && inherit) ||
1574
        (nsContentUtils::URIIsLocalFile(aLoadData->mURI) &&
1574
        (nsContentUtils::URIIsLocalFile(aLoadData->mURI) &&
1575
         NS_SUCCEEDED(aLoadData->mLoaderPrincipal->
1575
         NS_SUCCEEDED(aLoadData->mLoaderPrincipal->
1576
                      CheckMayLoad(aLoadData->mURI, false)))) {
1576
                      CheckMayLoad(aLoadData->mURI, false, false)))) {
1577
      channel->SetOwner(aLoadData->mLoaderPrincipal);
1577
      channel->SetOwner(aLoadData->mLoaderPrincipal);
1578
    }
1578
    }
1579
  }
1579
  }
1580
1580
1581
  // We don't have to hold on to the stream loader.  The ownership
1581
  // We don't have to hold on to the stream loader.  The ownership
1582
  // model is: Necko owns the stream loader, which owns the load data,
1582
  // model is: Necko owns the stream loader, which owns the load data,
1583
  // which owns us
1583
  // which owns us
1584
  nsCOMPtr<nsIUnicharStreamLoader> streamLoader;
1584
  nsCOMPtr<nsIUnicharStreamLoader> streamLoader;
(-)a/rdf/base/src/nsRDFXMLDataSource.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 915-933   RDFXMLDataSourceImpl::AsyncOnChannelRedi Link Here 
915
915
916
    nsCOMPtr<nsIURI> newURI;
916
    nsCOMPtr<nsIURI> newURI;
917
    aNewChannel->GetURI(getter_AddRefs(newURI));
917
    aNewChannel->GetURI(getter_AddRefs(newURI));
918
    nsCOMPtr<nsIURI> newOriginalURI;
918
    nsCOMPtr<nsIURI> newOriginalURI;
919
    aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
919
    aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
920
920
921
    NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
921
    NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
922
922
923
    rv = oldPrincipal->CheckMayLoad(newURI, false);
923
    rv = oldPrincipal->CheckMayLoad(newURI, false, false);
924
    if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
924
    if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
925
        rv = oldPrincipal->CheckMayLoad(newOriginalURI, false);
925
        rv = oldPrincipal->CheckMayLoad(newOriginalURI, false, false);
926
    }
926
    }
927
927
928
    if (NS_FAILED(rv))
928
    if (NS_FAILED(rv))
929
        return rv;
929
        return rv;
930
930
931
    cb->OnRedirectVerifyCallback(NS_OK);
931
    cb->OnRedirectVerifyCallback(NS_OK);
932
    return NS_OK;
932
    return NS_OK;
933
}
933
}

Return to bug 341604