Attachment #633209: iframe sandbox v16 for bug #341604

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

(-)a/content/base/public/nsContentUtils.h (-4 / +17 lines)
Line     Link Here 
 Lines 816-831   public: Link Here 
816
  /**
816
  /**
817
   * Get the localized string named |aKey| in properties file |aFile|.
817
   * Get the localized string named |aKey| in properties file |aFile|.
818
   */
818
   */
819
  static nsresult GetLocalizedString(PropertiesFile aFile,
819
  static nsresult GetLocalizedString(PropertiesFile aFile,
820
                                     const char* aKey,
820
                                     const char* aKey,
821
                                     nsXPIDLString& aResult);
821
                                     nsXPIDLString& aResult);
822
822
823
  /**
823
  /**
824
   * A helper function that parses a sandbox attribute (of an <iframe> or
825
   * a CSP directive) and converts it to the set of flags used internally.
826
   *
827
   * @param aAttribute 	the value of the sandbox attribute
828
   * @return 			the set of flags
829
   */
830
  static PRUint32 ParseSandboxAttributeToFlags(const nsAString&
831
                                                 aSandboxAttr);
832
833
834
  /**
824
   * Fill (with the parameters given) the localized string named |aKey| in
835
   * Fill (with the parameters given) the localized string named |aKey| in
825
   * properties file |aFile|.
836
   * properties file |aFile|.
826
   */
837
   */
827
private:
838
private:
828
  static nsresult FormatLocalizedString(PropertiesFile aFile,
839
  static nsresult FormatLocalizedString(PropertiesFile aFile,
829
                                        const char* aKey,
840
                                        const char* aKey,
830
                                        const PRUnichar** aParams,
841
                                        const PRUnichar** aParams,
831
                                        PRUint32 aParamsLength,
842
                                        PRUint32 aParamsLength,
 Lines 1935-1976   public: Link Here 
1935
   * from the document it comes from.
1946
   * from the document it comes from.
1936
   */
1947
   */
1937
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1948
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1938
1949
1939
  /**
1950
  /**
1940
   * Set the given principal as the owner of the given channel, if
1951
   * Set the given principal as the owner of the given channel, if
1941
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1952
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1942
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1953
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1943
   * the principal set up on it.
1954
   * the principal set up on it. If aForceOwner is true, the owner
1944
   *
1955
   * will be set on the channel, even if the principal can be determined
1956
   * from the channel.
1945
   * The return value is whether the principal was set up as the owner
1957
   * The return value is whether the principal was set up as the owner
1946
   * of the channel.
1958
   * of the channel.
1947
   */
1959
   */
1948
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1960
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1949
                                nsIChannel* aChannel,
1961
                                nsIChannel* aChannel,
1950
                                nsIURI* aURI,
1962
                                nsIURI* aURI,
1951
                                bool aSetUpForAboutBlank);
1963
                                bool aSetUpForAboutBlank,
1964
                                bool aForceOwner = false);
1952
1965
1953
  static nsresult Btoa(const nsAString& aBinaryData,
1966
  static nsresult Btoa(const nsAString& aBinaryData,
1954
                       nsAString& aAsciiBase64String);
1967
                       nsAString& aAsciiBase64String);
1955
1968
1956
  static nsresult Atob(const nsAString& aAsciiString,
1969
  static nsresult Atob(const nsAString& aAsciiString,
1957
                       nsAString& aBinaryData);
1970
                       nsAString& aBinaryData);
1958
1971
1959
  /** If aJSArray is a Javascript array, this method iterates over its
1972
  /** If aJSArray is a Javascript array, this method iterates over its
1960
   *  elements and appends values to aRetVal as nsIAtoms.
1973
   *  elements and appends values to aRetVal as nsIAtoms.
1961
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1974
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1962
   */ 
1975
   */ 
1963
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1976
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1964
                                     nsCOMArray<nsIAtom>& aRetVal);
1977
                                     nsCOMArray<nsIAtom>& aRetVal);
1965
1978
1966
  /**
1979
  /**
1967
   * Returns whether the input element passed in parameter has the autocomplete
1980
   * Returns whether the input element passed in parameter has the autocomplete
1968
   * functionnality enabled. It is taking into account the form owner.
1981
   * functionality enabled. It is taking into account the form owner.
1969
   * NOTE: the caller has to make sure autocomplete makes sense for the
1982
   * NOTE: the caller has to make sure autocomplete makes sense for the
1970
   * element's type.
1983
   * element's type.
1971
   *
1984
   *
1972
   * @param aInput the input element to check. NOTE: aInput can't be null.
1985
   * @param aInput the input element to check. NOTE: aInput can't be null.
1973
   * @return whether the input element has autocomplete enabled.
1986
   * @return whether the input element has autocomplete enabled.
1974
   */
1987
   */
1975
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
1988
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
1976
1989
(-)a/content/base/public/nsIDocument.h (-3 / +17 lines)
Line     Link Here 
 Lines 87-104   class Loader; Link Here 
87
87
88
namespace dom {
88
namespace dom {
89
class Link;
89
class Link;
90
class Element;
90
class Element;
91
} // namespace dom
91
} // namespace dom
92
} // namespace mozilla
92
} // namespace mozilla
93
93
94
#define NS_IDOCUMENT_IID \
94
#define NS_IDOCUMENT_IID \
95
{ 0x077dcff0, 0x400d, 0x4d3c, \
95
{ 0x57fe44ae, 0x6656, 0x44b8, \
96
  { 0xbd, 0x4d, 0x5f, 0xd5, 0xe1, 0xa6, 0x63, 0x07 } }
96
  { 0x8d, 0xc0, 0xfc, 0xa7, 0x43, 0x28, 0xbe, 0x86 } }
97
97
98
// Flag for AddStyleSheet().
98
// Flag for AddStyleSheet().
99
#define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
99
#define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
100
100
101
// Enum for requesting a particular type of document when creating a doc
101
// Enum for requesting a particular type of document when creating a doc
102
enum DocumentFlavor {
102
enum DocumentFlavor {
103
  DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
103
  DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
104
  DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
104
  DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
 Lines 426-442   public: Link Here 
426
   * callers are expected to take action as needed if they want this
426
   * callers are expected to take action as needed if they want this
427
   * change to actually change anything immediately.
427
   * change to actually change anything immediately.
428
   * @see nsBidiUtils.h
428
   * @see nsBidiUtils.h
429
   */
429
   */
430
  void SetBidiOptions(PRUint32 aBidiOptions)
430
  void SetBidiOptions(PRUint32 aBidiOptions)
431
  {
431
  {
432
    mBidiOptions = aBidiOptions;
432
    mBidiOptions = aBidiOptions;
433
  }
433
  }
434
  
434
435
  /**
436
   * Get the sandbox flags for this document.
437
   * @see nsSandboxFlags.h for the possible flags
438
   */
439
  PRUint32 SandboxFlags() const
440
  {
441
    return mSandboxFlags;
442
  }
443
435
  /**
444
  /**
436
   * Access HTTP header data (this may also get set from other
445
   * Access HTTP header data (this may also get set from other
437
   * sources, like HTML META tags).
446
   * sources, like HTML META tags).
438
   */
447
   */
439
  virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
448
  virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
440
  virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
449
  virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
441
450
442
  /**
451
  /**
 Lines 1841-1856   protected: Link Here 
1841
  // If mIsStaticDocument is true, mOriginalDocument points to the original
1850
  // If mIsStaticDocument is true, mOriginalDocument points to the original
1842
  // document.
1851
  // document.
1843
  nsCOMPtr<nsIDocument> mOriginalDocument;
1852
  nsCOMPtr<nsIDocument> mOriginalDocument;
1844
1853
1845
  // The bidi options for this document.  What this bitfield means is
1854
  // The bidi options for this document.  What this bitfield means is
1846
  // defined in nsBidiUtils.h
1855
  // defined in nsBidiUtils.h
1847
  PRUint32 mBidiOptions;
1856
  PRUint32 mBidiOptions;
1848
1857
1858
  // The sandbox flags on the document. These reflect the value of the sandbox attribute of the
1859
  // associated IFRAME or CSP-protectable content, if existent. These are set at load time and
1860
  // are immutable - see nsSandboxFlags.h for the possible flags.
1861
  PRUint32 mSandboxFlags;
1862
1849
  nsCString mContentLanguage;
1863
  nsCString mContentLanguage;
1850
private:
1864
private:
1851
  nsCString mContentType;
1865
  nsCString mContentType;
1852
protected:
1866
protected:
1853
1867
1854
  // The document's security info
1868
  // The document's security info
1855
  nsCOMPtr<nsISupports> mSecurityInfo;
1869
  nsCOMPtr<nsISupports> mSecurityInfo;
1856
1870
(-)a/content/base/src/nsContentUtils.cpp (-3 / +61 lines)
Line     Link Here 
 Lines 176-191   static NS_DEFINE_CID(kXTFServiceCID, NS_ Link Here 
176
176
177
#include "nsWrapperCacheInlines.h"
177
#include "nsWrapperCacheInlines.h"
178
#include "nsIDOMDocumentType.h"
178
#include "nsIDOMDocumentType.h"
179
#include "nsCharSeparatedTokenizer.h"
179
#include "nsCharSeparatedTokenizer.h"
180
180
181
#include "nsICharsetDetector.h"
181
#include "nsICharsetDetector.h"
182
#include "nsICharsetDetectionObserver.h"
182
#include "nsICharsetDetectionObserver.h"
183
#include "nsIPlatformCharset.h"
183
#include "nsIPlatformCharset.h"
184
#include "nsSandboxFlags.h"
184
185
185
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
186
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
186
                                      const char** next, PRUnichar* result);
187
                                      const char** next, PRUnichar* result);
187
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
188
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
188
                                 int ns_aware, const char** colon);
189
                                 int ns_aware, const char** colon);
189
190
190
using namespace mozilla::dom;
191
using namespace mozilla::dom;
191
using namespace mozilla::layers;
192
using namespace mozilla::layers;
 Lines 882-897   nsContentUtils::GetParserService() Link Here 
882
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
883
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
883
    if (NS_FAILED(rv)) {
884
    if (NS_FAILED(rv)) {
884
      sParserService = nsnull;
885
      sParserService = nsnull;
885
    }
886
    }
886
  }
887
  }
887
888
888
  return sParserService;
889
  return sParserService;
889
}
890
}
891
/**
892
 * A helper function that parses a sandbox attribute (of an <iframe> or
893
 * a CSP directive) and converts it to the set of flags used internally.
894
 *
895
 * @param aAttribute    the value of the sandbox attribute
896
 * @return              the set of flags
897
 */
898
PRUint32
899
nsContentUtils::ParseSandboxAttributeToFlags(const nsAString& aSandboxAttrValue)
900
{
901
  // If there's a sandbox attribute at all (and there is if this is being
902
  // called), start off by setting all the restriction flags.
903
  PRUint32 out = SANDBOXED_NAVIGATION |
904
    SANDBOXED_TOPLEVEL_NAVIGATION |
905
    SANDBOXED_PLUGINS | SANDBOXED_ORIGIN |
906
    SANDBOXED_FORMS | SANDBOXED_SCRIPTS |
907
    SANDBOXED_AUTOMATIC_FEATURES;
908
909
  if (!aSandboxAttrValue.IsEmpty()) {
910
    // The separator optional flag is used because the HTML5 spec says any
911
    // whitespace is ok as a separator, which is what this does.
912
    HTMLSplitOnSpacesTokenizer tokenizer(aSandboxAttrValue, ' ',
913
      nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>::SEPARATOR_OPTIONAL);
914
915
    while (tokenizer.hasMoreTokens()) {
916
      nsDependentSubstring token = tokenizer.nextToken();
917
918
      if (token.LowerCaseEqualsLiteral("allow-scripts")) {
919
        out &= ~SANDBOXED_SCRIPTS;
920
      } else if (token.LowerCaseEqualsLiteral("allow-same-origin")) {
921
        out &= ~SANDBOXED_ORIGIN;
922
      } else if (token.LowerCaseEqualsLiteral("allow-forms")) {
923
        out &= ~SANDBOXED_FORMS;
924
      } else if (token.LowerCaseEqualsLiteral("allow-scripts")) {
925
        // allow-scripts removes both SANDBOXED_SCRIPTS and
926
        // SANDBOXED_AUTOMATIC_FEATURES.
927
        out &= ~SANDBOXED_SCRIPTS;
928
        out &= ~SANDBOXED_AUTOMATIC_FEATURES;
929
      } else if (token.LowerCaseEqualsLiteral("allow-top-navigation")) {
930
        out &= ~SANDBOXED_TOPLEVEL_NAVIGATION;
931
      }
932
    }
933
  }
934
935
  return out;
936
}
890
937
891
#ifdef MOZ_XTF
938
#ifdef MOZ_XTF
892
nsIXTFService*
939
nsIXTFService*
893
nsContentUtils::GetXTFService()
940
nsContentUtils::GetXTFService()
894
{
941
{
895
  if (!sXTFService) {
942
  if (!sXTFService) {
896
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
943
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
897
    if (NS_FAILED(rv)) {
944
    if (NS_FAILED(rv)) {
 Lines 6538-6554   nsContentUtils::URIInheritsSecurityConte Link Here 
6538
                             aResult);
6585
                             aResult);
6539
}
6586
}
6540
6587
6541
// static
6588
// static
6542
bool
6589
bool
6543
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6590
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6544
                                  nsIChannel* aChannel,
6591
                                  nsIChannel* aChannel,
6545
                                  nsIURI* aURI,
6592
                                  nsIURI* aURI,
6546
                                  bool aSetUpForAboutBlank)
6593
                                  bool aSetUpForAboutBlank,
6594
                                  bool aForceOwner)
6547
{
6595
{
6548
  //
6596
  //
6549
  // Set the owner of the channel, but only for channels that can't
6597
  // Set the owner of the channel, but only for channels that can't
6550
  // provide their own security context.
6598
  // provide their own security context.
6551
  //
6599
  //
6552
  // XXX: It seems wrong that the owner is ignored - even if one is
6600
  // XXX: It seems wrong that the owner is ignored - even if one is
6553
  //      supplied) unless the URI is javascript or data or about:blank.
6601
  //      supplied) unless the URI is javascript or data or about:blank.
6554
  // XXX: If this is ever changed, check all callers for what owners
6602
  // XXX: If this is ever changed, check all callers for what owners
 Lines 6556-6578   nsContentUtils::SetUpChannelOwner(nsIPri Link Here 
6556
  //      comments in nsDocShell::LoadURI where we fall back on
6604
  //      comments in nsDocShell::LoadURI where we fall back on
6557
  //      inheriting the owner if called from chrome.  That would be
6605
  //      inheriting the owner if called from chrome.  That would be
6558
  //      very wrong if this code changed anything but channels that
6606
  //      very wrong if this code changed anything but channels that
6559
  //      can't provide their own security context!
6607
  //      can't provide their own security context!
6560
  //
6608
  //
6561
  //      (Currently chrome URIs set the owner when they are created!
6609
  //      (Currently chrome URIs set the owner when they are created!
6562
  //      So setting a NULL owner would be bad!)
6610
  //      So setting a NULL owner would be bad!)
6563
  //
6611
  //
6612
  // If aForceOwner is true, the owner will be set, even for a channel that
6613
  // can provide its own security context. This is used for the HTML5 IFRAME
6614
  // sandbox attribute, so we can force the channel (and its document) to
6615
  // explicitly have a null principal.
6564
  bool inherit;
6616
  bool inherit;
6565
  // We expect URIInheritsSecurityContext to return success for an
6617
  // We expect URIInheritsSecurityContext to return success for an
6566
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6618
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6567
  // This condition needs to match the one in nsDocShell::InternalLoad where
6619
  // This condition needs to match the one in nsDocShell::InternalLoad where
6568
  // we're checking for things that will use the owner.
6620
  // we're checking for things that will use the owner.
6569
  if (NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6621
  if (aForceOwner || ((NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6570
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))) {
6622
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))))) {
6623
    // Be certain that aForceOwner is only set for null principals
6624
    if (aForceOwner) {
6625
      nsCOMPtr<nsIURI> ownerURI;
6626
      nsresult rv = aLoadingPrincipal->GetURI(getter_AddRefs(ownerURI));
6627
      MOZ_ASSERT(NS_SUCCEEDED(rv) && SchemeIs(ownerURI, NS_NULLPRINCIPAL_SCHEME));
6628
    }
6571
    aChannel->SetOwner(aLoadingPrincipal);
6629
    aChannel->SetOwner(aLoadingPrincipal);
6572
    return true;
6630
    return true;
6573
  }
6631
  }
6574
6632
6575
  //
6633
  //
6576
  // file: uri special-casing
6634
  // file: uri special-casing
6577
  //
6635
  //
6578
  // 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
(-)a/content/base/src/nsDocument.cpp (+9 lines)
Line     Link Here 
 Lines 2363-2378   nsDocument::StartDocumentLoad(const char Link Here 
2363
    FindCharInReadable(';', semicolon, end);
2363
    FindCharInReadable(';', semicolon, end);
2364
    SetContentTypeInternal(Substring(start, semicolon));
2364
    SetContentTypeInternal(Substring(start, semicolon));
2365
  }
2365
  }
2366
2366
2367
  RetrieveRelevantHeaders(aChannel);
2367
  RetrieveRelevantHeaders(aChannel);
2368
2368
2369
  mChannel = aChannel;
2369
  mChannel = aChannel;
2370
2370
2371
  // If this document is being loaded by a docshell, copy its sandbox flags
2372
  // to the document. These are immutable after being set here.
2373
  nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aContainer);
2374
2375
  if (docShell) {
2376
    nsresult rv = docShell->GetSandboxFlags(&mSandboxFlags);
2377
    NS_ENSURE_SUCCESS(rv, rv);
2378
  }
2379
2371
  nsresult rv = InitCSP();
2380
  nsresult rv = InitCSP();
2372
  NS_ENSURE_SUCCESS(rv, rv);
2381
  NS_ENSURE_SUCCESS(rv, rv);
2373
2382
2374
  return NS_OK;
2383
  return NS_OK;
2375
}
2384
}
2376
2385
2377
nsresult
2386
nsresult
2378
nsDocument::InitCSP()
2387
nsDocument::InitCSP()
(-)a/content/base/src/nsFrameLoader.cpp (+34 lines)
Line     Link Here 
 Lines 77-92    Link Here 
77
#include "mozilla/GuardObjects.h"
77
#include "mozilla/GuardObjects.h"
78
#include "mozilla/Preferences.h"
78
#include "mozilla/Preferences.h"
79
#include "mozilla/unused.h"
79
#include "mozilla/unused.h"
80
#include "mozilla/dom/Element.h"
80
#include "mozilla/dom/Element.h"
81
#include "mozilla/layout/RenderFrameParent.h"
81
#include "mozilla/layout/RenderFrameParent.h"
82
82
83
#include "jsapi.h"
83
#include "jsapi.h"
84
84
85
#include "nsHTMLIFrameElement.h"
86
#include "nsSandboxFlags.h"
87
85
using namespace mozilla;
88
using namespace mozilla;
86
using namespace mozilla::dom;
89
using namespace mozilla::dom;
87
using namespace mozilla::layers;
90
using namespace mozilla::layers;
88
using namespace mozilla::layout;
91
using namespace mozilla::layout;
89
typedef FrameMetrics::ViewID ViewID;
92
typedef FrameMetrics::ViewID ViewID;
90
93
91
class nsAsyncDocShellDestroyer : public nsRunnable
94
class nsAsyncDocShellDestroyer : public nsRunnable
92
{
95
{
 Lines 438-453   nsFrameLoader::ReallyStartLoadingInterna Link Here 
438
  // Just to be safe, recheck uri.
441
  // Just to be safe, recheck uri.
439
  rv = CheckURILoad(mURIToLoad);
442
  rv = CheckURILoad(mURIToLoad);
440
  NS_ENSURE_SUCCESS(rv, rv);
443
  NS_ENSURE_SUCCESS(rv, rv);
441
444
442
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
445
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
443
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
446
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
444
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
447
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
445
448
449
  // Is this an <iframe> with a sandbox attribute or a parent which is
450
  // sandboxed ?
451
  nsHTMLIFrameElement* iframe =
452
    nsHTMLIFrameElement::FromContent(mOwnerContent);
453
454
  PRUint32 sandboxFlags = 0;
455
456
  if (iframe) {
457
    sandboxFlags = iframe->GetSandboxFlags();
458
459
    // The OwnerDoc of an iframe node is the parent document of that <iframe>.
460
    PRUint32 parentSandboxFlags = iframe->OwnerDoc() ?
461
      iframe->OwnerDoc()->SandboxFlags() : 0;
462
463
    if (sandboxFlags || parentSandboxFlags) {
464
      // The child can only add restrictions, not remove them.
465
      sandboxFlags |= parentSandboxFlags;
466
467
      mDocShell->SetSandboxFlags(sandboxFlags);
468
469
      // Set up the actual sandboxing for plugins as specified.
470
      if (sandboxFlags & SANDBOXED_PLUGINS) {
471
        mDocShell->SetAllowPlugins(false);
472
      }
473
    }
474
  }
475
476
  // If this is an <iframe> and it's sandboxed with respect to origin
477
  // we will set it up with a null principal later in nsDocShell::DoURILoad.
478
  // We do it there to correctly sandbox content that was loaded into
479
  // the iframe via other methods than the src attribute.
446
  // We'll use our principal, not that of the document loaded inside us.  This
480
  // We'll use our principal, not that of the document loaded inside us.  This
447
  // is very important; needed to prevent XSS attacks on documents loaded in
481
  // is very important; needed to prevent XSS attacks on documents loaded in
448
  // subframes!
482
  // subframes!
449
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
483
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
450
484
451
  nsCOMPtr<nsIURI> referrer;
485
  nsCOMPtr<nsIURI> referrer;
452
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
486
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
453
  NS_ENSURE_SUCCESS(rv, rv);
487
  NS_ENSURE_SUCCESS(rv, rv);
(-)a/content/base/src/nsGkAtomList.h (+5 lines)
Line     Link Here 
 Lines 62-78   GK_ATOM(actuate, "actuate") Link Here 
62
GK_ATOM(address, "address")
62
GK_ATOM(address, "address")
63
GK_ATOM(after, "after")
63
GK_ATOM(after, "after")
64
GK_ATOM(after_end, "after_end")
64
GK_ATOM(after_end, "after_end")
65
GK_ATOM(after_start, "after_start")
65
GK_ATOM(after_start, "after_start")
66
GK_ATOM(align, "align")
66
GK_ATOM(align, "align")
67
GK_ATOM(alink, "alink")
67
GK_ATOM(alink, "alink")
68
GK_ATOM(all, "all")
68
GK_ATOM(all, "all")
69
GK_ATOM(allowevents, "allowevents")
69
GK_ATOM(allowevents, "allowevents")
70
GK_ATOM(allowforms, "allow-forms")
70
GK_ATOM(allownegativeassertions, "allownegativeassertions")
71
GK_ATOM(allownegativeassertions, "allownegativeassertions")
72
GK_ATOM(allowsameorigin, "allow-same-origin")
73
GK_ATOM(allowscripts, "allow-scripts")
74
GK_ATOM(allowtopnavigation, "allow-top-navigation")
71
GK_ATOM(allowuntrusted, "allowuntrusted")
75
GK_ATOM(allowuntrusted, "allowuntrusted")
72
GK_ATOM(alt, "alt")
76
GK_ATOM(alt, "alt")
73
GK_ATOM(alternate, "alternate")
77
GK_ATOM(alternate, "alternate")
74
GK_ATOM(always, "always")
78
GK_ATOM(always, "always")
75
GK_ATOM(ancestor, "ancestor")
79
GK_ATOM(ancestor, "ancestor")
76
GK_ATOM(ancestorOrSelf, "ancestor-or-self")
80
GK_ATOM(ancestorOrSelf, "ancestor-or-self")
77
GK_ATOM(_and, "and")
81
GK_ATOM(_and, "and")
78
GK_ATOM(any, "any")
82
GK_ATOM(any, "any")
 Lines 837-852   GK_ATOM(rowspan, "rowspan") Link Here 
837
GK_ATOM(rp, "rp")
841
GK_ATOM(rp, "rp")
838
GK_ATOM(rt, "rt")
842
GK_ATOM(rt, "rt")
839
GK_ATOM(rtl, "rtl")
843
GK_ATOM(rtl, "rtl")
840
GK_ATOM(ruby, "ruby")
844
GK_ATOM(ruby, "ruby")
841
GK_ATOM(rule, "rule")
845
GK_ATOM(rule, "rule")
842
GK_ATOM(rules, "rules")
846
GK_ATOM(rules, "rules")
843
GK_ATOM(s, "s")
847
GK_ATOM(s, "s")
844
GK_ATOM(samp, "samp")
848
GK_ATOM(samp, "samp")
849
GK_ATOM(sandbox, "sandbox")
845
GK_ATOM(sbattr, "sbattr")
850
GK_ATOM(sbattr, "sbattr")
846
GK_ATOM(scale, "scale")
851
GK_ATOM(scale, "scale")
847
GK_ATOM(scan, "scan")
852
GK_ATOM(scan, "scan")
848
GK_ATOM(scheme, "scheme")
853
GK_ATOM(scheme, "scheme")
849
GK_ATOM(scope, "scope")
854
GK_ATOM(scope, "scope")
850
GK_ATOM(scoped, "scoped")
855
GK_ATOM(scoped, "scoped")
851
GK_ATOM(screen, "screen")
856
GK_ATOM(screen, "screen")
852
GK_ATOM(screenX, "screenX")
857
GK_ATOM(screenX, "screenX")
(-)a/content/base/src/nsSandboxFlags.h (+58 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
/*
7
 * Constant flags that describe how a document is sandboxed according to the
8
 * HTML5 spec.
9
 */
10
11
#ifndef nsSandboxFlags_h___
12
#define nsSandboxFlags_h___
13
14
/**
15
 * This flag prevents content from navigating browsing contexts other than
16
 * the sandboxed browsing context itself (or browsing contexts further
17
 * nested inside it), and the top-level browsing context.
18
 */
19
const unsigned long SANDBOXED_NAVIGATION  = 0x1;
20
21
/**
22
 * This flag prevents content from navigating their top-level browsing
23
 * context.
24
 */
25
const unsigned long SANDBOXED_TOPLEVEL_NAVIGATION = 0x2;
26
27
/**
28
 * This flag prevents content from instantiating plugins, whether using the
29
 * embed element, the object element, the applet element, or through
30
 * navigation of a nested browsing context, unless those plugins can be
31
 * secured.
32
 */
33
const unsigned long SANDBOXED_PLUGINS = 0x4;
34
35
/**
36
 * This flag forces content into a unique origin, thus preventing it from
37
 * accessing other content from the same origin.
38
 * This flag also prevents script from reading from or writing to the
39
 * document.cookie IDL attribute, and blocks access to localStorage.
40
 */
41
const unsigned long SANDBOXED_ORIGIN = 0x8;
42
43
/**
44
 * This flag blocks form submission.
45
 */
46
const unsigned long SANDBOXED_FORMS = 0x10;
47
48
/**
49
 * This flag blocks script execution.
50
 */
51
const unsigned long SANDBOXED_SCRIPTS = 0x20;
52
53
/**
54
 * This flag blocks features that trigger automatically, such as
55
 * automatically playing a video or automatically focusing a form control.
56
 */
57
const unsigned long SANDBOXED_AUTOMATIC_FEATURES = 0x40;
58
#endif
(-)a/content/base/src/nsScriptLoader.cpp (+12 lines)
Line     Link Here 
 Lines 37-52    Link Here 
37
#include "nsIContentSecurityPolicy.h"
37
#include "nsIContentSecurityPolicy.h"
38
#include "prlog.h"
38
#include "prlog.h"
39
#include "nsIChannelPolicy.h"
39
#include "nsIChannelPolicy.h"
40
#include "nsChannelPolicy.h"
40
#include "nsChannelPolicy.h"
41
#include "nsCRT.h"
41
#include "nsCRT.h"
42
#include "nsContentCreatorFunctions.h"
42
#include "nsContentCreatorFunctions.h"
43
#include "nsGenericElement.h"
43
#include "nsGenericElement.h"
44
#include "nsCrossSiteListenerProxy.h"
44
#include "nsCrossSiteListenerProxy.h"
45
#include "nsSandboxFlags.h"
45
46
46
#include "mozilla/FunctionTimer.h"
47
#include "mozilla/FunctionTimer.h"
47
#include "mozilla/CORSMode.h"
48
#include "mozilla/CORSMode.h"
48
49
49
#ifdef PR_LOGGING
50
#ifdef PR_LOGGING
50
static PRLogModuleInfo* gCspPRLog;
51
static PRLogModuleInfo* gCspPRLog;
51
#endif
52
#endif
52
53
 Lines 272-287   nsScriptLoader::StartLoad(nsScriptLoadRe Link Here 
272
  if (!window) {
273
  if (!window) {
273
    return NS_ERROR_NULL_POINTER;
274
    return NS_ERROR_NULL_POINTER;
274
  }
275
  }
275
276
276
  nsIDocShell *docshell = window->GetDocShell();
277
  nsIDocShell *docshell = window->GetDocShell();
277
278
278
  nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
279
  nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
279
280
281
  // If this document is sandboxed without 'allow-scripts', abort.
282
  if (mDocument->SandboxFlags() & SANDBOXED_SCRIPTS) {
283
    // REVIEW : this probably isn't the right error..
284
    return NS_ERROR_DOM_SECURITY_ERR;
285
  }
286
280
  // check for a Content Security Policy to pass down to the channel
287
  // check for a Content Security Policy to pass down to the channel
281
  // that will be created to load the script
288
  // that will be created to load the script
282
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
289
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
283
  nsCOMPtr<nsIContentSecurityPolicy> csp;
290
  nsCOMPtr<nsIContentSecurityPolicy> csp;
284
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
291
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
285
  NS_ENSURE_SUCCESS(rv, rv);
292
  NS_ENSURE_SUCCESS(rv, rv);
286
  if (csp) {
293
  if (csp) {
287
    channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
294
    channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
 Lines 629-644   nsScriptLoader::ProcessScriptElement(nsI Link Here 
629
        "There can be only one parser-blocking script at a time");
636
        "There can be only one parser-blocking script at a time");
630
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
637
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
631
        "Parser-blocking scripts and XSLT scripts in the same doc!");
638
        "Parser-blocking scripts and XSLT scripts in the same doc!");
632
    mParserBlockingRequest = request;
639
    mParserBlockingRequest = request;
633
    return true;
640
    return true;
634
  }
641
  }
635
642
636
  // inline script
643
  // inline script
644
  // Is this document sandboxed without 'allow-scripts'?
645
  if (mDocument->SandboxFlags() & SANDBOXED_SCRIPTS) {
646
    return false;
647
  }
648
637
  nsCOMPtr<nsIContentSecurityPolicy> csp;
649
  nsCOMPtr<nsIContentSecurityPolicy> csp;
638
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
650
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
639
  NS_ENSURE_SUCCESS(rv, false);
651
  NS_ENSURE_SUCCESS(rv, false);
640
652
641
  if (csp) {
653
  if (csp) {
642
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
654
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
643
    bool inlineOK;
655
    bool inlineOK;
644
    rv = csp->GetAllowsInlineScript(&inlineOK);
656
    rv = csp->GetAllowsInlineScript(&inlineOK);
(-)a/content/events/src/nsEventListenerManager.cpp (+7 lines)
Line     Link Here 
 Lines 50-65    Link Here 
50
#include "nsDOMJSUtils.h"
50
#include "nsDOMJSUtils.h"
51
#include "nsDOMScriptObjectHolder.h"
51
#include "nsDOMScriptObjectHolder.h"
52
#include "nsDataHashtable.h"
52
#include "nsDataHashtable.h"
53
#include "nsCOMArray.h"
53
#include "nsCOMArray.h"
54
#include "nsEventListenerService.h"
54
#include "nsEventListenerService.h"
55
#include "nsIContentSecurityPolicy.h"
55
#include "nsIContentSecurityPolicy.h"
56
#include "nsJSEnvironment.h"
56
#include "nsJSEnvironment.h"
57
#include "xpcpublic.h"
57
#include "xpcpublic.h"
58
#include "nsSandboxFlags.h"
58
59
59
using namespace mozilla::dom;
60
using namespace mozilla::dom;
60
using namespace mozilla::hal;
61
using namespace mozilla::hal;
61
62
62
#define EVENT_TYPE_EQUALS( ls, type, userType ) \
63
#define EVENT_TYPE_EQUALS( ls, type, userType ) \
63
  (ls->mEventType == type && \
64
  (ls->mEventType == type && \
64
  (ls->mEventType != NS_USER_DEFINED_EVENT || ls->mTypeAtom == userType))
65
  (ls->mEventType != NS_USER_DEFINED_EVENT || ls->mTypeAtom == userType))
65
66
 Lines 561-576   nsEventListenerManager::AddScriptEventLi Link Here 
561
    // loaded as data.
562
    // loaded as data.
562
    return NS_OK;
563
    return NS_OK;
563
  }
564
  }
564
565
565
  nsresult rv = NS_OK;
566
  nsresult rv = NS_OK;
566
  // return early preventing the event listener from being added
567
  // return early preventing the event listener from being added
567
  // 'doc' is fetched above
568
  // 'doc' is fetched above
568
  if (doc) {
569
  if (doc) {
570
    // Don't allow adding an event listener if the document is sandboxed
571
    // without 'allow-scripts'.
572
    if (doc->SandboxFlags() & SANDBOXED_SCRIPTS) {
573
      return NS_ERROR_DOM_SECURITY_ERR;
574
    }
575
569
    nsCOMPtr<nsIContentSecurityPolicy> csp;
576
    nsCOMPtr<nsIContentSecurityPolicy> csp;
570
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
577
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
571
    NS_ENSURE_SUCCESS(rv, rv);
578
    NS_ENSURE_SUCCESS(rv, rv);
572
579
573
    if (csp) {
580
    if (csp) {
574
      bool inlineOK;
581
      bool inlineOK;
575
      rv = csp->GetAllowsInlineScript(&inlineOK);
582
      rv = csp->GetAllowsInlineScript(&inlineOK);
576
      NS_ENSURE_SUCCESS(rv, rv);
583
      NS_ENSURE_SUCCESS(rv, rv);
(-)a/content/html/content/src/nsHTMLFormElement.cpp (-1 / +12 lines)
Line     Link Here 
 Lines 48-63    Link Here 
48
48
49
#include "mozAutoDocUpdate.h"
49
#include "mozAutoDocUpdate.h"
50
#include "nsIHTMLCollection.h"
50
#include "nsIHTMLCollection.h"
51
51
52
#include "nsIConstraintValidation.h"
52
#include "nsIConstraintValidation.h"
53
53
54
#include "nsIDOMHTMLButtonElement.h"
54
#include "nsIDOMHTMLButtonElement.h"
55
#include "dombindings.h"
55
#include "dombindings.h"
56
#include "nsSandboxFlags.h"
56
57
57
using namespace mozilla::dom;
58
using namespace mozilla::dom;
58
59
59
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
60
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
60
61
61
static const PRUint8 NS_FORM_AUTOCOMPLETE_ON  = 1;
62
static const PRUint8 NS_FORM_AUTOCOMPLETE_ON  = 1;
62
static const PRUint8 NS_FORM_AUTOCOMPLETE_OFF = 0;
63
static const PRUint8 NS_FORM_AUTOCOMPLETE_OFF = 0;
63
64
 Lines 648-664   nsHTMLFormElement::DoSubmitOrReset(nsEve Link Here 
648
    return DoReset();
649
    return DoReset();
649
  }
650
  }
650
651
651
  if (NS_FORM_SUBMIT == aMessage) {
652
  if (NS_FORM_SUBMIT == aMessage) {
652
    // Don't submit if we're not in a document.
653
    // Don't submit if we're not in a document.
653
    if (!doc) {
654
    if (!doc) {
654
      return NS_OK;
655
      return NS_OK;
655
    }
656
    }
656
    return DoSubmit(aEvent);
657
    // Don't submit if we're in a sandboxed frame and form submit
658
    // is disabled.
659
    return (doc->SandboxFlags() & SANDBOXED_FORMS) ? NS_OK : DoSubmit(aEvent);
657
  }
660
  }
658
661
659
  MOZ_ASSERT(false);
662
  MOZ_ASSERT(false);
660
  return NS_OK;
663
  return NS_OK;
661
}
664
}
662
665
663
nsresult
666
nsresult
664
nsHTMLFormElement::DoReset()
667
nsHTMLFormElement::DoReset()
 Lines 1649-1664   nsHTMLFormElement::CheckValidFormSubmiss Link Here 
1649
   * TODO: the check for observer should be removed later when HTML5 Forms will
1652
   * TODO: the check for observer should be removed later when HTML5 Forms will
1650
   * be spread enough and authors will assume forms can't be submitted when
1653
   * be spread enough and authors will assume forms can't be submitted when
1651
   * invalid. See bug 587671.
1654
   * invalid. See bug 587671.
1652
   */
1655
   */
1653
1656
1654
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1657
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1655
               "We shouldn't be there if novalidate is set!");
1658
               "We shouldn't be there if novalidate is set!");
1656
1659
1660
  // Don't do validation for a form submit done by a sandboxed document that
1661
  // doesn't have 'allow-forms', the submit will have been blocked and the
1662
  // HTML5 spec says we shouldn't validate in this case.
1663
  nsIDocument* doc = GetCurrentDoc();
1664
  if (doc && (doc->SandboxFlags() & SANDBOXED_FORMS)) {
1665
      return true;
1666
  }
1667
1657
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1668
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1658
  // we have to check the validity of the form.
1669
  // we have to check the validity of the form.
1659
  nsCOMPtr<nsIObserverService> service =
1670
  nsCOMPtr<nsIObserverService> service =
1660
    mozilla::services::GetObserverService();
1671
    mozilla::services::GetObserverService();
1661
  if (!service) {
1672
  if (!service) {
1662
    NS_WARNING("No observer service available!");
1673
    NS_WARNING("No observer service available!");
1663
    return true;
1674
    return true;
1664
  }
1675
  }
(-)a/content/html/content/src/nsHTMLIFrameElement.cpp (-8 / +30 lines)
Line     Link Here 
 Lines 1-24    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
#include "mozilla/Util.h"
6
#include "mozilla/Util.h"
7
7
8
#include "nsHTMLIFrameElement.h"
8
#include "nsHTMLIFrameElement.h"
9
#include "nsIDOMDocument.h"
10
#include "nsIDOMSVGDocument.h"
11
#include "nsGkAtoms.h"
12
#include "nsIDocument.h"
13
#include "nsMappedAttributes.h"
14
#include "nsDOMError.h"
15
#include "nsRuleData.h"
16
#include "nsStyleConsts.h"
17
9
18
using namespace mozilla;
10
using namespace mozilla;
19
using namespace mozilla::dom;
11
using namespace mozilla::dom;
20
12
21
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
13
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
22
14
23
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
15
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
24
                                         FromParser aFromParser)
16
                                         FromParser aFromParser)
 Lines 53-68   NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Link Here 
53
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
45
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
54
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
46
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
55
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
47
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
56
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
48
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
57
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
49
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
58
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
50
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
59
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
51
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
60
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
52
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
53
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Sandbox, sandbox)
61
54
62
void
55
void
63
nsHTMLIFrameElement::GetItemValueText(nsAString& aValue)
56
nsHTMLIFrameElement::GetItemValueText(nsAString& aValue)
64
{
57
{
65
  GetSrc(aValue);
58
  GetSrc(aValue);
66
}
59
}
67
60
68
void
61
void
 Lines 202-209   nsHTMLIFrameElement::IsAttributeMapped(c Link Here 
202
195
203
196
204
nsMapRuleToAttributesFunc
197
nsMapRuleToAttributesFunc
205
nsHTMLIFrameElement::GetAttributeMappingFunction() const
198
nsHTMLIFrameElement::GetAttributeMappingFunction() const
206
{
199
{
207
  return &MapAttributesIntoRule;
200
  return &MapAttributesIntoRule;
208
}
201
}
209
202
203
nsresult
204
nsHTMLIFrameElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
205
                                    const nsAttrValue* aValue,
206
                                    bool aNotify)
207
{
208
  if (aName == nsGkAtoms::sandbox && aNameSpaceID == kNameSpaceID_None) {
209
    // Parse the new value of the sandbox attribute, and if we have a docshell
210
    // set its sandbox flags appropriately.
211
    if (mFrameLoader) {
212
      nsCOMPtr<nsIDocShell> docshell = mFrameLoader->GetExistingDocShell();
213
214
      if (docshell) {
215
        PRUint32 newFlags = 0;
216
        // If a NULL aValue is passed in, we want to clear the sandbox flags
217
        // which we will do by setting them to 0.
218
        if (aValue) {
219
          nsAutoString strValue;
220
          aValue->ToString(strValue);
221
          newFlags = nsContentUtils::ParseSandboxAttributeToFlags(
222
            strValue);
223
        }
224
        docshell->SetSandboxFlags(newFlags);
225
      }
226
    }
227
  }
228
  return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
229
                                            aNotify);
230
231
}
(-)a/content/html/content/src/nsHTMLIFrameElement.h (+32 lines)
Line     Link Here 
 Lines 1-16    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
#include "nsGenericHTMLFrameElement.h"
6
#include "nsGenericHTMLFrameElement.h"
7
#include "nsIDOMHTMLIFrameElement.h"
7
#include "nsIDOMHTMLIFrameElement.h"
8
#include "nsIDOMGetSVGDocument.h"
8
#include "nsIDOMGetSVGDocument.h"
9
#include "nsIDOMSVGDocument.h"
10
#include "nsGkAtoms.h"
11
#include "nsIDocument.h"
12
#include "nsMappedAttributes.h"
13
#include "nsDOMError.h"
14
#include "nsRuleData.h"
15
#include "nsStyleConsts.h"
16
#include "nsContentUtils.h"
9
17
10
class nsHTMLIFrameElement : public nsGenericHTMLFrameElement
18
class nsHTMLIFrameElement : public nsGenericHTMLFrameElement
11
                          , public nsIDOMHTMLIFrameElement
19
                          , public nsIDOMHTMLIFrameElement
12
                          , public nsIDOMGetSVGDocument
20
                          , public nsIDOMGetSVGDocument
13
{
21
{
14
public:
22
public:
15
  nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
23
  nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
16
                      mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
24
                      mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
 Lines 41-52   public: Link Here 
41
                                nsAttrValue& aResult);
49
                                nsAttrValue& aResult);
42
  NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
50
  NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
43
  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
51
  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
44
52
45
  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
53
  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
46
  virtual nsXPCClassInfo* GetClassInfo();
54
  virtual nsXPCClassInfo* GetClassInfo();
47
  virtual nsIDOMNode* AsDOMNode() { return this; }
55
  virtual nsIDOMNode* AsDOMNode() { return this; }
48
56
57
  virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
58
                                const nsAttrValue* aValue,
59
                                bool aNotify);
60
61
  PRUint32 GetSandboxFlags()
62
  {
63
    nsAutoString sandboxAttr;
64
65
    if (GetAttr(kNameSpaceID_None, nsGkAtoms::sandbox, sandboxAttr)) {
66
      return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
67
    }
68
69
    // No sandbox attribute, no sandbox flags.
70
    return 0;
71
  }
72
73
  static nsHTMLIFrameElement* FromContent(nsIContent *aContent)
74
  {
75
    if (aContent->IsHTML(nsGkAtoms::iframe)) {
76
      return static_cast<nsHTMLIFrameElement*>(aContent);
77
    }
78
    return nsnull;
79
  }
80
49
protected:
81
protected:
50
  virtual void GetItemValueText(nsAString& text);
82
  virtual void GetItemValueText(nsAString& text);
51
  virtual void SetItemValueText(const nsAString& text);
83
  virtual void SetItemValueText(const nsAString& text);
52
};
84
};
(-)a/content/html/document/src/nsHTMLDocument.cpp (+13 lines)
Line     Link Here 
 Lines 97-112    Link Here 
97
#include "prprf.h"
97
#include "prprf.h"
98
#include "mozilla/dom/Element.h"
98
#include "mozilla/dom/Element.h"
99
#include "mozilla/Preferences.h"
99
#include "mozilla/Preferences.h"
100
#include "nsMimeTypes.h"
100
#include "nsMimeTypes.h"
101
#include "nsIRequest.h"
101
#include "nsIRequest.h"
102
#include "nsHtml5TreeOpExecutor.h"
102
#include "nsHtml5TreeOpExecutor.h"
103
#include "nsHtml5Parser.h"
103
#include "nsHtml5Parser.h"
104
#include "nsIDOMJSWindow.h"
104
#include "nsIDOMJSWindow.h"
105
#include "nsSandboxFlags.h"
105
106
106
using namespace mozilla;
107
using namespace mozilla;
107
using namespace mozilla::dom;
108
using namespace mozilla::dom;
108
109
109
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
110
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
110
111
111
#include "prmem.h"
112
#include "prmem.h"
112
#include "prtime.h"
113
#include "prtime.h"
 Lines 1215-1230   nsHTMLDocument::GetCookie(nsAString& aCo Link Here 
1215
{
1216
{
1216
  aCookie.Truncate(); // clear current cookie in case service fails;
1217
  aCookie.Truncate(); // clear current cookie in case service fails;
1217
                      // no cookie isn't an error condition.
1218
                      // no cookie isn't an error condition.
1218
1219
1219
  if (mDisableCookieAccess) {
1220
  if (mDisableCookieAccess) {
1220
    return NS_OK;
1221
    return NS_OK;
1221
  }
1222
  }
1222
1223
1224
  // If the document's sandboxed origin flag is set, access to read cookies
1225
  // is prohibited.
1226
  if (mSandboxFlags & SANDBOXED_ORIGIN) {
1227
    return NS_ERROR_DOM_SECURITY_ERR;
1228
  }
1229
  
1223
  // not having a cookie service isn't an error
1230
  // not having a cookie service isn't an error
1224
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1231
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1225
  if (service) {
1232
  if (service) {
1226
    // Get a URI from the document principal. We use the original
1233
    // Get a URI from the document principal. We use the original
1227
    // codebase in case the codebase was changed by SetDomain
1234
    // codebase in case the codebase was changed by SetDomain
1228
    nsCOMPtr<nsIURI> codebaseURI;
1235
    nsCOMPtr<nsIURI> codebaseURI;
1229
    NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
1236
    NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
1230
1237
 Lines 1245-1260   nsHTMLDocument::GetCookie(nsAString& aCo Link Here 
1245
1252
1246
NS_IMETHODIMP
1253
NS_IMETHODIMP
1247
nsHTMLDocument::SetCookie(const nsAString& aCookie)
1254
nsHTMLDocument::SetCookie(const nsAString& aCookie)
1248
{
1255
{
1249
  if (mDisableCookieAccess) {
1256
  if (mDisableCookieAccess) {
1250
    return NS_OK;
1257
    return NS_OK;
1251
  }
1258
  }
1252
1259
1260
  // If the document's sandboxed origin flag is set, access to write cookies
1261
  // is prohibited.
1262
  if (mSandboxFlags & SANDBOXED_ORIGIN) {
1263
    return NS_ERROR_DOM_SECURITY_ERR;
1264
  }
1265
1253
  // not having a cookie service isn't an error
1266
  // not having a cookie service isn't an error
1254
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1267
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1255
  if (service && mDocumentURI) {
1268
  if (service && mDocumentURI) {
1256
    nsCOMPtr<nsIPrompt> prompt;
1269
    nsCOMPtr<nsIPrompt> prompt;
1257
    nsCOMPtr<nsPIDOMWindow> window = GetWindow();
1270
    nsCOMPtr<nsPIDOMWindow> window = GetWindow();
1258
    if (window) {
1271
    if (window) {
1259
      window->GetPrompter(getter_AddRefs(prompt));
1272
      window->GetPrompter(getter_AddRefs(prompt));
1260
    }
1273
    }
(-)a/docshell/base/Makefile.in (+1 lines)
Line     Link Here 
 Lines 85-93   include $(topsrcdir)/config/config.mk Link Here 
85
include $(topsrcdir)/ipc/chromium/chromium-config.mk
85
include $(topsrcdir)/ipc/chromium/chromium-config.mk
86
include $(topsrcdir)/config/rules.mk
86
include $(topsrcdir)/config/rules.mk
87
87
88
LOCAL_INCLUDES += \
88
LOCAL_INCLUDES += \
89
  -I$(srcdir)/../shistory/src \
89
  -I$(srcdir)/../shistory/src \
90
  -I$(topsrcdir)/dom/base \
90
  -I$(topsrcdir)/dom/base \
91
  -I$(topsrcdir)/layout/base \
91
  -I$(topsrcdir)/layout/base \
92
  -I$(topsrcdir)/xpcom/ds \
92
  -I$(topsrcdir)/xpcom/ds \
93
  -I$(topsrcdir)/content/base/src \
93
  $(NULL)
94
  $(NULL)
(-)a/docshell/base/nsDocShell.cpp (-2 / +101 lines)
Line     Link Here 
 Lines 177-192    Link Here 
177
#include "nsIWebBrowserPrint.h"
177
#include "nsIWebBrowserPrint.h"
178
#endif
178
#endif
179
179
180
#include "nsPluginError.h"
180
#include "nsPluginError.h"
181
#include "nsContentUtils.h"
181
#include "nsContentUtils.h"
182
#include "nsContentErrors.h"
182
#include "nsContentErrors.h"
183
#include "nsIChannelPolicy.h"
183
#include "nsIChannelPolicy.h"
184
#include "nsIContentSecurityPolicy.h"
184
#include "nsIContentSecurityPolicy.h"
185
#include "nsSandboxFlags.h"
185
186
186
#include "nsXULAppAPI.h"
187
#include "nsXULAppAPI.h"
187
188
188
#include "nsDOMNavigationTiming.h"
189
#include "nsDOMNavigationTiming.h"
189
#include "nsITimedChannel.h"
190
#include "nsITimedChannel.h"
190
#include "mozilla/StartupTimeline.h"
191
#include "mozilla/StartupTimeline.h"
191
#include "nsIFrameMessageManager.h"
192
#include "nsIFrameMessageManager.h"
192
193
 Lines 728-743   nsDocShell::nsDocShell(): Link Here 
728
    mBusyFlags(BUSY_FLAGS_NONE),
729
    mBusyFlags(BUSY_FLAGS_NONE),
729
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
730
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
730
    mLoadType(0),
731
    mLoadType(0),
731
    mMarginWidth(-1),
732
    mMarginWidth(-1),
732
    mMarginHeight(-1),
733
    mMarginHeight(-1),
733
    mItemType(typeContent),
734
    mItemType(typeContent),
734
    mPreviousTransIndex(-1),
735
    mPreviousTransIndex(-1),
735
    mLoadedTransIndex(-1),
736
    mLoadedTransIndex(-1),
737
    mSandboxFlags(0),
736
    mCreated(false),
738
    mCreated(false),
737
    mAllowSubframes(true),
739
    mAllowSubframes(true),
738
    mAllowPlugins(true),
740
    mAllowPlugins(true),
739
    mAllowJavascript(true),
741
    mAllowJavascript(true),
740
    mAllowMetaRedirects(true),
742
    mAllowMetaRedirects(true),
741
    mAllowImages(true),
743
    mAllowImages(true),
742
    mAllowDNSPrefetch(true),
744
    mAllowDNSPrefetch(true),
743
    mAllowWindowControl(true),
745
    mAllowWindowControl(true),
 Lines 2972-2987   nsDocShell::FindItemWithName(const PRUni Link Here 
2972
            foundItem = nsnull;
2974
            foundItem = nsnull;
2973
        }
2975
        }
2974
2976
2975
        if (foundItem) {
2977
        if (foundItem) {
2976
            // We return foundItem here even if it's not an active
2978
            // We return foundItem here even if it's not an active
2977
            // item since all the names we've dealt with so far are
2979
            // item since all the names we've dealt with so far are
2978
            // special cases that we won't bother looking for further.
2980
            // special cases that we won't bother looking for further.
2979
2981
2982
            // If our document is sandboxed, we need to do some extra checks.
2983
            PRUint32 sandboxFlags = 0;
2984
2985
            nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor);
2986
2987
            if (doc) {
2988
                sandboxFlags = doc->SandboxFlags();
2989
            }
2990
2991
            if (sandboxFlags) {
2992
                nsCOMPtr<nsIDocShellTreeItem> root;
2993
                GetSameTypeRootTreeItem(getter_AddRefs(root));
2994
2995
                // Is the found item not a top level browsing context and not ourself ?
2996
                nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this);
2997
                if (foundItem != root && foundItem != selfAsItem) {
2998
                    // Are we an ancestor of the foundItem ?
2999
                    bool isAncestor = false;
3000
3001
                    nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
3002
                    GetSameTypeParent(getter_AddRefs(parentAsItem));
3003
3004
                    while (parentAsItem) {
3005
                        nsCOMPtr<nsIDocShellTreeItem> tmp;
3006
                        parentAsItem->GetParent(getter_AddRefs(tmp));
3007
3008
                        if (tmp && tmp == selfAsItem) {
3009
                            isAncestor = true;
3010
                            break;
3011
                        }
3012
                        parentAsItem = tmp;
3013
                    }
3014
3015
                    if (!isAncestor) {
3016
                        // No, we are not an ancestor and our document is
3017
                        // sandboxed, we can't allow this.
3018
                        foundItem = nsnull;
3019
                    }
3020
                } else {
3021
                    // Top level browsing context - is it an ancestor of ours ?
3022
                    nsCOMPtr<nsIDocShellTreeItem> tmp;
3023
                    GetSameTypeParent(getter_AddRefs(tmp));
3024
3025
                    while (tmp) {
3026
                        if (tmp && tmp == foundItem) {
3027
                            // This is an ancestor, and we are sandboxed.
3028
                            // Unless allow-top-navigation is set, we can't allow this.
3029
                            if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) {
3030
                              foundItem = nsnull;
3031
                            }
3032
                            break;
3033
                        }
3034
                        tmp->GetParent(getter_AddRefs(tmp));
3035
                    }
3036
                }
3037
            }
3038
2980
            foundItem.swap(*_retval);
3039
            foundItem.swap(*_retval);
2981
            return NS_OK;
3040
            return NS_OK;
2982
        }
3041
        }
2983
    }
3042
    }
2984
3043
2985
    // Keep looking
3044
    // Keep looking
2986
        
3045
        
2987
    // First we check our name.
3046
    // First we check our name.
 Lines 5012-5027   nsDocShell::SetIsAppTab(bool aIsAppTab) Link Here 
5012
NS_IMETHODIMP
5071
NS_IMETHODIMP
5013
nsDocShell::GetIsAppTab(bool *aIsAppTab)
5072
nsDocShell::GetIsAppTab(bool *aIsAppTab)
5014
{
5073
{
5015
  *aIsAppTab = mIsAppTab;
5074
  *aIsAppTab = mIsAppTab;
5016
  return NS_OK;
5075
  return NS_OK;
5017
}
5076
}
5018
5077
5019
NS_IMETHODIMP
5078
NS_IMETHODIMP
5079
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags)
5080
{
5081
    mSandboxFlags = aSandboxFlags;
5082
    return NS_OK;
5083
}
5084
5085
NS_IMETHODIMP
5086
nsDocShell::GetSandboxFlags(PRUint32  *aSandboxFlags)
5087
{
5088
    *aSandboxFlags = mSandboxFlags;
5089
    return NS_OK;
5090
}
5091
5092
NS_IMETHODIMP
5020
nsDocShell::SetVisibility(bool aVisibility)
5093
nsDocShell::SetVisibility(bool aVisibility)
5021
{
5094
{
5022
    if (!mContentViewer)
5095
    if (!mContentViewer)
5023
        return NS_OK;
5096
        return NS_OK;
5024
    if (aVisibility) {
5097
    if (aVisibility) {
5025
        mContentViewer->Show();
5098
        mContentViewer->Show();
5026
    }
5099
    }
5027
    else {
5100
    else {
 Lines 8250-8265   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
8250
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8323
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8251
        FindItemWithName(aWindowTarget, nsnull, this,
8324
        FindItemWithName(aWindowTarget, nsnull, this,
8252
                         getter_AddRefs(targetItem));
8325
                         getter_AddRefs(targetItem));
8253
8326
8254
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8327
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8255
        
8328
        
8256
        bool isNewWindow = false;
8329
        bool isNewWindow = false;
8257
        if (!targetDocShell) {
8330
        if (!targetDocShell) {
8331
            // If the docshell's document is sandboxed and was trying to
8332
            // navigate/load a frame it wasn't allowed to access, the
8333
            // FindItemWithName above will have returned null for the target
8334
            // item - we don't want to actually open a new window in this case
8335
            // though. Check if we are sandboxed and bail out here if so.
8336
            NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
8337
            nsIDocument* doc = mContentViewer->GetDocument();
8338
            PRUint32 sandboxFlags = 0;
8339
            sandboxFlags = doc->SandboxFlags();
8340
            if (sandboxFlags & SANDBOXED_NAVIGATION) {
8341
                return NS_ERROR_FAILURE;
8342
            }
8343
8258
            nsCOMPtr<nsIDOMWindow> win =
8344
            nsCOMPtr<nsIDOMWindow> win =
8259
                do_GetInterface(GetAsSupports(this));
8345
                do_GetInterface(GetAsSupports(this));
8260
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8346
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8261
8347
8262
            nsDependentString name(aWindowTarget);
8348
            nsDependentString name(aWindowTarget);
8263
            nsCOMPtr<nsIDOMWindow> newWin;
8349
            nsCOMPtr<nsIDOMWindow> newWin;
8264
            rv = win->Open(EmptyString(), // URL to load
8350
            rv = win->Open(EmptyString(), // URL to load
8265
                           name,          // window name
8351
                           name,          // window name
 Lines 9061-9078   nsDocShell::DoURILoad(nsIURI * aURI, Link Here 
9061
        }
9147
        }
9062
        // Set the referrer explicitly
9148
        // Set the referrer explicitly
9063
        if (aReferrerURI && aSendReferrer) {
9149
        if (aReferrerURI && aSendReferrer) {
9064
            // Referrer is currenly only set for link clicks here.
9150
            // Referrer is currenly only set for link clicks here.
9065
            httpChannel->SetReferrer(aReferrerURI);
9151
            httpChannel->SetReferrer(aReferrerURI);
9066
        }
9152
        }
9067
    }
9153
    }
9068
9154
9069
    nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner));
9155
    nsCOMPtr<nsIPrincipal> ownerPrincipal;
9070
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true);
9156
9157
    // If the content being loaded should be sandboxed with respect to origin
9158
    // we need to create a new null principal here, and then tell
9159
    // nsContentUtils::SetUpChannelOwner to force it to be set as the
9160
    // channel owner.
9161
    if (mSandboxFlags & SANDBOXED_ORIGIN) {
9162
        ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
9163
    } else {
9164
        // Not sandboxed - we allow the content to assume its natural owner.
9165
        ownerPrincipal = do_QueryInterface(aOwner);
9166
    }
9167
9168
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true,
9169
                                      (mSandboxFlags & SANDBOXED_ORIGIN));
9071
9170
9072
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
9171
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
9073
    if (scriptChannel) {
9172
    if (scriptChannel) {
9074
        // Allow execution against our context if the principals match
9173
        // Allow execution against our context if the principals match
9075
        scriptChannel->
9174
        scriptChannel->
9076
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
9175
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
9077
    }
9176
    }
9078
9177
(-)a/docshell/base/nsDocShell.h (+2 lines)
Line     Link Here 
 Lines 755-770   protected: Link Here 
755
    // Create() is called, the type is not expected to change.
755
    // Create() is called, the type is not expected to change.
756
    PRInt32                    mItemType;
756
    PRInt32                    mItemType;
757
757
758
    // Index into the SHTransaction list, indicating the previous and current
758
    // Index into the SHTransaction list, indicating the previous and current
759
    // transaction at the time that this DocShell begins to load
759
    // transaction at the time that this DocShell begins to load
760
    PRInt32                    mPreviousTransIndex;
760
    PRInt32                    mPreviousTransIndex;
761
    PRInt32                    mLoadedTransIndex;
761
    PRInt32                    mLoadedTransIndex;
762
762
763
    PRUint32                   mSandboxFlags;
764
763
    bool                       mCreated;
765
    bool                       mCreated;
764
    bool                       mAllowSubframes;
766
    bool                       mAllowSubframes;
765
    bool                       mAllowPlugins;
767
    bool                       mAllowPlugins;
766
    bool                       mAllowJavascript;
768
    bool                       mAllowJavascript;
767
    bool                       mAllowMetaRedirects;
769
    bool                       mAllowMetaRedirects;
768
    bool                       mAllowImages;
770
    bool                       mAllowImages;
769
    bool                       mAllowDNSPrefetch;
771
    bool                       mAllowDNSPrefetch;
770
    bool                       mAllowWindowControl;
772
    bool                       mAllowWindowControl;
(-)a/docshell/base/nsIDocShell.idl (-1 / +15 lines)
Line     Link Here 
 Lines 34-50   interface nsISHEntry; Link Here 
34
interface nsILayoutHistoryState;
34
interface nsILayoutHistoryState;
35
interface nsISecureBrowserUI;
35
interface nsISecureBrowserUI;
36
interface nsIDOMStorage;
36
interface nsIDOMStorage;
37
interface nsIPrincipal;
37
interface nsIPrincipal;
38
interface nsIWebBrowserPrint;
38
interface nsIWebBrowserPrint;
39
interface nsIVariant;
39
interface nsIVariant;
40
interface nsIPrivacyTransitionObserver;
40
interface nsIPrivacyTransitionObserver;
41
41
42
[scriptable, uuid(6f60ac96-fa2c-41a5-92b4-29aaadbd7a7b)]
42
[scriptable, uuid(9b283337-097d-4fa8-a2da-916318eaf828)]
43
interface nsIDocShell : nsISupports
43
interface nsIDocShell : nsISupports
44
{
44
{
45
  /**
45
  /**
46
   * Loads a given URI.  This will give priority to loading the requested URI
46
   * Loads a given URI.  This will give priority to loading the requested URI
47
   * in the object implementing	this interface.  If it can't be loaded here
47
   * in the object implementing	this interface.  If it can't be loaded here
48
   * however, the URL dispatcher will go through its normal process of content
48
   * however, the URL dispatcher will go through its normal process of content
49
   * loading.
49
   * loading.
50
   *
50
   *
 Lines 588-596   interface nsIDocShell : nsISupports Link Here 
588
   */
588
   */
589
  attribute bool isBrowserFrame;
589
  attribute bool isBrowserFrame;
590
590
591
  /*
591
  /*
592
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
592
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
593
   * indirectly?
593
   * indirectly?
594
   */
594
   */
595
  readonly attribute bool containedInBrowserFrame;
595
  readonly attribute bool containedInBrowserFrame;
596
597
  /**
598
   * The sandbox flags on the docshell. These reflect the value of the sandbox
599
   * attribute of the associated IFRAME or CSP-protectable content, if
600
   * existent. See the HTML5 spec for more details.
601
   * These flags on the docshell reflect the current state of the sandbox
602
   * attribute, which is modifiable. They are only used when loading new
603
   * content, sandbox flags are also immutably set on the document when it is
604
   * loaded.
605
   * The sandbox flags of a document depend on the sandbox flags on its
606
   * docshell and of its parent document, if any.
607
   * See nsSandboxFlags.h for the possible flags.
608
   */
609
  attribute unsigned long sandboxFlags;
596
};
610
};
(-)a/dom/base/nsGlobalWindow.cpp (+13 lines)
Line     Link Here 
 Lines 213-228    Link Here 
213
#include "nsRefreshDriver.h"
213
#include "nsRefreshDriver.h"
214
#include "mozAutoDocUpdate.h"
214
#include "mozAutoDocUpdate.h"
215
215
216
#include "mozilla/Telemetry.h"
216
#include "mozilla/Telemetry.h"
217
#include "nsLocation.h"
217
#include "nsLocation.h"
218
#include "nsWrapperCacheInlines.h"
218
#include "nsWrapperCacheInlines.h"
219
#include "nsDOMEventTargetHelper.h"
219
#include "nsDOMEventTargetHelper.h"
220
#include "nsIAppsService.h"
220
#include "nsIAppsService.h"
221
#include "nsSandboxFlags.h"
221
222
222
#ifdef ANDROID
223
#ifdef ANDROID
223
#include <android/log.h>
224
#include <android/log.h>
224
#endif
225
#endif
225
226
226
#ifdef PR_LOGGING
227
#ifdef PR_LOGGING
227
static PRLogModuleInfo* gDOMLeakPRLog;
228
static PRLogModuleInfo* gDOMLeakPRLog;
228
#endif
229
#endif
 Lines 8135-8150   nsGlobalWindow::GetSessionStorage(nsIDOM Link Here 
8135
  if (!mSessionStorage) {
8136
  if (!mSessionStorage) {
8136
    *aSessionStorage = nsnull;
8137
    *aSessionStorage = nsnull;
8137
8138
8138
    nsString documentURI;
8139
    nsString documentURI;
8139
    if (mDocument) {
8140
    if (mDocument) {
8140
      mDocument->GetDocumentURI(documentURI);
8141
      mDocument->GetDocumentURI(documentURI);
8141
    }
8142
    }
8142
8143
8144
    // If the document has the sandboxed origin flag set
8145
    // don't allow access to localStorage.
8146
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
8147
      return NS_ERROR_DOM_SECURITY_ERR;
8148
    }
8149
8143
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
8150
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
8144
                                                          documentURI,
8151
                                                          documentURI,
8145
                                                          true,
8152
                                                          true,
8146
                                                          getter_AddRefs(mSessionStorage));
8153
                                                          getter_AddRefs(mSessionStorage));
8147
    NS_ENSURE_SUCCESS(rv, rv);
8154
    NS_ENSURE_SUCCESS(rv, rv);
8148
8155
8149
#ifdef PR_LOGGING
8156
#ifdef PR_LOGGING
8150
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
8157
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
 Lines 8200-8215   nsGlobalWindow::GetLocalStorage(nsIDOMSt Link Here 
8200
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8207
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8201
    NS_ENSURE_SUCCESS(rv, rv);
8208
    NS_ENSURE_SUCCESS(rv, rv);
8202
8209
8203
    nsString documentURI;
8210
    nsString documentURI;
8204
    if (mDocument) {
8211
    if (mDocument) {
8205
      mDocument->GetDocumentURI(documentURI);
8212
      mDocument->GetDocumentURI(documentURI);
8206
    }
8213
    }
8207
8214
8215
    // If the document has the sandboxed origin flag set
8216
    // don't allow access to localStorage.
8217
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
8218
      return NS_ERROR_DOM_SECURITY_ERR;
8219
    }
8220
8208
    nsIDocShell* docShell = GetDocShell();
8221
    nsIDocShell* docShell = GetDocShell();
8209
    nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
8222
    nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
8210
8223
8211
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8224
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8212
                                                     documentURI,
8225
                                                     documentURI,
8213
                                                     loadContext && loadContext->UsePrivateBrowsing(),
8226
                                                     loadContext && loadContext->UsePrivateBrowsing(),
8214
                                                     getter_AddRefs(mLocalStorage));
8227
                                                     getter_AddRefs(mLocalStorage));
8215
    NS_ENSURE_SUCCESS(rv, rv);
8228
    NS_ENSURE_SUCCESS(rv, rv);
(-)a/dom/interfaces/html/nsIDOMHTMLIFrameElement.idl (-2 / +2 lines)
Line     Link Here 
 Lines 11-42    Link Here 
11
 *
11
 *
12
 * This interface is trying to follow the DOM Level 2 HTML specification:
12
 * This interface is trying to follow the DOM Level 2 HTML specification:
13
 * http://www.w3.org/TR/DOM-Level-2-HTML/
13
 * http://www.w3.org/TR/DOM-Level-2-HTML/
14
 *
14
 *
15
 * with changes from the work-in-progress WHATWG HTML specification:
15
 * with changes from the work-in-progress WHATWG HTML specification:
16
 * http://www.whatwg.org/specs/web-apps/current-work/
16
 * http://www.whatwg.org/specs/web-apps/current-work/
17
 */
17
 */
18
18
19
[scriptable, uuid(97E4F0E1-BD27-40EC-9287-5634DAF15B73)]
19
[scriptable, uuid(52f6244b-b1f5-4f4c-8ff3-7e146316f411)]
20
interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
20
interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
21
{
21
{
22
           attribute DOMString        align;
22
           attribute DOMString        align;
23
           attribute DOMString        frameBorder;
23
           attribute DOMString        frameBorder;
24
           attribute DOMString        height;
24
           attribute DOMString        height;
25
           attribute DOMString        longDesc;
25
           attribute DOMString        longDesc;
26
           attribute DOMString        marginHeight;
26
           attribute DOMString        marginHeight;
27
           attribute DOMString        marginWidth;
27
           attribute DOMString        marginWidth;
28
           attribute DOMString        name;
28
           attribute DOMString        name;
29
           attribute DOMString        scrolling;
29
           attribute DOMString        scrolling;
30
           attribute DOMString        src;
30
           attribute DOMString        src;
31
           attribute DOMString        width;
31
           attribute DOMString        width;
32
  // Introduced in DOM Level 2:
32
  // Introduced in DOM Level 2:
33
  readonly attribute nsIDOMDocument   contentDocument;
33
  readonly attribute nsIDOMDocument   contentDocument;
34
  readonly attribute nsIDOMWindow     contentWindow;
34
  readonly attribute nsIDOMWindow     contentWindow;
35
35
36
36
           attribute DOMString        sandbox;
37
  // Mozilla extensions
37
  // Mozilla extensions
38
  // iframe elements require the mozAllowFullScreen attribute to be present
38
  // iframe elements require the mozAllowFullScreen attribute to be present
39
  // if they're to allow content in the sub document to go into DOM full-screen
39
  // if they're to allow content in the sub document to go into DOM full-screen
40
  // mode. See https://wiki.mozilla.org/index.php?title=Gecko:FullScreenAPI
40
  // mode. See https://wiki.mozilla.org/index.php?title=Gecko:FullScreenAPI
41
           attribute boolean          mozAllowFullScreen;
41
           attribute boolean          mozAllowFullScreen;
42
};
42
};
(-)a/dom/src/jsurl/Makefile.in (+1 lines)
Line     Link Here 
 Lines 25-40   XPIDLSRCS = \ Link Here 
25
CPPSRCS		= nsJSProtocolHandler.cpp
25
CPPSRCS		= nsJSProtocolHandler.cpp
26
26
27
EXPORTS		= $(srcdir)/nsJSProtocolHandler.h
27
EXPORTS		= $(srcdir)/nsJSProtocolHandler.h
28
28
29
LOCAL_INCLUDES += \
29
LOCAL_INCLUDES += \
30
		-I$(srcdir) \
30
		-I$(srcdir) \
31
		-I$(topsrcdir)/dom/base \
31
		-I$(topsrcdir)/dom/base \
32
		-I$(topsrcdir)/netwerk/base/src \
32
		-I$(topsrcdir)/netwerk/base/src \
33
		-I$(topsrcdir)/content/base/src \
33
34
34
ifdef BUILD_DEBUG_GC
35
ifdef BUILD_DEBUG_GC
35
DEFINES		+= -DDEBUG_GC
36
DEFINES		+= -DDEBUG_GC
36
endif
37
endif
37
38
38
DIRS            = $(NULL)
39
DIRS            = $(NULL)
39
TEST_DIRS += test
40
TEST_DIRS += test
40
41
(-)a/dom/src/jsurl/nsJSProtocolHandler.cpp (+13 lines)
Line     Link Here 
 Lines 40-55    Link Here 
40
#include "nsThreadUtils.h"
40
#include "nsThreadUtils.h"
41
#include "nsIJSContextStack.h"
41
#include "nsIJSContextStack.h"
42
#include "nsIScriptChannel.h"
42
#include "nsIScriptChannel.h"
43
#include "nsIDocument.h"
43
#include "nsIDocument.h"
44
#include "nsIObjectInputStream.h"
44
#include "nsIObjectInputStream.h"
45
#include "nsIObjectOutputStream.h"
45
#include "nsIObjectOutputStream.h"
46
#include "nsIWritablePropertyBag2.h"
46
#include "nsIWritablePropertyBag2.h"
47
#include "nsIContentSecurityPolicy.h"
47
#include "nsIContentSecurityPolicy.h"
48
#include "nsSandboxFlags.h"
48
49
49
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
50
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
50
51
51
class nsJSThunk : public nsIInputStream
52
class nsJSThunk : public nsIInputStream
52
{
53
{
53
public:
54
public:
54
    nsJSThunk();
55
    nsJSThunk();
55
56
 Lines 186-201   nsresult nsJSThunk::EvaluateScript(nsICh Link Here 
186
    // Get the global object we should be running on.
187
    // Get the global object we should be running on.
187
    nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
188
    nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
188
    if (!global) {
189
    if (!global) {
189
        return NS_ERROR_FAILURE;
190
        return NS_ERROR_FAILURE;
190
    }
191
    }
191
192
192
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
193
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
193
194
195
    // Sandboxed document check: javascript: URI's are disabled
196
    // in a sandboxed document unless 'allow-scripts' was specified
197
198
    // REVIEW - it seems like the original inner window would be the one
199
    // that will execute the javascript with its principal - is this
200
    // assumption correct ?? (and is GetExtantDocument() the right way
201
    // to get the right document ??
202
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(aOriginalInnerWindow->GetExtantDocument());
203
    if (doc && (doc->SandboxFlags() & SANDBOXED_SCRIPTS)) {
204
      return NS_ERROR_DOM_RETVAL_UNDEFINED;
205
    }
206
194
    // Push our popup control state
207
    // Push our popup control state
195
    nsAutoPopupStatePusher popupStatePusher(win, aPopupState);
208
    nsAutoPopupStatePusher popupStatePusher(win, aPopupState);
196
209
197
    // Make sure we still have the same inner window as we used to.
210
    // Make sure we still have the same inner window as we used to.
198
    nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
211
    nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
199
212
200
    if (innerWin != aOriginalInnerWindow) {
213
    if (innerWin != aOriginalInnerWindow) {
201
        return NS_ERROR_UNEXPECTED;
214
        return NS_ERROR_UNEXPECTED;
(-)a/embedding/components/windowwatcher/src/Makefile.in (-1 / +2 lines)
Line     Link Here 
 Lines 24-34   CPPSRCS += nsDialogParamBlock.cpp \ Link Here 
24
		   $(NULL)
24
		   $(NULL)
25
endif
25
endif
26
26
27
# we don't want the shared lib, but we want to force the creation of a
27
# we don't want the shared lib, but we want to force the creation of a
28
# static lib.
28
# static lib.
29
FORCE_STATIC_LIB = 1
29
FORCE_STATIC_LIB = 1
30
30
31
# For nsJSUtils
31
# For nsJSUtils
32
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base
32
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base \
33
		  -I$(topsrcdir)/content/base/src \
33
34
34
include $(topsrcdir)/config/rules.mk
35
include $(topsrcdir)/config/rules.mk
(-)a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp (+18 lines)
Line     Link Here 
 Lines 53-68    Link Here 
53
#include "nsPIDOMStorage.h"
53
#include "nsPIDOMStorage.h"
54
#include "nsIWidget.h"
54
#include "nsIWidget.h"
55
#include "nsFocusManager.h"
55
#include "nsFocusManager.h"
56
#include "nsIPresShell.h"
56
#include "nsIPresShell.h"
57
#include "nsPresContext.h"
57
#include "nsPresContext.h"
58
#include "nsContentUtils.h"
58
#include "nsContentUtils.h"
59
#include "nsIPrefBranch.h"
59
#include "nsIPrefBranch.h"
60
#include "nsIPrefService.h"
60
#include "nsIPrefService.h"
61
#include "nsSandboxFlags.h"
61
62
62
#ifdef USEWEAKREFS
63
#ifdef USEWEAKREFS
63
#include "nsIWeakReference.h"
64
#include "nsIWeakReference.h"
64
#endif
65
#endif
65
66
66
using namespace mozilla;
67
using namespace mozilla;
67
68
68
static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
69
static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
 Lines 570-585   nsWindowWatcher::OpenWindowJSInternal(ns Link Here 
570
  }
571
  }
571
572
572
  if (!newDocShellItem) {
573
  if (!newDocShellItem) {
573
    // We're going to either open up a new window ourselves or ask a
574
    // We're going to either open up a new window ourselves or ask a
574
    // nsIWindowProvider for one.  In either case, we'll want to set the right
575
    // nsIWindowProvider for one.  In either case, we'll want to set the right
575
    // name on it.
576
    // name on it.
576
    windowNeedsName = true;
577
    windowNeedsName = true;
577
578
579
    // If the parent trying to open a new window is sandboxed,
580
    // this is not allowed and we fail here.
581
    if (aParent) {
582
      nsCOMPtr<nsIDOMDocument> domdoc;
583
      aParent->GetDocument(getter_AddRefs(domdoc));
584
      nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
585
586
      if (doc) {
587
        PRUint32 sandboxFlags = 0;
588
        sandboxFlags = doc->SandboxFlags();
589
590
        if (sandboxFlags & SANDBOXED_NAVIGATION) {
591
          return NS_ERROR_FAILURE;
592
        }
593
      }
594
    }
595
578
    // Now check whether it's ok to ask a window provider for a window.  Don't
596
    // Now check whether it's ok to ask a window provider for a window.  Don't
579
    // do it if we're opening a dialog or if our parent is a chrome window or
597
    // do it if we're opening a dialog or if our parent is a chrome window or
580
    // if we're opening something that has modal, dialog, or chrome flags set.
598
    // if we're opening something that has modal, dialog, or chrome flags set.
581
    nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(aParent);
599
    nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(aParent);
582
    if (!aDialog && !chromeWin &&
600
    if (!aDialog && !chromeWin &&
583
        !(chromeFlags & (nsIWebBrowserChrome::CHROME_MODAL         |
601
        !(chromeFlags & (nsIWebBrowserChrome::CHROME_MODAL         |
584
                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 
602
                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 
585
                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {
603
                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {

Return to bug 341604