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

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

(-)a/caps/idl/nsIPrincipal.idl (-4 / +14 lines)
Line     Link Here 
 Lines 16-32   struct JSPrincipals; Link Here 
16
16
17
interface nsIURI;
17
interface nsIURI;
18
interface nsIContentSecurityPolicy;
18
interface nsIContentSecurityPolicy;
19
19
20
[ptr] native JSContext(JSContext);
20
[ptr] native JSContext(JSContext);
21
[ptr] native JSPrincipals(JSPrincipals);
21
[ptr] native JSPrincipals(JSPrincipals);
22
[ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
22
[ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
23
23
24
[scriptable, uuid(42ba6a38-d619-49ab-8248-3d247e959d5e)]
24
[scriptable, uuid(825ffce8-962d-11e1-aef3-8f2b6188709b)]
25
interface nsIPrincipal : nsISerializable
25
interface nsIPrincipal : nsISerializable
26
{
26
{
27
    /**
27
    /**
28
     * Values of capabilities for each principal. Order is
28
     * Values of capabilities for each principal. Order is
29
     * significant: if an operation is performed on a set
29
     * significant: if an operation is performed on a set
30
     * of capabilities, the minimum is computed.
30
     * of capabilities, the minimum is computed.
31
     */
31
     */
32
    const short ENABLE_DENIED                = 1;
32
    const short ENABLE_DENIED                = 1;
 Lines 168-200   interface nsIPrincipal : nsISerializable Link Here 
168
     */
168
     */
169
    boolean subsumesIgnoringDomain(in nsIPrincipal other);
169
    boolean subsumesIgnoringDomain(in nsIPrincipal other);
170
170
171
    /**
171
    /**
172
     * Checks whether this principal is allowed to load the network resource
172
     * Checks whether this principal is allowed to load the network resource
173
     * located at the given URI under the same-origin policy. This means that
173
     * located at the given URI under the same-origin policy. This means that
174
     * codebase principals are only allowed to load resources from the same
174
     * codebase principals are only allowed to load resources from the same
175
     * domain, the system principal is allowed to load anything, and null
175
     * domain, the system principal is allowed to load anything, and null
176
     * principals are not allowed to load anything.
176
     * principals are not allowed to load anything. This is changed slightly
177
     * by the optional flag allowIfInheritsPrincipal (which defaults to false)
178
     * which allows the load of a data: URI (which inherits the principal of
179
     * its loader) or a URI with the same principal as its loader (eg. a 
180
     * Blob URI).
181
     * In these cases, with allowIfInheritsPrincipal set to true, the URI can
182
     * be loaded by a null principal.
177
     *
183
     *
178
     * If the load is allowed this function does nothing. If the load is not
184
     * If the load is allowed this function does nothing. If the load is not
179
     * allowed the function throws NS_ERROR_DOM_BAD_URI.
185
     * allowed the function throws NS_ERROR_DOM_BAD_URI.
180
     *
186
     *
181
     * NOTE: Other policies might override this, such as the Access-Control
187
     * NOTE: Other policies might override this, such as the Access-Control
182
     *       specification.
188
     *       specification.
183
     * NOTE: The 'domain' attribute has no effect on the behaviour of this
189
     * NOTE: The 'domain' attribute has no effect on the behaviour of this
184
     *       function.
190
     *       function.
185
     *
191
     *
186
     *
192
     *
187
     * @param uri    The URI about to be loaded.
193
     * @param uri    The URI about to be loaded.
188
     * @param report If true, will report a warning to the console service
194
     * @param report If true, will report a warning to the console service
189
     *               if the load is not allowed.
195
     *               if the load is not allowed.
196
     * @param allowIfInheritsPrincipal   If true, the load is allowed if the
197
     *                                   loadee inherits the principal of the
198
     *                                   loader.
190
     * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
199
     * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
191
     */
200
     */
192
    void checkMayLoad(in nsIURI uri, in boolean report);
201
    void checkMayLoad(in nsIURI uri, in boolean report,
202
                      in boolean allowIfInheritsPrincipal);
193
203
194
    /**
204
    /**
195
     * The subject name for the certificate.  This actually identifies the
205
     * The subject name for the certificate.  This actually identifies the
196
     * subject of the certificate.  This may well not be a string that would
206
     * subject of the certificate.  This may well not be a string that would
197
     * mean much to a typical user on its own (e.g. it may have a number of
207
     * mean much to a typical user on its own (e.g. it may have a number of
198
     * different names all concatenated together with some information on what
208
     * different names all concatenated together with some information on what
199
     * they mean in between).
209
     * they mean in between).
200
     *
210
     *
 Lines 229-237   interface nsIPrincipal : nsISerializable Link Here 
229
interface nsIExpandedPrincipal : nsISupports
239
interface nsIExpandedPrincipal : nsISupports
230
{
240
{
231
  /**
241
  /**
232
   * An array of principals that the expanded principal subsumes.
242
   * An array of principals that the expanded principal subsumes.
233
   * Note: this list is not reference counted, it is shared, so 
243
   * Note: this list is not reference counted, it is shared, so 
234
   * should not be changed and should only be used ephemerally.
244
   * should not be changed and should only be used ephemerally.
235
   */
245
   */
236
  [notxpcom] readonly attribute PrincipalArray whiteList;
246
  [notxpcom] readonly attribute PrincipalArray whiteList;
237
};
247
};
(-)a/caps/include/nsNullPrincipal.h (+1 lines)
Line     Link Here 
 Lines 10-25    Link Here 
10
 */
10
 */
11
11
12
#ifndef nsNullPrincipal_h__
12
#ifndef nsNullPrincipal_h__
13
#define nsNullPrincipal_h__
13
#define nsNullPrincipal_h__
14
14
15
#include "nsIPrincipal.h"
15
#include "nsIPrincipal.h"
16
#include "nsJSPrincipals.h"
16
#include "nsJSPrincipals.h"
17
#include "nsCOMPtr.h"
17
#include "nsCOMPtr.h"
18
#include "nsPrincipal.h"
18
19
19
class nsIURI;
20
class nsIURI;
20
21
21
#define NS_NULLPRINCIPAL_CLASSNAME "nullprincipal"
22
#define NS_NULLPRINCIPAL_CLASSNAME "nullprincipal"
22
#define NS_NULLPRINCIPAL_CID \
23
#define NS_NULLPRINCIPAL_CID \
23
{ 0xdd156d62, 0xd26f, 0x4441, \
24
{ 0xdd156d62, 0xd26f, 0x4441, \
24
 { 0x9c, 0xdb, 0xe8, 0xf0, 0x91, 0x07, 0xc2, 0x73 } }
25
 { 0x9c, 0xdb, 0xe8, 0xf0, 0x91, 0x07, 0xc2, 0x73 } }
25
#define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
26
#define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
(-)a/caps/include/nsPrincipal.h (-2 / +21 lines)
Line     Link Here 
 Lines 8-23    Link Here 
8
8
9
#include "nsAutoPtr.h"
9
#include "nsAutoPtr.h"
10
#include "nsCOMPtr.h"
10
#include "nsCOMPtr.h"
11
#include "nsVoidArray.h"
11
#include "nsVoidArray.h"
12
#include "nsHashtable.h"
12
#include "nsHashtable.h"
13
#include "nsJSPrincipals.h"
13
#include "nsJSPrincipals.h"
14
#include "nsTArray.h"
14
#include "nsTArray.h"
15
#include "nsAutoPtr.h"
15
#include "nsAutoPtr.h"
16
#include "nsIProtocolHandler.h"
17
#include "nsNetUtil.h"
18
#include "nsScriptSecurityManager.h"
16
19
17
class nsIObjectInputStream;
20
class nsIObjectInputStream;
18
class nsIObjectOutputStream;
21
class nsIObjectOutputStream;
19
class DomainPolicy; 
22
class DomainPolicy; 
20
23
21
class nsBasePrincipal : public nsJSPrincipals
24
class nsBasePrincipal : public nsJSPrincipals
22
{
25
{
23
public:
26
public:
 Lines 124-140   public: Link Here 
124
  NS_IMETHOD EqualsIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
127
  NS_IMETHOD EqualsIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
125
  NS_IMETHOD GetHashValue(PRUint32* aHashValue);
128
  NS_IMETHOD GetHashValue(PRUint32* aHashValue);
126
  NS_IMETHOD GetURI(nsIURI** aURI);
129
  NS_IMETHOD GetURI(nsIURI** aURI);
127
  NS_IMETHOD GetDomain(nsIURI** aDomain);
130
  NS_IMETHOD GetDomain(nsIURI** aDomain);
128
  NS_IMETHOD SetDomain(nsIURI* aDomain);
131
  NS_IMETHOD SetDomain(nsIURI* aDomain);
129
  NS_IMETHOD GetOrigin(char** aOrigin);
132
  NS_IMETHOD GetOrigin(char** aOrigin);
130
  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
133
  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
131
  NS_IMETHOD SubsumesIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
134
  NS_IMETHOD SubsumesIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
132
  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report);
135
  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal);
133
#ifdef DEBUG
136
#ifdef DEBUG
134
  virtual void dumpImpl();
137
  virtual void dumpImpl();
135
#endif
138
#endif
136
  // Either Init() or InitFromPersistent() must be called before
139
  // Either Init() or InitFromPersistent() must be called before
137
  // the principal is in a usable state.
140
  // the principal is in a usable state.
138
  nsresult Init(const nsACString& aCertFingerprint,
141
  nsresult Init(const nsACString& aCertFingerprint,
139
                const nsACString& aSubjectName,
142
                const nsACString& aSubjectName,
140
                const nsACString& aPrettyName,
143
                const nsACString& aPrettyName,
 Lines 148-163   public: Link Here 
148
                              const char* aDeniedList,
151
                              const char* aDeniedList,
149
                              nsISupports* aCert,
152
                              nsISupports* aCert,
150
                              bool aIsCert,
153
                              bool aIsCert,
151
                              bool aTrusted);
154
                              bool aTrusted);
152
155
153
  virtual void GetScriptLocation(nsACString& aStr) MOZ_OVERRIDE;
156
  virtual void GetScriptLocation(nsACString& aStr) MOZ_OVERRIDE;
154
  void SetURI(nsIURI* aURI);
157
  void SetURI(nsIURI* aURI);
155
158
159
  static bool IsPrincipalInherited(nsIURI* aURI) {
160
    // return true if the loadee URI has
161
    // the URI_INHERITS_SECURITY_CONTEXT flag set.
162
    bool doesInheritSecurityContext;
163
    nsresult rv =
164
    NS_URIChainHasFlags(aURI,
165
                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
166
                        &doesInheritSecurityContext);
167
168
    if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) {
169
      return true;
170
    }
171
172
    return false;
173
  }
174
156
  nsCOMPtr<nsIURI> mDomain;
175
  nsCOMPtr<nsIURI> mDomain;
157
  nsCOMPtr<nsIURI> mCodebase;
176
  nsCOMPtr<nsIURI> mCodebase;
158
  // If mCodebaseImmutable is true, mCodebase is non-null and immutable
177
  // If mCodebaseImmutable is true, mCodebase is non-null and immutable
159
  bool mCodebaseImmutable;
178
  bool mCodebaseImmutable;
160
  bool mDomainImmutable;
179
  bool mDomainImmutable;
161
  bool mInitialized;
180
  bool mInitialized;
162
};
181
};
163
182
 Lines 177-193   public: Link Here 
177
  NS_IMETHOD EqualsIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
196
  NS_IMETHOD EqualsIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
178
  NS_IMETHOD GetHashValue(PRUint32* aHashValue);
197
  NS_IMETHOD GetHashValue(PRUint32* aHashValue);
179
  NS_IMETHOD GetURI(nsIURI** aURI);
198
  NS_IMETHOD GetURI(nsIURI** aURI);
180
  NS_IMETHOD GetDomain(nsIURI** aDomain);
199
  NS_IMETHOD GetDomain(nsIURI** aDomain);
181
  NS_IMETHOD SetDomain(nsIURI* aDomain);
200
  NS_IMETHOD SetDomain(nsIURI* aDomain);
182
  NS_IMETHOD GetOrigin(char** aOrigin);
201
  NS_IMETHOD GetOrigin(char** aOrigin);
183
  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
202
  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
184
  NS_IMETHOD SubsumesIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
203
  NS_IMETHOD SubsumesIgnoringDomain(nsIPrincipal* other, bool* _retval NS_OUTPARAM);
185
  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report);
204
  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal);
186
#ifdef DEBUG
205
#ifdef DEBUG
187
  virtual void dumpImpl();
206
  virtual void dumpImpl();
188
#endif
207
#endif
189
  
208
  
190
  virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE;
209
  virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE;
191
210
192
private:
211
private:
193
  nsTArray< nsCOMPtr<nsIPrincipal> > mPrincipals;
212
  nsTArray< nsCOMPtr<nsIPrincipal> > mPrincipals;
(-)a/caps/src/nsNullPrincipal.cpp (-1 / +19 lines)
Line     Link Here 
 Lines 286-303   nsNullPrincipal::Subsumes(nsIPrincipal * Link Here 
286
286
287
NS_IMETHODIMP
287
NS_IMETHODIMP
288
nsNullPrincipal::SubsumesIgnoringDomain(nsIPrincipal *aOther, bool *aResult)
288
nsNullPrincipal::SubsumesIgnoringDomain(nsIPrincipal *aOther, bool *aResult)
289
{
289
{
290
  return Subsumes(aOther, aResult);
290
  return Subsumes(aOther, aResult);
291
}
291
}
292
292
293
NS_IMETHODIMP
293
NS_IMETHODIMP
294
nsNullPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport)
294
nsNullPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
295
{
295
{
296
  if (aAllowIfInheritsPrincipal) {
297
    if (nsPrincipal::IsPrincipalInherited(aURI)) {
298
      return NS_OK;
299
    }
300
301
    // Also allow the load if the principal of the URI being checked is exactly
302
    // us ie this.
303
    nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
304
    if (uriPrinc) {
305
      nsCOMPtr<nsIPrincipal> principal;
306
      uriPrinc->GetPrincipal(getter_AddRefs(principal));
307
308
      if (principal && principal == this) {
309
        return NS_OK;
310
      }
311
    }
312
  }
313
296
  if (aReport) {
314
  if (aReport) {
297
    nsScriptSecurityManager::ReportError(
315
    nsScriptSecurityManager::ReportError(
298
      nsnull, NS_LITERAL_STRING("CheckSameOriginError"), mURI, aURI);
316
      nsnull, NS_LITERAL_STRING("CheckSameOriginError"), mURI, aURI);
299
  }
317
  }
300
318
301
  return NS_ERROR_DOM_BAD_URI;
319
  return NS_ERROR_DOM_BAD_URI;
302
}
320
}
303
321
(-)a/caps/src/nsPrincipal.cpp (-3 / +11 lines)
Line     Link Here 
 Lines 824-841   URIIsLocalFile(nsIURI *aURI) Link Here 
824
824
825
  return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
825
  return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
826
                                nsIProtocolHandler::URI_IS_LOCAL_FILE,
826
                                nsIProtocolHandler::URI_IS_LOCAL_FILE,
827
                                &isFile)) &&
827
                                &isFile)) &&
828
         isFile;
828
         isFile;
829
}
829
}
830
830
831
NS_IMETHODIMP
831
NS_IMETHODIMP
832
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport)
832
nsPrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
833
{
833
{
834
   if (aAllowIfInheritsPrincipal) {
835
    // If the caller specified to allow loads of URIs that inherit
836
    // our principal, allow the load if this URI inherits its principal
837
    if (nsPrincipal::IsPrincipalInherited(aURI)) {
838
      return NS_OK;
839
    }
840
  }
841
834
  if (!nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
842
  if (!nsScriptSecurityManager::SecurityCompareURIs(mCodebase, aURI)) {
835
    if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
843
    if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
836
        URIIsLocalFile(aURI)) {
844
        URIIsLocalFile(aURI)) {
837
      nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(aURI));
845
      nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(aURI));
838
846
839
      if (!URIIsLocalFile(mCodebase)) {
847
      if (!URIIsLocalFile(mCodebase)) {
840
        // If the codebase is not also a file: uri then forget it
848
        // If the codebase is not also a file: uri then forget it
841
        // (don't want resource: principals in a file: doc)
849
        // (don't want resource: principals in a file: doc)
 Lines 1334-1354   nsExpandedPrincipal::Subsumes(nsIPrincip Link Here 
1334
1342
1335
NS_IMETHODIMP
1343
NS_IMETHODIMP
1336
nsExpandedPrincipal::SubsumesIgnoringDomain(nsIPrincipal* aOther, bool* aResult)
1344
nsExpandedPrincipal::SubsumesIgnoringDomain(nsIPrincipal* aOther, bool* aResult)
1337
{
1345
{
1338
  return ::Subsumes(this, &nsIPrincipal::SubsumesIgnoringDomain, aOther, aResult);
1346
  return ::Subsumes(this, &nsIPrincipal::SubsumesIgnoringDomain, aOther, aResult);
1339
}
1347
}
1340
1348
1341
NS_IMETHODIMP
1349
NS_IMETHODIMP
1342
nsExpandedPrincipal::CheckMayLoad(nsIURI* uri, bool aReport)
1350
nsExpandedPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
1343
{
1351
{
1344
  nsresult rv;
1352
  nsresult rv;
1345
  for (uint32_t i = 0; i < mPrincipals.Length(); ++i){
1353
  for (uint32_t i = 0; i < mPrincipals.Length(); ++i){
1346
    rv = mPrincipals[i]->CheckMayLoad(uri, aReport);
1354
    rv = mPrincipals[i]->CheckMayLoad(uri, aReport, aAllowIfInheritsPrincipal);
1347
    if (NS_SUCCEEDED(rv))
1355
    if (NS_SUCCEEDED(rv))
1348
      return rv;
1356
      return rv;
1349
  }
1357
  }
1350
1358
1351
  return NS_ERROR_DOM_BAD_URI;
1359
  return NS_ERROR_DOM_BAD_URI;
1352
}
1360
}
1353
1361
1354
NS_IMETHODIMP
1362
NS_IMETHODIMP
(-)a/caps/src/nsScriptSecurityManager.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1459-1475   nsScriptSecurityManager::CheckLoadURIWit Link Here 
1459
    // Check for uris that are only loadable by principals that subsume them
1459
    // Check for uris that are only loadable by principals that subsume them
1460
    bool hasFlags;
1460
    bool hasFlags;
1461
    rv = NS_URIChainHasFlags(targetBaseURI,
1461
    rv = NS_URIChainHasFlags(targetBaseURI,
1462
                             nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS,
1462
                             nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS,
1463
                             &hasFlags);
1463
                             &hasFlags);
1464
    NS_ENSURE_SUCCESS(rv, rv);
1464
    NS_ENSURE_SUCCESS(rv, rv);
1465
1465
1466
    if (hasFlags) {
1466
    if (hasFlags) {
1467
        return aPrincipal->CheckMayLoad(targetBaseURI, true);
1467
        return aPrincipal->CheckMayLoad(targetBaseURI, true, false);
1468
    }
1468
    }
1469
1469
1470
    //-- get the source scheme
1470
    //-- get the source scheme
1471
    nsCAutoString sourceScheme;
1471
    nsCAutoString sourceScheme;
1472
    rv = sourceBaseURI->GetScheme(sourceScheme);
1472
    rv = sourceBaseURI->GetScheme(sourceScheme);
1473
    if (NS_FAILED(rv)) return rv;
1473
    if (NS_FAILED(rv)) return rv;
1474
1474
1475
    if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
1475
    if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
(-)a/caps/src/nsSystemPrincipal.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 109-125   nsSystemPrincipal::Subsumes(nsIPrincipal Link Here 
109
NS_IMETHODIMP
109
NS_IMETHODIMP
110
nsSystemPrincipal::SubsumesIgnoringDomain(nsIPrincipal *other, bool *result)
110
nsSystemPrincipal::SubsumesIgnoringDomain(nsIPrincipal *other, bool *result)
111
{
111
{
112
    *result = true;
112
    *result = true;
113
    return NS_OK;
113
    return NS_OK;
114
}
114
}
115
115
116
NS_IMETHODIMP
116
NS_IMETHODIMP
117
nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport)
117
nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
118
{
118
{
119
    return NS_OK;
119
    return NS_OK;
120
}
120
}
121
121
122
NS_IMETHODIMP
122
NS_IMETHODIMP
123
nsSystemPrincipal::GetHashValue(PRUint32 *result)
123
nsSystemPrincipal::GetHashValue(PRUint32 *result)
124
{
124
{
125
    *result = NS_PTR_TO_INT32(this);
125
    *result = NS_PTR_TO_INT32(this);
(-)a/content/base/public/nsContentUtils.h (-1 / +1 lines)
Line     Link Here 
 Lines 1696-1712   public: Link Here 
1696
   *
1696
   *
1697
   * @param aScriptContext the script context to get the document for; can be null
1697
   * @param aScriptContext the script context to get the document for; can be null
1698
   *
1698
   *
1699
   * @return the document associated with the script context
1699
   * @return the document associated with the script context
1700
   */
1700
   */
1701
  static already_AddRefed<nsIDocument>
1701
  static already_AddRefed<nsIDocument>
1702
  GetDocumentFromScriptContext(nsIScriptContext *aScriptContext);
1702
  GetDocumentFromScriptContext(nsIScriptContext *aScriptContext);
1703
1703
1704
  static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel);
1704
  static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel, bool aAllowIfInheritsPrincipal);
1705
1705
1706
  /**
1706
  /**
1707
   * The method checks whether the caller can access native anonymous content.
1707
   * The method checks whether the caller can access native anonymous content.
1708
   * If there is no JS in the stack or privileged JS is running, this
1708
   * If there is no JS in the stack or privileged JS is running, this
1709
   * method returns true, otherwise false.
1709
   * method returns true, otherwise false.
1710
   */
1710
   */
1711
  static bool CanAccessNativeAnon();
1711
  static bool CanAccessNativeAnon();
1712
1712
(-)a/content/base/src/nsContentSink.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1081-1097   nsContentSink::ProcessOfflineManifest(co Link Here 
1081
    nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(manifestURI),
1081
    nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(manifestURI),
1082
                                              aManifestSpec, mDocument,
1082
                                              aManifestSpec, mDocument,
1083
                                              mDocumentURI);
1083
                                              mDocumentURI);
1084
    if (!manifestURI) {
1084
    if (!manifestURI) {
1085
      return;
1085
      return;
1086
    }
1086
    }
1087
1087
1088
    // Documents must list a manifest from the same origin
1088
    // Documents must list a manifest from the same origin
1089
    rv = mDocument->NodePrincipal()->CheckMayLoad(manifestURI, true);
1089
    rv = mDocument->NodePrincipal()->CheckMayLoad(manifestURI, true, false);
1090
    if (NS_FAILED(rv)) {
1090
    if (NS_FAILED(rv)) {
1091
      action = CACHE_SELECTION_RESELECT_WITHOUT_MANIFEST;
1091
      action = CACHE_SELECTION_RESELECT_WITHOUT_MANIFEST;
1092
    }
1092
    }
1093
    else {
1093
    else {
1094
      // Only continue if the document has permission to use offline APIs.
1094
      // Only continue if the document has permission to use offline APIs.
1095
      if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
1095
      if (!nsContentUtils::OfflineAppAllowed(mDocument->NodePrincipal())) {
1096
        return;
1096
        return;
1097
      }
1097
      }
(-)a/content/base/src/nsContentUtils.cpp (-6 / +6 lines)
Line     Link Here 
 Lines 4560-4576   nsContentUtils::CheckSecurityBeforeLoad( Link Here 
4560
4560
4561
  // Same Origin
4561
  // Same Origin
4562
  if ((aAllowData && SchemeIs(aURIToLoad, "data")) ||
4562
  if ((aAllowData && SchemeIs(aURIToLoad, "data")) ||
4563
      ((aCheckLoadFlags & nsIScriptSecurityManager::ALLOW_CHROME) &&
4563
      ((aCheckLoadFlags & nsIScriptSecurityManager::ALLOW_CHROME) &&
4564
       SchemeIs(aURIToLoad, "chrome"))) {
4564
       SchemeIs(aURIToLoad, "chrome"))) {
4565
    return NS_OK;
4565
    return NS_OK;
4566
  }
4566
  }
4567
4567
4568
  return aLoadingPrincipal->CheckMayLoad(aURIToLoad, true);
4568
  return aLoadingPrincipal->CheckMayLoad(aURIToLoad, true, false);
4569
}
4569
}
4570
4570
4571
bool
4571
bool
4572
nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
4572
nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
4573
{
4573
{
4574
  bool isSystem;
4574
  bool isSystem;
4575
  nsresult rv = sSecurityManager->IsSystemPrincipal(aPrincipal, &isSystem);
4575
  nsresult rv = sSecurityManager->IsSystemPrincipal(aPrincipal, &isSystem);
4576
  return NS_SUCCEEDED(rv) && isSystem;
4576
  return NS_SUCCEEDED(rv) && isSystem;
 Lines 5688-5706   nsContentUtils::CheckSameOrigin(nsIChann Link Here 
5688
5688
5689
  nsCOMPtr<nsIURI> newURI;
5689
  nsCOMPtr<nsIURI> newURI;
5690
  aNewChannel->GetURI(getter_AddRefs(newURI));
5690
  aNewChannel->GetURI(getter_AddRefs(newURI));
5691
  nsCOMPtr<nsIURI> newOriginalURI;
5691
  nsCOMPtr<nsIURI> newOriginalURI;
5692
  aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
5692
  aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
5693
5693
5694
  NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
5694
  NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
5695
5695
5696
  nsresult rv = oldPrincipal->CheckMayLoad(newURI, false);
5696
  nsresult rv = oldPrincipal->CheckMayLoad(newURI, false, false);
5697
  if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
5697
  if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
5698
    rv = oldPrincipal->CheckMayLoad(newOriginalURI, false);
5698
    rv = oldPrincipal->CheckMayLoad(newOriginalURI, false, false);
5699
  }
5699
  }
5700
5700
5701
  return rv;
5701
  return rv;
5702
}
5702
}
5703
5703
5704
NS_IMPL_ISUPPORTS2(SameOriginChecker,
5704
NS_IMPL_ISUPPORTS2(SameOriginChecker,
5705
                   nsIChannelEventSink,
5705
                   nsIChannelEventSink,
5706
                   nsIInterfaceRequestor)
5706
                   nsIInterfaceRequestor)
 Lines 5861-5883   nsContentUtils::GetDocumentFromScriptCon Link Here 
5861
      CallQueryInterface(domdoc, &doc);
5861
      CallQueryInterface(domdoc, &doc);
5862
    }
5862
    }
5863
  }
5863
  }
5864
  return doc;
5864
  return doc;
5865
}
5865
}
5866
5866
5867
/* static */
5867
/* static */
5868
bool
5868
bool
5869
nsContentUtils::CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel)
5869
nsContentUtils::CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel, bool aAllowIfInheritsPrincipal)
5870
{
5870
{
5871
  nsCOMPtr<nsIURI> channelURI;
5871
  nsCOMPtr<nsIURI> channelURI;
5872
  nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
5872
  nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
5873
  NS_ENSURE_SUCCESS(rv, false);
5873
  NS_ENSURE_SUCCESS(rv, false);
5874
5874
5875
  return NS_SUCCEEDED(aPrincipal->CheckMayLoad(channelURI, false));
5875
  return NS_SUCCEEDED(aPrincipal->CheckMayLoad(channelURI, false, aAllowIfInheritsPrincipal));
5876
}
5876
}
5877
5877
5878
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
5878
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
5879
  : mString(aString), mService(nsnull)
5879
  : mString(aString), mService(nsnull)
5880
{
5880
{
5881
  CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
5881
  CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
5882
}
5882
}
5883
5883
 Lines 6634-6650   nsContentUtils::SetUpChannelOwner(nsIPri Link Here 
6634
  // file: uri special-casing
6634
  // file: uri special-casing
6635
  //
6635
  //
6636
  // If this is a file: load opened from another file: then it may need
6636
  // If this is a file: load opened from another file: then it may need
6637
  // to inherit the owner from the referrer so they can script each other.
6637
  // to inherit the owner from the referrer so they can script each other.
6638
  // If we don't set the owner explicitly then each file: gets an owner
6638
  // If we don't set the owner explicitly then each file: gets an owner
6639
  // based on its own codebase later.
6639
  // based on its own codebase later.
6640
  //
6640
  //
6641
  if (URIIsLocalFile(aURI) && aLoadingPrincipal &&
6641
  if (URIIsLocalFile(aURI) && aLoadingPrincipal &&
6642
      NS_SUCCEEDED(aLoadingPrincipal->CheckMayLoad(aURI, false)) &&
6642
      NS_SUCCEEDED(aLoadingPrincipal->CheckMayLoad(aURI, false, false)) &&
6643
      // One more check here.  CheckMayLoad will always return true for the
6643
      // One more check here.  CheckMayLoad will always return true for the
6644
      // system principal, but we do NOT want to inherit in that case.
6644
      // system principal, but we do NOT want to inherit in that case.
6645
      !IsSystemPrincipal(aLoadingPrincipal)) {
6645
      !IsSystemPrincipal(aLoadingPrincipal)) {
6646
    aChannel->SetOwner(aLoadingPrincipal);
6646
    aChannel->SetOwner(aLoadingPrincipal);
6647
    return true;
6647
    return true;
6648
  }
6648
  }
6649
6649
6650
  return false;
6650
  return false;
(-)a/content/base/src/nsCrossSiteListenerProxy.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 738-757   nsCORSListenerProxy::UpdateChannel(nsICh Link Here 
738
  if (originalURI != uri) {
738
  if (originalURI != uri) {
739
    rv = nsContentUtils::GetSecurityManager()->
739
    rv = nsContentUtils::GetSecurityManager()->
740
      CheckLoadURIWithPrincipal(mRequestingPrincipal, originalURI,
740
      CheckLoadURIWithPrincipal(mRequestingPrincipal, originalURI,
741
                                nsIScriptSecurityManager::STANDARD);
741
                                nsIScriptSecurityManager::STANDARD);
742
    NS_ENSURE_SUCCESS(rv, rv);
742
    NS_ENSURE_SUCCESS(rv, rv);
743
  }
743
  }
744
744
745
  if (!mHasBeenCrossSite &&
745
  if (!mHasBeenCrossSite &&
746
      NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(uri, false)) &&
746
      NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(uri, false, false)) &&
747
      (originalURI == uri ||
747
      (originalURI == uri ||
748
       NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(originalURI,
748
       NS_SUCCEEDED(mRequestingPrincipal->CheckMayLoad(originalURI,
749
                                                       false)))) {
749
                                                       false, false)))) {
750
    return NS_OK;
750
    return NS_OK;
751
  }
751
  }
752
752
753
  // It's a cross site load
753
  // It's a cross site load
754
  mHasBeenCrossSite = true;
754
  mHasBeenCrossSite = true;
755
755
756
  nsCString userpass;
756
  nsCString userpass;
757
  uri->GetUserPass(userpass);
757
  uri->GetUserPass(userpass);
(-)a/content/base/src/nsDocument.cpp (-10 / +4 lines)
Line     Link Here 
 Lines 1049-1076   nsExternalResourceMap::PendingLoad::Star Link Here 
1049
1049
1050
  nsIPrincipal* requestingPrincipal = aRequestingNode->NodePrincipal();
1050
  nsIPrincipal* requestingPrincipal = aRequestingNode->NodePrincipal();
1051
1051
1052
  nsresult rv = nsContentUtils::GetSecurityManager()->
1052
  nsresult rv = nsContentUtils::GetSecurityManager()->
1053
    CheckLoadURIWithPrincipal(requestingPrincipal, aURI,
1053
    CheckLoadURIWithPrincipal(requestingPrincipal, aURI,
1054
                              nsIScriptSecurityManager::STANDARD);
1054
                              nsIScriptSecurityManager::STANDARD);
1055
  NS_ENSURE_SUCCESS(rv, rv);
1055
  NS_ENSURE_SUCCESS(rv, rv);
1056
  
1056
  
1057
  // Allow data URIs (let them skip the CheckMayLoad call), since we want
1057
  // Allow data URIs and other URI's that inherit their principal by passing
1058
  // true as the 3rd argument of CheckMayLoad, since we want
1058
  // to allow external resources from data URIs regardless of the difference
1059
  // to allow external resources from data URIs regardless of the difference
1059
  // in URI scheme.
1060
  // in URI scheme.
1060
  bool doesInheritSecurityContext;
1061
  rv = requestingPrincipal->CheckMayLoad(aURI, true, true);
1061
  rv =
1062
  NS_ENSURE_SUCCESS(rv, rv);
1062
    NS_URIChainHasFlags(aURI,
1063
                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1064
                        &doesInheritSecurityContext);
1065
  if (NS_FAILED(rv) || !doesInheritSecurityContext) {
1066
    rv = requestingPrincipal->CheckMayLoad(aURI, true);
1067
    NS_ENSURE_SUCCESS(rv, rv);
1068
  }
1069
1063
1070
  PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
1064
  PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
1071
  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER,
1065
  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER,
1072
                                 aURI,
1066
                                 aURI,
1073
                                 requestingPrincipal,
1067
                                 requestingPrincipal,
1074
                                 aRequestingNode,
1068
                                 aRequestingNode,
1075
                                 EmptyCString(), //mime guess
1069
                                 EmptyCString(), //mime guess
1076
                                 nsnull,         //extra
1070
                                 nsnull,         //extra
(-)a/content/base/src/nsXMLHttpRequest.cpp (-12 / +3 lines)
Line     Link Here 
 Lines 1713-1740   nsXMLHttpRequest::IsSystemXHR() Link Here 
1713
nsresult
1713
nsresult
1714
nsXMLHttpRequest::CheckChannelForCrossSiteRequest(nsIChannel* aChannel)
1714
nsXMLHttpRequest::CheckChannelForCrossSiteRequest(nsIChannel* aChannel)
1715
{
1715
{
1716
  // First check if cross-site requests are enabled...
1716
  // First check if cross-site requests are enabled...
1717
  if (IsSystemXHR()) {
1717
  if (IsSystemXHR()) {
1718
    return NS_OK;
1718
    return NS_OK;
1719
  }
1719
  }
1720
1720
1721
  // ...or if this is a same-origin request.
1721
  // If this is a same-origin request or the channel's URI inherits
1722
  if (nsContentUtils::CheckMayLoad(mPrincipal, aChannel)) {
1722
  // its principal, it's allowed.
1723
    return NS_OK;
1723
  if (nsContentUtils::CheckMayLoad(mPrincipal, aChannel, true)) {
1724
  }
1725
1726
  // exempt data URIs from the same origin check.
1727
  nsCOMPtr<nsIURI> channelURI;
1728
  bool dataScheme = false;
1729
  if (NS_SUCCEEDED(NS_GetFinalChannelURI(aChannel,
1730
                                         getter_AddRefs(channelURI))) &&
1731
      NS_SUCCEEDED(channelURI->SchemeIs("data", &dataScheme)) &&
1732
      dataScheme) {
1733
    return NS_OK;
1724
    return NS_OK;
1734
  }
1725
  }
1735
1726
1736
  // This is a cross-site request
1727
  // This is a cross-site request
1737
  mState |= XML_HTTP_REQUEST_USE_XSITE_AC;
1728
  mState |= XML_HTTP_REQUEST_USE_XSITE_AC;
1738
1729
1739
  // Check if we need to do a preflight request.
1730
  // Check if we need to do a preflight request.
1740
  nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
1731
  nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
(-)a/content/xbl/src/nsXBLService.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 925-941   nsXBLService::LoadBindingDocumentInfo(ns Link Here 
925
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
925
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
926
926
927
    if (!IsSystemOrChromeURLPrincipal(aOriginPrincipal)) {
927
    if (!IsSystemOrChromeURLPrincipal(aOriginPrincipal)) {
928
      // Also make sure that we're same-origin with the bound document
928
      // Also make sure that we're same-origin with the bound document
929
      // except if the stylesheet has the system principal.
929
      // except if the stylesheet has the system principal.
930
      if (!(gAllowDataURIs && SchemeIs(aBindingURI, "data")) &&
930
      if (!(gAllowDataURIs && SchemeIs(aBindingURI, "data")) &&
931
          !SchemeIs(aBindingURI, "chrome")) {
931
          !SchemeIs(aBindingURI, "chrome")) {
932
        rv = aBoundDocument->NodePrincipal()->CheckMayLoad(aBindingURI,
932
        rv = aBoundDocument->NodePrincipal()->CheckMayLoad(aBindingURI,
933
                                                           true);
933
                                                           true, false);
934
        NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
934
        NS_ENSURE_SUCCESS(rv, NS_ERROR_XBL_BLOCKED);
935
      }
935
      }
936
936
937
      // Finally check if this document is allowed to use XBL at all.
937
      // Finally check if this document is allowed to use XBL at all.
938
      NS_ENSURE_TRUE(aBoundDocument->AllowXULXBL(),
938
      NS_ENSURE_TRUE(aBoundDocument->AllowXULXBL(),
939
                     NS_ERROR_XBL_BLOCKED);
939
                     NS_ERROR_XBL_BLOCKED);
940
    }
940
    }
941
  }
941
  }
(-)a/content/xml/document/src/nsXMLDocument.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 329-345   nsXMLDocument::Load(const nsAString& aUr Link Here 
329
  // that we don't end up in a case where code with elevated privileges is
329
  // that we don't end up in a case where code with elevated privileges is
330
  // calling us and changing the principal of this document.
330
  // calling us and changing the principal of this document.
331
331
332
  // Enforce same-origin even for chrome loaders to avoid someone accidentally
332
  // Enforce same-origin even for chrome loaders to avoid someone accidentally
333
  // using a document that content has a reference to and turn that into a
333
  // using a document that content has a reference to and turn that into a
334
  // chrome document.
334
  // chrome document.
335
  nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
335
  nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
336
  if (!nsContentUtils::IsSystemPrincipal(principal)) {
336
  if (!nsContentUtils::IsSystemPrincipal(principal)) {
337
    rv = principal->CheckMayLoad(uri, false);
337
    rv = principal->CheckMayLoad(uri, false, false);
338
    NS_ENSURE_SUCCESS(rv, rv);
338
    NS_ENSURE_SUCCESS(rv, rv);
339
339
340
    PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
340
    PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
341
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
341
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
342
                                   uri,
342
                                   uri,
343
                                   principal,
343
                                   principal,
344
                                   callingDoc ? callingDoc.get() :
344
                                   callingDoc ? callingDoc.get() :
345
                                     static_cast<nsIDocument*>(this),
345
                                     static_cast<nsIDocument*>(this),
(-)a/content/xul/document/src/nsXULDocument.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 2654-2670   nsXULDocument::LoadOverlayInternal(nsIUR Link Here 
2654
2654
2655
    // Chrome documents are allowed to load overlays from anywhere.
2655
    // Chrome documents are allowed to load overlays from anywhere.
2656
    // In all other cases, the overlay is only allowed to load if
2656
    // In all other cases, the overlay is only allowed to load if
2657
    // the master document and prototype document have the same origin.
2657
    // the master document and prototype document have the same origin.
2658
2658
2659
    bool documentIsChrome = IsChromeURI(mDocumentURI);
2659
    bool documentIsChrome = IsChromeURI(mDocumentURI);
2660
    if (!documentIsChrome) {
2660
    if (!documentIsChrome) {
2661
        // Make sure we're allowed to load this overlay.
2661
        // Make sure we're allowed to load this overlay.
2662
        rv = NodePrincipal()->CheckMayLoad(aURI, true);
2662
        rv = NodePrincipal()->CheckMayLoad(aURI, true, false);
2663
        if (NS_FAILED(rv)) {
2663
        if (NS_FAILED(rv)) {
2664
            *aFailureFromContent = true;
2664
            *aFailureFromContent = true;
2665
            return rv;
2665
            return rv;
2666
        }
2666
        }
2667
    }
2667
    }
2668
2668
2669
    // Look in the prototype cache for the prototype document with
2669
    // Look in the prototype cache for the prototype document with
2670
    // the specified overlay URI. Only use the cache if the containing
2670
    // 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 1323-1339   nsXULTemplateBuilder::LoadDataSourceUrls Link Here 
1323
1323
1324
        nsCOMPtr<nsIURI> uri;
1324
        nsCOMPtr<nsIURI> uri;
1325
        rv = NS_NewURI(getter_AddRefs(uri), uriStr);
1325
        rv = NS_NewURI(getter_AddRefs(uri), uriStr);
1326
        if (NS_FAILED(rv) || !uri)
1326
        if (NS_FAILED(rv) || !uri)
1327
            continue; // Necko will barf if our URI is weird
1327
            continue; // Necko will barf if our URI is weird
1328
1328
1329
        // don't add the uri to the list if the document is not allowed to
1329
        // don't add the uri to the list if the document is not allowed to
1330
        // load it
1330
        // load it
1331
        if (!isTrusted && NS_FAILED(docPrincipal->CheckMayLoad(uri, true)))
1331
        if (!isTrusted && NS_FAILED(docPrincipal->CheckMayLoad(uri, true, false)))
1332
          continue;
1332
          continue;
1333
1333
1334
        uriList->AppendElement(uri, false);
1334
        uriList->AppendElement(uri, false);
1335
    }
1335
    }
1336
1336
1337
    nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(mRoot);
1337
    nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(mRoot);
1338
    rv = mQueryProcessor->GetDatasource(uriList,
1338
    rv = mQueryProcessor->GetDatasource(uriList,
1339
                                        rootNode,
1339
                                        rootNode,
(-)a/docshell/base/nsDocShell.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 9929-9945   nsDocShell::AddState(nsIVariant *aData, Link Here 
9929
9929
9930
            if (!docScriptObj) {
9930
            if (!docScriptObj) {
9931
                return NS_ERROR_DOM_SECURITY_ERR;
9931
                return NS_ERROR_DOM_SECURITY_ERR;
9932
            }
9932
            }
9933
9933
9934
            nsCOMPtr<nsIPrincipal> principal = docScriptObj->GetPrincipal();
9934
            nsCOMPtr<nsIPrincipal> principal = docScriptObj->GetPrincipal();
9935
9935
9936
            if (!principal ||
9936
            if (!principal ||
9937
                NS_FAILED(principal->CheckMayLoad(newURI, true))) {
9937
                NS_FAILED(principal->CheckMayLoad(newURI, true, false))) {
9938
9938
9939
                return NS_ERROR_DOM_SECURITY_ERR;
9939
                return NS_ERROR_DOM_SECURITY_ERR;
9940
            }
9940
            }
9941
        }
9941
        }
9942
9942
9943
        if (mCurrentURI) {
9943
        if (mCurrentURI) {
9944
            mCurrentURI->Equals(newURI, &equalURIs);
9944
            mCurrentURI->Equals(newURI, &equalURIs);
9945
        }
9945
        }
(-)a/dom/workers/ScriptLoader.cpp (-8 / +9 lines)
Line     Link Here 
 Lines 296-316   public: Link Here 
296
      // If this script loader is being used to make a new worker then we need
296
      // If this script loader is being used to make a new worker then we need
297
      // to do a same-origin check. Otherwise we need to clear the load with the
297
      // to do a same-origin check. Otherwise we need to clear the load with the
298
      // security manager.
298
      // security manager.
299
      if (mIsWorkerScript) {
299
      if (mIsWorkerScript) {
300
        nsCString scheme;
300
        nsCString scheme;
301
        rv = uri->GetScheme(scheme);
301
        rv = uri->GetScheme(scheme);
302
        NS_ENSURE_SUCCESS(rv, rv);
302
        NS_ENSURE_SUCCESS(rv, rv);
303
303
304
        // We exempt data URLs from the same origin check.
304
        // We pass true as the 3rd argument to checkMayLoad here.
305
        if (!scheme.EqualsLiteral("data")) {
305
        // This allows workers in sandboxed documents to load data URLs
306
          rv = principal->CheckMayLoad(uri, false);
306
        // (and other URLs that inherit their principal from their
307
          NS_ENSURE_SUCCESS(rv, rv);
307
        // creator.)
308
        }
308
        rv = principal->CheckMayLoad(uri, false, true);
309
        NS_ENSURE_SUCCESS(rv, rv);
309
      }
310
      }
310
      else {
311
      else {
311
        rv = secMan->CheckLoadURIWithPrincipal(principal, uri, 0);
312
        rv = secMan->CheckLoadURIWithPrincipal(principal, uri, 0);
312
        NS_ENSURE_SUCCESS(rv, rv);
313
        NS_ENSURE_SUCCESS(rv, rv);
313
      }
314
      }
314
315
315
      // We need to know which index we're on in OnStreamComplete so we know
316
      // We need to know which index we're on in OnStreamComplete so we know
316
      // where to put the result.
317
      // where to put the result.
 Lines 483-501   public: Link Here 
483
          return NS_ERROR_DOM_BAD_URI;
484
          return NS_ERROR_DOM_BAD_URI;
484
        }
485
        }
485
      }
486
      }
486
      else  {
487
      else  {
487
        nsCString scheme;
488
        nsCString scheme;
488
        rv = finalURI->GetScheme(scheme);
489
        rv = finalURI->GetScheme(scheme);
489
        NS_ENSURE_SUCCESS(rv, rv);
490
        NS_ENSURE_SUCCESS(rv, rv);
490
491
491
        // We exempt data urls again.
492
        // We exempt data urls and other URI's that inherit their
492
        if (!scheme.EqualsLiteral("data") &&
493
        // principal again.
493
            NS_FAILED(loadPrincipal->CheckMayLoad(finalURI, false))) {
494
        if (NS_FAILED(loadPrincipal->CheckMayLoad(finalURI, false, true))) {
494
          return NS_ERROR_DOM_BAD_URI;
495
          return NS_ERROR_DOM_BAD_URI;
495
        }
496
        }
496
      }
497
      }
497
498
498
      mWorkerPrivate->SetPrincipal(channelPrincipal);
499
      mWorkerPrivate->SetPrincipal(channelPrincipal);
499
    }
500
    }
500
501
501
    return NS_OK;
502
    return NS_OK;
(-)a/layout/style/Loader.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 1541-1557   Loader::LoadSheet(SheetLoadData* aLoadDa Link Here 
1541
  if (aLoadData->mLoaderPrincipal) {
1541
  if (aLoadData->mLoaderPrincipal) {
1542
    bool inherit;
1542
    bool inherit;
1543
    rv = NS_URIChainHasFlags(aLoadData->mURI,
1543
    rv = NS_URIChainHasFlags(aLoadData->mURI,
1544
                             nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1544
                             nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
1545
                             &inherit);
1545
                             &inherit);
1546
    if ((NS_SUCCEEDED(rv) && inherit) ||
1546
    if ((NS_SUCCEEDED(rv) && inherit) ||
1547
        (nsContentUtils::URIIsLocalFile(aLoadData->mURI) &&
1547
        (nsContentUtils::URIIsLocalFile(aLoadData->mURI) &&
1548
         NS_SUCCEEDED(aLoadData->mLoaderPrincipal->
1548
         NS_SUCCEEDED(aLoadData->mLoaderPrincipal->
1549
                      CheckMayLoad(aLoadData->mURI, false)))) {
1549
                      CheckMayLoad(aLoadData->mURI, false, false)))) {
1550
      channel->SetOwner(aLoadData->mLoaderPrincipal);
1550
      channel->SetOwner(aLoadData->mLoaderPrincipal);
1551
    }
1551
    }
1552
  }
1552
  }
1553
1553
1554
  // We don't have to hold on to the stream loader.  The ownership
1554
  // We don't have to hold on to the stream loader.  The ownership
1555
  // model is: Necko owns the stream loader, which owns the load data,
1555
  // model is: Necko owns the stream loader, which owns the load data,
1556
  // which owns us
1556
  // which owns us
1557
  nsCOMPtr<nsIUnicharStreamLoader> streamLoader;
1557
  nsCOMPtr<nsIUnicharStreamLoader> streamLoader;
(-)a/rdf/base/src/nsRDFXMLDataSource.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 882-900   RDFXMLDataSourceImpl::AsyncOnChannelRedi Link Here 
882
882
883
    nsCOMPtr<nsIURI> newURI;
883
    nsCOMPtr<nsIURI> newURI;
884
    aNewChannel->GetURI(getter_AddRefs(newURI));
884
    aNewChannel->GetURI(getter_AddRefs(newURI));
885
    nsCOMPtr<nsIURI> newOriginalURI;
885
    nsCOMPtr<nsIURI> newOriginalURI;
886
    aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
886
    aNewChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));
887
887
888
    NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
888
    NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);
889
889
890
    rv = oldPrincipal->CheckMayLoad(newURI, false);
890
    rv = oldPrincipal->CheckMayLoad(newURI, false, false);
891
    if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
891
    if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
892
        rv = oldPrincipal->CheckMayLoad(newOriginalURI, false);
892
        rv = oldPrincipal->CheckMayLoad(newOriginalURI, false, false);
893
    }
893
    }
894
894
895
    if (NS_FAILED(rv))
895
    if (NS_FAILED(rv))
896
        return rv;
896
        return rv;
897
897
898
    cb->OnRedirectVerifyCallback(NS_OK);
898
    cb->OnRedirectVerifyCallback(NS_OK);
899
    return NS_OK;
899
    return NS_OK;
900
}
900
}

Return to bug 341604