Attachment #621203: iframe sandbox v13 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 835-850   public: Link Here 
835
  /**
835
  /**
836
   * Get the localized string named |aKey| in properties file |aFile|.
836
   * Get the localized string named |aKey| in properties file |aFile|.
837
   */
837
   */
838
  static nsresult GetLocalizedString(PropertiesFile aFile,
838
  static nsresult GetLocalizedString(PropertiesFile aFile,
839
                                     const char* aKey,
839
                                     const char* aKey,
840
                                     nsXPIDLString& aResult);
840
                                     nsXPIDLString& aResult);
841
841
842
  /**
842
  /**
843
   * A helper function that parses a sandbox attribute (of an <iframe> or
844
   * a CSP directive) and converts it to the set of flags used internally.
845
   *
846
   * @param aAttribute 	the value of the sandbox attribute
847
   * @return 			the set of flags
848
   */
849
  static PRUint32 ParseSandboxAttributeToFlags(const nsAString&
850
                                                 sandboxAttr);
851
852
853
  /**
843
   * Fill (with the parameters given) the localized string named |aKey| in
854
   * Fill (with the parameters given) the localized string named |aKey| in
844
   * properties file |aFile|.
855
   * properties file |aFile|.
845
   */
856
   */
846
private:
857
private:
847
  static nsresult FormatLocalizedString(PropertiesFile aFile,
858
  static nsresult FormatLocalizedString(PropertiesFile aFile,
848
                                        const char* aKey,
859
                                        const char* aKey,
849
                                        const PRUnichar** aParams,
860
                                        const PRUnichar** aParams,
850
                                        PRUint32 aParamsLength,
861
                                        PRUint32 aParamsLength,
 Lines 1955-1996   public: Link Here 
1955
   * from the document it comes from.
1966
   * from the document it comes from.
1956
   */
1967
   */
1957
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1968
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1958
1969
1959
  /**
1970
  /**
1960
   * Set the given principal as the owner of the given channel, if
1971
   * Set the given principal as the owner of the given channel, if
1961
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1972
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1962
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1973
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1963
   * the principal set up on it.
1974
   * the principal set up on it. If aForceOwner is true, the owner
1964
   *
1975
   * will be set on the channel, even if the principal can be determined
1976
   * from the channel.
1965
   * The return value is whether the principal was set up as the owner
1977
   * The return value is whether the principal was set up as the owner
1966
   * of the channel.
1978
   * of the channel.
1967
   */
1979
   */
1968
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1980
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1969
                                nsIChannel* aChannel,
1981
                                nsIChannel* aChannel,
1970
                                nsIURI* aURI,
1982
                                nsIURI* aURI,
1971
                                bool aSetUpForAboutBlank);
1983
                                bool aSetUpForAboutBlank,
1984
                                bool aForceOwner = false);
1972
1985
1973
  static nsresult Btoa(const nsAString& aBinaryData,
1986
  static nsresult Btoa(const nsAString& aBinaryData,
1974
                       nsAString& aAsciiBase64String);
1987
                       nsAString& aAsciiBase64String);
1975
1988
1976
  static nsresult Atob(const nsAString& aAsciiString,
1989
  static nsresult Atob(const nsAString& aAsciiString,
1977
                       nsAString& aBinaryData);
1990
                       nsAString& aBinaryData);
1978
1991
1979
  /** If aJSArray is a Javascript array, this method iterates over its
1992
  /** If aJSArray is a Javascript array, this method iterates over its
1980
   *  elements and appends values to aRetVal as nsIAtoms.
1993
   *  elements and appends values to aRetVal as nsIAtoms.
1981
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1994
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1982
   */ 
1995
   */ 
1983
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1996
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1984
                                     nsCOMArray<nsIAtom>& aRetVal);
1997
                                     nsCOMArray<nsIAtom>& aRetVal);
1985
1998
1986
  /**
1999
  /**
1987
   * Returns whether the input element passed in parameter has the autocomplete
2000
   * Returns whether the input element passed in parameter has the autocomplete
1988
   * functionnality enabled. It is taking into account the form owner.
2001
   * functionality enabled. It is taking into account the form owner.
1989
   * NOTE: the caller has to make sure autocomplete makes sense for the
2002
   * NOTE: the caller has to make sure autocomplete makes sense for the
1990
   * element's type.
2003
   * element's type.
1991
   *
2004
   *
1992
   * @param aInput the input element to check. NOTE: aInput can't be null.
2005
   * @param aInput the input element to check. NOTE: aInput can't be null.
1993
   * @return whether the input element has autocomplete enabled.
2006
   * @return whether the input element has autocomplete enabled.
1994
   */
2007
   */
1995
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
2008
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
1996
2009
(-)a/content/base/public/nsIDocument.h (-4 / +17 lines)
Line     Link Here 
 Lines 120-138   class Loader; Link Here 
120
120
121
namespace dom {
121
namespace dom {
122
class Link;
122
class Link;
123
class Element;
123
class Element;
124
} // namespace dom
124
} // namespace dom
125
} // namespace mozilla
125
} // namespace mozilla
126
126
127
#define NS_IDOCUMENT_IID \
127
#define NS_IDOCUMENT_IID \
128
{ 0x8e51e6d9, 0x914d, 0x46ba, \
128
{ 0x57fe44ae, 0x6656, 0x44b8, \
129
  { 0xb3, 0x11, 0x2f, 0x27, 0x3d, 0xe6, 0x0d, 0x19 } }
129
  { 0x8d, 0xc0, 0xfc, 0xa7, 0x43, 0x28, 0xbe, 0x86 } }
130
131
130
132
// Flag for AddStyleSheet().
131
// Flag for AddStyleSheet().
133
#define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
132
#define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
134
133
135
// Enum for requesting a particular type of document when creating a doc
134
// Enum for requesting a particular type of document when creating a doc
136
enum DocumentFlavor {
135
enum DocumentFlavor {
137
  DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
136
  DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
138
  DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
137
  DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
 Lines 460-476   public: Link Here 
460
   * callers are expected to take action as needed if they want this
459
   * callers are expected to take action as needed if they want this
461
   * change to actually change anything immediately.
460
   * change to actually change anything immediately.
462
   * @see nsBidiUtils.h
461
   * @see nsBidiUtils.h
463
   */
462
   */
464
  void SetBidiOptions(PRUint32 aBidiOptions)
463
  void SetBidiOptions(PRUint32 aBidiOptions)
465
  {
464
  {
466
    mBidiOptions = aBidiOptions;
465
    mBidiOptions = aBidiOptions;
467
  }
466
  }
468
  
467
468
  /**
469
   * Get the sandbox flags for this document.
470
   * @see nsSandboxFlags.h for the possible flags
471
   */
472
  PRUint32 SandboxFlags() const
473
  {
474
    return mSandboxFlags;
475
  }
476
469
  /**
477
  /**
470
   * Access HTTP header data (this may also get set from other
478
   * Access HTTP header data (this may also get set from other
471
   * sources, like HTML META tags).
479
   * sources, like HTML META tags).
472
   */
480
   */
473
  virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
481
  virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
474
  virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
482
  virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
475
483
476
  /**
484
  /**
 Lines 1854-1869   protected: Link Here 
1854
  // If mIsStaticDocument is true, mOriginalDocument points to the original
1862
  // If mIsStaticDocument is true, mOriginalDocument points to the original
1855
  // document.
1863
  // document.
1856
  nsCOMPtr<nsIDocument> mOriginalDocument;
1864
  nsCOMPtr<nsIDocument> mOriginalDocument;
1857
1865
1858
  // The bidi options for this document.  What this bitfield means is
1866
  // The bidi options for this document.  What this bitfield means is
1859
  // defined in nsBidiUtils.h
1867
  // defined in nsBidiUtils.h
1860
  PRUint32 mBidiOptions;
1868
  PRUint32 mBidiOptions;
1861
1869
1870
  // The sandbox flags on the document. These reflect the value of the sandbox attribute of the
1871
  // associated IFRAME or CSP-protectable content, if existent. These are set at load time and
1872
  // are immutable - see nsSandboxFlags.h for the possible flags.
1873
  PRUint32 mSandboxFlags;
1874
1862
  nsCString mContentLanguage;
1875
  nsCString mContentLanguage;
1863
private:
1876
private:
1864
  nsCString mContentType;
1877
  nsCString mContentType;
1865
protected:
1878
protected:
1866
1879
1867
  // The document's security info
1880
  // The document's security info
1868
  nsCOMPtr<nsISupports> mSecurityInfo;
1881
  nsCOMPtr<nsISupports> mSecurityInfo;
1869
1882
(-)a/content/base/src/nsContentUtils.cpp (-3 / +55 lines)
Line     Link Here 
 Lines 208-223   static NS_DEFINE_CID(kXTFServiceCID, NS_ Link Here 
208
#include "nsCCUncollectableMarker.h"
208
#include "nsCCUncollectableMarker.h"
209
#include "mozilla/Base64.h"
209
#include "mozilla/Base64.h"
210
#include "mozilla/Preferences.h"
210
#include "mozilla/Preferences.h"
211
#include "nsDOMMutationObserver.h"
211
#include "nsDOMMutationObserver.h"
212
212
213
#include "nsWrapperCacheInlines.h"
213
#include "nsWrapperCacheInlines.h"
214
#include "nsIDOMDocumentType.h"
214
#include "nsIDOMDocumentType.h"
215
#include "nsCharSeparatedTokenizer.h"
215
#include "nsCharSeparatedTokenizer.h"
216
#include "nsSandboxFlags.h"
216
217
217
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
218
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
218
                                      const char** next, PRUnichar* result);
219
                                      const char** next, PRUnichar* result);
219
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
220
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
220
                                 int ns_aware, const char** colon);
221
                                 int ns_aware, const char** colon);
221
222
222
using namespace mozilla::dom;
223
using namespace mozilla::dom;
223
using namespace mozilla::layers;
224
using namespace mozilla::layers;
 Lines 916-931   nsContentUtils::GetParserService() Link Here 
916
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
917
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
917
    if (NS_FAILED(rv)) {
918
    if (NS_FAILED(rv)) {
918
      sParserService = nsnull;
919
      sParserService = nsnull;
919
    }
920
    }
920
  }
921
  }
921
922
922
  return sParserService;
923
  return sParserService;
923
}
924
}
925
/**
926
 * A helper function that parses a sandbox attribute (of an <iframe> or
927
 * a CSP directive) and converts it to the set of flags used internally.
928
 *
929
 * @param aAttribute    the value of the sandbox attribute
930
 * @return              the set of flags
931
 */
932
PRUint32
933
nsContentUtils::ParseSandboxAttributeToFlags(const nsAString& sandboxAttrValue)
934
{
935
  // If there's a sandbox attribute at all (and there is if this is being
936
  // called), start off by setting all the restriction flags.
937
  PRUint32 out = SANDBOXED_NAVIGATION |
938
    SANDBOXED_TOPLEVEL_NAVIGATION |
939
    SANDBOXED_PLUGINS | SANDBOXED_ORIGIN |
940
    SANDBOXED_FORMS | SANDBOXED_SCRIPTS |
941
    SANDBOXED_AUTOMATIC_FEATURES;
942
943
  if (!sandboxAttrValue.IsEmpty()) {
944
    // The separator optional flag is used because the HTML5 spec says any
945
    // whitespace is ok as a separator, which is what this does.
946
    HTMLSplitOnSpacesTokenizer tokenizer(sandboxAttrValue, ' ',
947
      nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>::SEPARATOR_OPTIONAL);
948
949
    while (tokenizer.hasMoreTokens()) {
950
      nsDependentSubstring token = tokenizer.nextToken();
951
952
      if (token.LowerCaseEqualsLiteral("allow-scripts")) {
953
        out &= ~SANDBOXED_SCRIPTS;
954
      } else if (token.LowerCaseEqualsLiteral("allow-same-origin")) {
955
        out &= ~SANDBOXED_ORIGIN;
956
      } else if (token.LowerCaseEqualsLiteral("allow-forms")) {
957
        out &= ~SANDBOXED_FORMS;
958
      } else if (token.LowerCaseEqualsLiteral("allow-scripts")) {
959
        // allow-scripts removes both SANDBOXED_SCRIPTS and
960
        // SANDBOXED_AUTOMATIC_FEATURES.
961
        out &= ~SANDBOXED_SCRIPTS;
962
        out &= ~SANDBOXED_AUTOMATIC_FEATURES;
963
      } else if (token.LowerCaseEqualsLiteral("allow-top-navigation")) {
964
        out &= ~SANDBOXED_TOPLEVEL_NAVIGATION;
965
      }
966
    }
967
  }
968
969
  return out;
970
}
924
971
925
#ifdef MOZ_XTF
972
#ifdef MOZ_XTF
926
nsIXTFService*
973
nsIXTFService*
927
nsContentUtils::GetXTFService()
974
nsContentUtils::GetXTFService()
928
{
975
{
929
  if (!sXTFService) {
976
  if (!sXTFService) {
930
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
977
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
931
    if (NS_FAILED(rv)) {
978
    if (NS_FAILED(rv)) {
 Lines 6453-6469   nsContentUtils::URIInheritsSecurityConte Link Here 
6453
                             aResult);
6500
                             aResult);
6454
}
6501
}
6455
6502
6456
// static
6503
// static
6457
bool
6504
bool
6458
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6505
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6459
                                  nsIChannel* aChannel,
6506
                                  nsIChannel* aChannel,
6460
                                  nsIURI* aURI,
6507
                                  nsIURI* aURI,
6461
                                  bool aSetUpForAboutBlank)
6508
                                  bool aSetUpForAboutBlank,
6509
                                  bool aForceOwner)
6462
{
6510
{
6463
  //
6511
  //
6464
  // Set the owner of the channel, but only for channels that can't
6512
  // Set the owner of the channel, but only for channels that can't
6465
  // provide their own security context.
6513
  // provide their own security context.
6466
  //
6514
  //
6467
  // XXX: It seems wrong that the owner is ignored - even if one is
6515
  // XXX: It seems wrong that the owner is ignored - even if one is
6468
  //      supplied) unless the URI is javascript or data or about:blank.
6516
  //      supplied) unless the URI is javascript or data or about:blank.
6469
  // XXX: If this is ever changed, check all callers for what owners
6517
  // XXX: If this is ever changed, check all callers for what owners
 Lines 6471-6493   nsContentUtils::SetUpChannelOwner(nsIPri Link Here 
6471
  //      comments in nsDocShell::LoadURI where we fall back on
6519
  //      comments in nsDocShell::LoadURI where we fall back on
6472
  //      inheriting the owner if called from chrome.  That would be
6520
  //      inheriting the owner if called from chrome.  That would be
6473
  //      very wrong if this code changed anything but channels that
6521
  //      very wrong if this code changed anything but channels that
6474
  //      can't provide their own security context!
6522
  //      can't provide their own security context!
6475
  //
6523
  //
6476
  //      (Currently chrome URIs set the owner when they are created!
6524
  //      (Currently chrome URIs set the owner when they are created!
6477
  //      So setting a NULL owner would be bad!)
6525
  //      So setting a NULL owner would be bad!)
6478
  //
6526
  //
6527
  // If aForceOwner is true, the owner will be set, even for a channel that
6528
  // can provide its own security context. This is used for the HTML5 IFRAME
6529
  // sandbox attribute, so we can force the channel (and its document) to
6530
  // explicitly have a null principal.
6479
  bool inherit;
6531
  bool inherit;
6480
  // We expect URIInheritsSecurityContext to return success for an
6532
  // We expect URIInheritsSecurityContext to return success for an
6481
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6533
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6482
  // This condition needs to match the one in nsDocShell::InternalLoad where
6534
  // This condition needs to match the one in nsDocShell::InternalLoad where
6483
  // we're checking for things that will use the owner.
6535
  // we're checking for things that will use the owner.
6484
  if (NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6536
  if (aForceOwner || ((NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6485
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))) {
6537
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))))) {
6486
    aChannel->SetOwner(aLoadingPrincipal);
6538
    aChannel->SetOwner(aLoadingPrincipal);
6487
    return true;
6539
    return true;
6488
  }
6540
  }
6489
6541
6490
  //
6542
  //
6491
  // file: uri special-casing
6543
  // file: uri special-casing
6492
  //
6544
  //
6493
  // If this is a file: load opened from another file: then it may need
6545
  // 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 2415-2430   nsDocument::StartDocumentLoad(const char Link Here 
2415
    FindCharInReadable(';', semicolon, end);
2415
    FindCharInReadable(';', semicolon, end);
2416
    SetContentTypeInternal(Substring(start, semicolon));
2416
    SetContentTypeInternal(Substring(start, semicolon));
2417
  }
2417
  }
2418
2418
2419
  RetrieveRelevantHeaders(aChannel);
2419
  RetrieveRelevantHeaders(aChannel);
2420
2420
2421
  mChannel = aChannel;
2421
  mChannel = aChannel;
2422
2422
2423
  // If this document is being loaded by a docshell, copy its sandbox flags
2424
  // to the document. These are immutable after being set here.
2425
  nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(aContainer);
2426
2427
  if (docShell) {
2428
    nsresult rv = docShell->GetSandboxFlags(&mSandboxFlags);
2429
    NS_ENSURE_SUCCESS(rv, rv);
2430
  }
2431
2423
  nsresult rv = InitCSP();
2432
  nsresult rv = InitCSP();
2424
  NS_ENSURE_SUCCESS(rv, rv);
2433
  NS_ENSURE_SUCCESS(rv, rv);
2425
2434
2426
  return NS_OK;
2435
  return NS_OK;
2427
}
2436
}
2428
2437
2429
nsresult
2438
nsresult
2430
nsDocument::InitCSP()
2439
nsDocument::InitCSP()
(-)a/content/base/src/nsFrameLoader.cpp (+47 lines)
Line     Link Here 
 Lines 112-127    Link Here 
112
#include "mozilla/GuardObjects.h"
112
#include "mozilla/GuardObjects.h"
113
#include "mozilla/Preferences.h"
113
#include "mozilla/Preferences.h"
114
#include "mozilla/unused.h"
114
#include "mozilla/unused.h"
115
#include "mozilla/dom/Element.h"
115
#include "mozilla/dom/Element.h"
116
#include "mozilla/layout/RenderFrameParent.h"
116
#include "mozilla/layout/RenderFrameParent.h"
117
117
118
#include "jsapi.h"
118
#include "jsapi.h"
119
119
120
#include "nsHTMLIFrameElement.h"
121
#include "nsSandboxFlags.h"
122
120
using namespace mozilla;
123
using namespace mozilla;
121
using namespace mozilla::dom;
124
using namespace mozilla::dom;
122
using namespace mozilla::layers;
125
using namespace mozilla::layers;
123
using namespace mozilla::layout;
126
using namespace mozilla::layout;
124
typedef FrameMetrics::ViewID ViewID;
127
typedef FrameMetrics::ViewID ViewID;
125
128
126
class nsAsyncDocShellDestroyer : public nsRunnable
129
class nsAsyncDocShellDestroyer : public nsRunnable
127
{
130
{
 Lines 473-488   nsFrameLoader::ReallyStartLoadingInterna Link Here 
473
  // Just to be safe, recheck uri.
476
  // Just to be safe, recheck uri.
474
  rv = CheckURILoad(mURIToLoad);
477
  rv = CheckURILoad(mURIToLoad);
475
  NS_ENSURE_SUCCESS(rv, rv);
478
  NS_ENSURE_SUCCESS(rv, rv);
476
479
477
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
480
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
478
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
481
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
479
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
482
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
480
483
484
  // Is this an <iframe> with a sandbox attribute or a parent which is
485
  // sandboxed ?
486
  nsHTMLIFrameElement * iframe =
487
    nsHTMLIFrameElement::FromContent(mOwnerContent);
488
489
  PRUint32 sandboxFlags = 0;
490
491
  if (iframe) {
492
    sandboxFlags = iframe->GetSandboxFlags();
493
494
    PRUint32 parentSandboxFlags = 0;
495
496
    // Get the parent's sandbox flags, they're needed to determine if the
497
    // frame being loaded needs to be sandboxed.
498
    nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
499
    nsCOMPtr<nsIDocShellTreeItem> curDocShellItem = do_QueryInterface(mDocShell);
500
501
    if (NS_SUCCEEDED(curDocShellItem->GetParent(getter_AddRefs(parentDocShellItem)))) {
502
      nsCOMPtr<nsIDocument> parentDoc = do_GetInterface(parentDocShellItem);
503
504
      if (parentDoc) {
505
        parentSandboxFlags = parentDoc->SandboxFlags();
506
      }
507
    }
508
509
    if (sandboxFlags || parentSandboxFlags) {
510
      if (parentSandboxFlags) {
511
        // The child can only add restrictions, not remove them.
512
        sandboxFlags |= parentSandboxFlags;
513
      }
514
515
      mDocShell->SetSandboxFlags(sandboxFlags);
516
517
      // Set up the actual sandboxing for plugins as specified.
518
      if (sandboxFlags & SANDBOXED_PLUGINS) {
519
        mDocShell->SetAllowPlugins(false);
520
      }
521
    }
522
  }
523
524
  // If this is an <iframe> and it's sandboxed with respect to origin
525
  // we will set it up with a null principal later in nsDocShell::DoURILoad.
526
  // We do it there to correctly sandbox content that was loaded into
527
  // the iframe via other methods than the src attribute.
481
  // We'll use our principal, not that of the document loaded inside us.  This
528
  // We'll use our principal, not that of the document loaded inside us.  This
482
  // is very important; needed to prevent XSS attacks on documents loaded in
529
  // is very important; needed to prevent XSS attacks on documents loaded in
483
  // subframes!
530
  // subframes!
484
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
531
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
485
532
486
  nsCOMPtr<nsIURI> referrer;
533
  nsCOMPtr<nsIURI> referrer;
487
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
534
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
488
  NS_ENSURE_SUCCESS(rv, rv);
535
  NS_ENSURE_SUCCESS(rv, rv);
(-)a/content/base/src/nsGkAtomList.h (+5 lines)
Line     Link Here 
 Lines 93-109   GK_ATOM(actuate, "actuate") Link Here 
93
GK_ATOM(address, "address")
93
GK_ATOM(address, "address")
94
GK_ATOM(after, "after")
94
GK_ATOM(after, "after")
95
GK_ATOM(after_end, "after_end")
95
GK_ATOM(after_end, "after_end")
96
GK_ATOM(after_start, "after_start")
96
GK_ATOM(after_start, "after_start")
97
GK_ATOM(align, "align")
97
GK_ATOM(align, "align")
98
GK_ATOM(alink, "alink")
98
GK_ATOM(alink, "alink")
99
GK_ATOM(all, "all")
99
GK_ATOM(all, "all")
100
GK_ATOM(allowevents, "allowevents")
100
GK_ATOM(allowevents, "allowevents")
101
GK_ATOM(allowforms, "allow-forms")
101
GK_ATOM(allownegativeassertions, "allownegativeassertions")
102
GK_ATOM(allownegativeassertions, "allownegativeassertions")
103
GK_ATOM(allowsameorigin, "allow-same-origin")
104
GK_ATOM(allowscripts, "allow-scripts")
105
GK_ATOM(allowtopnavigation, "allow-top-navigation")
102
GK_ATOM(allowuntrusted, "allowuntrusted")
106
GK_ATOM(allowuntrusted, "allowuntrusted")
103
GK_ATOM(alt, "alt")
107
GK_ATOM(alt, "alt")
104
GK_ATOM(alternate, "alternate")
108
GK_ATOM(alternate, "alternate")
105
GK_ATOM(always, "always")
109
GK_ATOM(always, "always")
106
GK_ATOM(ancestor, "ancestor")
110
GK_ATOM(ancestor, "ancestor")
107
GK_ATOM(ancestorOrSelf, "ancestor-or-self")
111
GK_ATOM(ancestorOrSelf, "ancestor-or-self")
108
GK_ATOM(_and, "and")
112
GK_ATOM(_and, "and")
109
GK_ATOM(any, "any")
113
GK_ATOM(any, "any")
 Lines 882-897   GK_ATOM(rowspan, "rowspan") Link Here 
882
GK_ATOM(rp, "rp")
886
GK_ATOM(rp, "rp")
883
GK_ATOM(rt, "rt")
887
GK_ATOM(rt, "rt")
884
GK_ATOM(rtl, "rtl")
888
GK_ATOM(rtl, "rtl")
885
GK_ATOM(ruby, "ruby")
889
GK_ATOM(ruby, "ruby")
886
GK_ATOM(rule, "rule")
890
GK_ATOM(rule, "rule")
887
GK_ATOM(rules, "rules")
891
GK_ATOM(rules, "rules")
888
GK_ATOM(s, "s")
892
GK_ATOM(s, "s")
889
GK_ATOM(samp, "samp")
893
GK_ATOM(samp, "samp")
894
GK_ATOM(sandbox, "sandbox")
890
GK_ATOM(sbattr, "sbattr")
895
GK_ATOM(sbattr, "sbattr")
891
GK_ATOM(scale, "scale")
896
GK_ATOM(scale, "scale")
892
GK_ATOM(scan, "scan")
897
GK_ATOM(scan, "scan")
893
GK_ATOM(scheme, "scheme")
898
GK_ATOM(scheme, "scheme")
894
GK_ATOM(scope, "scope")
899
GK_ATOM(scope, "scope")
895
GK_ATOM(scoped, "scoped")
900
GK_ATOM(scoped, "scoped")
896
GK_ATOM(screen, "screen")
901
GK_ATOM(screen, "screen")
897
GK_ATOM(screenX, "screenX")
902
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 70-85    Link Here 
70
#include "nsIContentSecurityPolicy.h"
70
#include "nsIContentSecurityPolicy.h"
71
#include "prlog.h"
71
#include "prlog.h"
72
#include "nsIChannelPolicy.h"
72
#include "nsIChannelPolicy.h"
73
#include "nsChannelPolicy.h"
73
#include "nsChannelPolicy.h"
74
#include "nsCRT.h"
74
#include "nsCRT.h"
75
#include "nsContentCreatorFunctions.h"
75
#include "nsContentCreatorFunctions.h"
76
#include "nsGenericElement.h"
76
#include "nsGenericElement.h"
77
#include "nsCrossSiteListenerProxy.h"
77
#include "nsCrossSiteListenerProxy.h"
78
#include "nsSandboxFlags.h"
78
79
79
#include "mozilla/FunctionTimer.h"
80
#include "mozilla/FunctionTimer.h"
80
#include "mozilla/CORSMode.h"
81
#include "mozilla/CORSMode.h"
81
82
82
#ifdef PR_LOGGING
83
#ifdef PR_LOGGING
83
static PRLogModuleInfo* gCspPRLog;
84
static PRLogModuleInfo* gCspPRLog;
84
#endif
85
#endif
85
86
 Lines 305-320   nsScriptLoader::StartLoad(nsScriptLoadRe Link Here 
305
  if (!window) {
306
  if (!window) {
306
    return NS_ERROR_NULL_POINTER;
307
    return NS_ERROR_NULL_POINTER;
307
  }
308
  }
308
309
309
  nsIDocShell *docshell = window->GetDocShell();
310
  nsIDocShell *docshell = window->GetDocShell();
310
311
311
  nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
312
  nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
312
313
314
  // If this document is sandboxed without 'allow-scripts', abort.
315
  if (mDocument->SandboxFlags() & SANDBOXED_SCRIPTS) {
316
    // REVIEW : this probably isn't the right error..
317
    return NS_ERROR_DOM_SECURITY_ERR;
318
  }
319
313
  // check for a Content Security Policy to pass down to the channel
320
  // check for a Content Security Policy to pass down to the channel
314
  // that will be created to load the script
321
  // that will be created to load the script
315
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
322
  nsCOMPtr<nsIChannelPolicy> channelPolicy;
316
  nsCOMPtr<nsIContentSecurityPolicy> csp;
323
  nsCOMPtr<nsIContentSecurityPolicy> csp;
317
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
324
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
318
  NS_ENSURE_SUCCESS(rv, rv);
325
  NS_ENSURE_SUCCESS(rv, rv);
319
  if (csp) {
326
  if (csp) {
320
    channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
327
    channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
 Lines 676-691   nsScriptLoader::ProcessScriptElement(nsI Link Here 
676
        "There can be only one parser-blocking script at a time");
683
        "There can be only one parser-blocking script at a time");
677
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
684
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
678
        "Parser-blocking scripts and XSLT scripts in the same doc!");
685
        "Parser-blocking scripts and XSLT scripts in the same doc!");
679
    mParserBlockingRequest = request;
686
    mParserBlockingRequest = request;
680
    return true;
687
    return true;
681
  }
688
  }
682
689
683
  // inline script
690
  // inline script
691
  // Is this document sandboxed without 'allow-scripts'?
692
  if (mDocument->SandboxFlags() & SANDBOXED_SCRIPTS) {
693
    return false;
694
  }
695
684
  nsCOMPtr<nsIContentSecurityPolicy> csp;
696
  nsCOMPtr<nsIContentSecurityPolicy> csp;
685
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
697
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
686
  NS_ENSURE_SUCCESS(rv, false);
698
  NS_ENSURE_SUCCESS(rv, false);
687
699
688
  if (csp) {
700
  if (csp) {
689
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
701
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
690
    bool inlineOK;
702
    bool inlineOK;
691
    rv = csp->GetAllowsInlineScript(&inlineOK);
703
    rv = csp->GetAllowsInlineScript(&inlineOK);
(-)a/content/events/src/nsEventListenerManager.cpp (+7 lines)
Line     Link Here 
 Lines 83-98    Link Here 
83
#include "nsDOMJSUtils.h"
83
#include "nsDOMJSUtils.h"
84
#include "nsDOMScriptObjectHolder.h"
84
#include "nsDOMScriptObjectHolder.h"
85
#include "nsDataHashtable.h"
85
#include "nsDataHashtable.h"
86
#include "nsCOMArray.h"
86
#include "nsCOMArray.h"
87
#include "nsEventListenerService.h"
87
#include "nsEventListenerService.h"
88
#include "nsIContentSecurityPolicy.h"
88
#include "nsIContentSecurityPolicy.h"
89
#include "nsJSEnvironment.h"
89
#include "nsJSEnvironment.h"
90
#include "xpcpublic.h"
90
#include "xpcpublic.h"
91
#include "nsSandboxFlags.h"
91
92
92
using namespace mozilla::dom;
93
using namespace mozilla::dom;
93
using namespace mozilla::hal;
94
using namespace mozilla::hal;
94
95
95
#define EVENT_TYPE_EQUALS( ls, type, userType ) \
96
#define EVENT_TYPE_EQUALS( ls, type, userType ) \
96
  (ls->mEventType == type && \
97
  (ls->mEventType == type && \
97
  (ls->mEventType != NS_USER_DEFINED_EVENT || ls->mTypeAtom == userType))
98
  (ls->mEventType != NS_USER_DEFINED_EVENT || ls->mTypeAtom == userType))
98
99
 Lines 585-600   nsEventListenerManager::AddScriptEventLi Link Here 
585
    // loaded as data.
586
    // loaded as data.
586
    return NS_OK;
587
    return NS_OK;
587
  }
588
  }
588
589
589
  nsresult rv = NS_OK;
590
  nsresult rv = NS_OK;
590
  // return early preventing the event listener from being added
591
  // return early preventing the event listener from being added
591
  // 'doc' is fetched above
592
  // 'doc' is fetched above
592
  if (doc) {
593
  if (doc) {
594
    // Don't allow adding an event listener if the document is sandboxed
595
    // without 'allow-scripts'.
596
    if (doc->SandboxFlags() & SANDBOXED_SCRIPTS) {
597
      return NS_ERROR_DOM_SECURITY_ERR;
598
    }
599
593
    nsCOMPtr<nsIContentSecurityPolicy> csp;
600
    nsCOMPtr<nsIContentSecurityPolicy> csp;
594
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
601
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
595
    NS_ENSURE_SUCCESS(rv, rv);
602
    NS_ENSURE_SUCCESS(rv, rv);
596
603
597
    if (csp) {
604
    if (csp) {
598
      bool inlineOK;
605
      bool inlineOK;
599
      rv = csp->GetAllowsInlineScript(&inlineOK);
606
      rv = csp->GetAllowsInlineScript(&inlineOK);
600
      NS_ENSURE_SUCCESS(rv, rv);
607
      NS_ENSURE_SUCCESS(rv, rv);
(-)a/content/html/content/src/nsHTMLFormElement.cpp (-1 / +22 lines)
Line     Link Here 
 Lines 80-95    Link Here 
80
80
81
#include "mozAutoDocUpdate.h"
81
#include "mozAutoDocUpdate.h"
82
#include "nsIHTMLCollection.h"
82
#include "nsIHTMLCollection.h"
83
83
84
#include "nsIConstraintValidation.h"
84
#include "nsIConstraintValidation.h"
85
85
86
#include "nsIDOMHTMLButtonElement.h"
86
#include "nsIDOMHTMLButtonElement.h"
87
#include "dombindings.h"
87
#include "dombindings.h"
88
#include "nsSandboxFlags.h"
88
89
89
using namespace mozilla::dom;
90
using namespace mozilla::dom;
90
91
91
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
92
static const int NS_FORM_CONTROL_LIST_HASHTABLE_SIZE = 16;
92
93
93
static const PRUint8 NS_FORM_AUTOCOMPLETE_ON  = 1;
94
static const PRUint8 NS_FORM_AUTOCOMPLETE_ON  = 1;
94
static const PRUint8 NS_FORM_AUTOCOMPLETE_OFF = 0;
95
static const PRUint8 NS_FORM_AUTOCOMPLETE_OFF = 0;
95
96
 Lines 683-699   nsHTMLFormElement::DoSubmitOrReset(nsEve Link Here 
683
    return DoReset();
684
    return DoReset();
684
  }
685
  }
685
686
686
  if (NS_FORM_SUBMIT == aMessage) {
687
  if (NS_FORM_SUBMIT == aMessage) {
687
    // Don't submit if we're not in a document.
688
    // Don't submit if we're not in a document.
688
    if (!doc) {
689
    if (!doc) {
689
      return NS_OK;
690
      return NS_OK;
690
    }
691
    }
691
    return DoSubmit(aEvent);
692
    // Don't submit if we're in a sandboxed frame and form submit
693
    // is disabled.
694
    PRUint32 sandboxFlags = doc->SandboxFlags();
695
696
    if (!(sandboxFlags & SANDBOXED_FORMS)) {
697
      return DoSubmit(aEvent);
698
    }
699
700
    return NS_OK;
692
  }
701
  }
693
702
694
  MOZ_ASSERT(false);
703
  MOZ_ASSERT(false);
695
  return NS_OK;
704
  return NS_OK;
696
}
705
}
697
706
698
nsresult
707
nsresult
699
nsHTMLFormElement::DoReset()
708
nsHTMLFormElement::DoReset()
 Lines 1684-1699   nsHTMLFormElement::CheckValidFormSubmiss Link Here 
1684
   * TODO: the check for observer should be removed later when HTML5 Forms will
1693
   * TODO: the check for observer should be removed later when HTML5 Forms will
1685
   * be spread enough and authors will assume forms can't be submitted when
1694
   * be spread enough and authors will assume forms can't be submitted when
1686
   * invalid. See bug 587671.
1695
   * invalid. See bug 587671.
1687
   */
1696
   */
1688
1697
1689
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1698
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1690
               "We shouldn't be there if novalidate is set!");
1699
               "We shouldn't be there if novalidate is set!");
1691
1700
1701
  // Don't do validation for a form submit done by a sandboxed document that
1702
  // doesn't have 'allow-forms', the submit will have been blocked and the
1703
  // HTML5 spec says we shouldn't validate in this case.
1704
  nsIDocument* doc = GetCurrentDoc();
1705
  if (doc) {
1706
    PRUint32 sandboxFlags = doc->SandboxFlags();
1707
1708
    if (sandboxFlags & SANDBOXED_FORMS) {
1709
      return true;
1710
    }
1711
  }
1712
1692
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1713
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1693
  // we have to check the validity of the form.
1714
  // we have to check the validity of the form.
1694
  nsCOMPtr<nsIObserverService> service =
1715
  nsCOMPtr<nsIObserverService> service =
1695
    mozilla::services::GetObserverService();
1716
    mozilla::services::GetObserverService();
1696
  if (!service) {
1717
  if (!service) {
1697
    NS_WARNING("No observer service available!");
1718
    NS_WARNING("No observer service available!");
1698
    return true;
1719
    return true;
1699
  }
1720
  }
(-)a/content/html/content/src/nsHTMLIFrameElement.cpp (-52 / +31 lines)
Line     Link Here 
 Lines 33-106    Link Here 
33
 * the provisions above, a recipient may use your version of this file under
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
35
 *
36
 * ***** END LICENSE BLOCK ***** */
36
 * ***** END LICENSE BLOCK ***** */
37
37
38
#include "mozilla/Util.h"
38
#include "mozilla/Util.h"
39
39
40
#include "nsIDOMHTMLIFrameElement.h"
40
#include "nsIDOMHTMLIFrameElement.h"
41
#include "nsGenericHTMLFrameElement.h"
41
#include "nsHTMLIFrameElement.h"
42
#include "nsIDOMDocument.h"
43
#include "nsIDOMGetSVGDocument.h"
44
#include "nsIDOMSVGDocument.h"
45
#include "nsGkAtoms.h"
46
#include "nsIDocument.h"
47
#include "nsMappedAttributes.h"
48
#include "nsDOMError.h"
49
#include "nsRuleData.h"
50
#include "nsStyleConsts.h"
51
42
52
using namespace mozilla;
43
using namespace mozilla;
53
using namespace mozilla::dom;
44
using namespace mozilla::dom;
54
45
55
class nsHTMLIFrameElement : public nsGenericHTMLFrameElement
56
                          , public nsIDOMHTMLIFrameElement
57
                          , public nsIDOMGetSVGDocument
58
{
59
public:
60
  nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
61
                      mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
62
  virtual ~nsHTMLIFrameElement();
63
64
  // nsISupports
65
  NS_DECL_ISUPPORTS_INHERITED
66
67
  // nsIDOMNode
68
  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
69
70
  // nsIDOMElement
71
  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
72
73
  // nsIDOMHTMLElement
74
  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
75
76
  // nsIDOMHTMLIFrameElement
77
  NS_DECL_NSIDOMHTMLIFRAMEELEMENT
78
79
  // nsIDOMGetSVGDocument
80
  NS_DECL_NSIDOMGETSVGDOCUMENT
81
82
  // nsIContent
83
  virtual bool ParseAttribute(PRInt32 aNamespaceID,
84
                                nsIAtom* aAttribute,
85
                                const nsAString& aValue,
86
                                nsAttrValue& aResult);
87
  NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
88
  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
89
90
  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
91
  virtual nsXPCClassInfo* GetClassInfo();
92
  virtual nsIDOMNode* AsDOMNode() { return this; }
93
};
94
95
96
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
46
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
97
47
98
99
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
48
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
100
                                         FromParser aFromParser)
49
                                         FromParser aFromParser)
101
  : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
50
  : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
102
{
51
{
103
}
52
}
104
53
105
nsHTMLIFrameElement::~nsHTMLIFrameElement()
54
nsHTMLIFrameElement::~nsHTMLIFrameElement()
106
{
55
{
 Lines 132-147   NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Link Here 
132
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
81
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
133
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
82
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
134
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
83
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
135
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
84
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
136
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
85
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
137
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
86
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
138
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
87
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
139
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
88
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
89
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Sandbox, sandbox)
140
90
141
NS_IMETHODIMP
91
NS_IMETHODIMP
142
nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
92
nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
143
{
93
{
144
  return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
94
  return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
145
}
95
}
146
96
147
NS_IMETHODIMP
97
NS_IMETHODIMP
 Lines 269-276   nsHTMLIFrameElement::IsAttributeMapped(c Link Here 
269
219
270
220
271
nsMapRuleToAttributesFunc
221
nsMapRuleToAttributesFunc
272
nsHTMLIFrameElement::GetAttributeMappingFunction() const
222
nsHTMLIFrameElement::GetAttributeMappingFunction() const
273
{
223
{
274
  return &MapAttributesIntoRule;
224
  return &MapAttributesIntoRule;
275
}
225
}
276
226
227
nsresult
228
nsHTMLIFrameElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
229
                                    const nsAttrValue* aValue,
230
                                    bool aNotify)
231
{
232
  if (aName == nsGkAtoms::sandbox && aNameSpaceID == kNameSpaceID_None) {
233
    // Parse the new value of the sandbox attribute, and if we have a docshell
234
    // set its sandbox flags appropriately.
235
    if (mFrameLoader) {
236
      nsCOMPtr<nsIDocShell> docshell = mFrameLoader->GetExistingDocShell();
237
238
      if (docshell) {
239
        PRUint32 newFlags = 0;
240
        // If a NULL aValue is passed in, we want to clear the sandbox flags
241
        // which we will do by setting them to 0.
242
        if (aValue) {
243
          nsAutoString strValue;
244
          aValue->ToString(strValue);
245
          newFlags = nsContentUtils::ParseSandboxAttributeToFlags(
246
            strValue);
247
        }
248
        docshell->SetSandboxFlags(newFlags);
249
      }
250
    }
251
  }
252
  return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
253
                                            aNotify);
254
255
}
(-)a/content/html/content/src/nsHTMLIFrameElement.h (+114 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is Mozilla Communicator client code.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Netscape Communications Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 1998
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either of the GNU General Public License Version 2 or later (the "GPL"),
26
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "mozilla/Util.h"
39
40
#include "nsIDOMHTMLIFrameElement.h"
41
#include "nsGenericHTMLElement.h"
42
#include "nsGenericHTMLFrameElement.h"
43
#include "nsIDOMDocument.h"
44
#include "nsIDOMGetSVGDocument.h"
45
#include "nsIDOMSVGDocument.h"
46
#include "nsGkAtoms.h"
47
#include "nsIDocument.h"
48
#include "nsMappedAttributes.h"
49
#include "nsDOMError.h"
50
#include "nsRuleData.h"
51
#include "nsStyleConsts.h"
52
#include "nsContentUtils.h"
53
54
class nsHTMLIFrameElement : public nsGenericHTMLFrameElement
55
                          , public nsIDOMHTMLIFrameElement
56
                          , public nsIDOMGetSVGDocument
57
{
58
public:
59
  nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
60
                      mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
61
  virtual ~nsHTMLIFrameElement();
62
63
  // nsISupports
64
  NS_DECL_ISUPPORTS_INHERITED
65
66
  // nsIDOMNode
67
  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
68
69
  // nsIDOMElement
70
  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
71
72
  // nsIDOMHTMLElement
73
  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
74
75
  // nsIDOMHTMLIFrameElement
76
  NS_DECL_NSIDOMHTMLIFRAMEELEMENT
77
78
  // nsIDOMGetSVGDocument
79
  NS_DECL_NSIDOMGETSVGDOCUMENT
80
81
  // nsIContent
82
  virtual bool ParseAttribute(PRInt32 aNamespaceID,
83
                                nsIAtom* aAttribute,
84
                                const nsAString& aValue,
85
                                nsAttrValue& aResult);
86
  NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
87
  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
88
89
  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
90
  virtual nsXPCClassInfo* GetClassInfo();
91
  virtual nsIDOMNode* AsDOMNode() { return this; }
92
93
  virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
94
                                  const nsAttrValue* aValue,
95
                                  bool aNotify);
96
97
  PRUint32 GetSandboxFlags() {
98
    nsAutoString sandboxAttr;
99
100
    if (GetAttr(kNameSpaceID_None, nsGkAtoms::sandbox, sandboxAttr)) {
101
      return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
102
    }
103
104
    // No sandbox attribute, no sandbox flags.
105
    return 0;
106
  }
107
108
  static nsHTMLIFrameElement* FromContent(nsIContent *aContent)
109
  {
110
    if (aContent->IsHTML(nsGkAtoms::iframe))
111
      return static_cast<nsHTMLIFrameElement*>(aContent);
112
    return nsnull;
113
  }
114
};
(-)a/content/html/document/src/nsHTMLDocument.cpp (+11 lines)
Line     Link Here 
 Lines 131-146    Link Here 
131
#include "prprf.h"
131
#include "prprf.h"
132
#include "mozilla/dom/Element.h"
132
#include "mozilla/dom/Element.h"
133
#include "mozilla/Preferences.h"
133
#include "mozilla/Preferences.h"
134
#include "nsMimeTypes.h"
134
#include "nsMimeTypes.h"
135
#include "nsIRequest.h"
135
#include "nsIRequest.h"
136
#include "nsHtml5TreeOpExecutor.h"
136
#include "nsHtml5TreeOpExecutor.h"
137
#include "nsHtml5Parser.h"
137
#include "nsHtml5Parser.h"
138
#include "nsIDOMJSWindow.h"
138
#include "nsIDOMJSWindow.h"
139
#include "nsSandboxFlags.h"
139
140
140
using namespace mozilla;
141
using namespace mozilla;
141
using namespace mozilla::dom;
142
using namespace mozilla::dom;
142
143
143
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
144
#define NS_MAX_DOCUMENT_WRITE_DEPTH 20
144
145
145
#include "prmem.h"
146
#include "prmem.h"
146
#include "prtime.h"
147
#include "prtime.h"
 Lines 1249-1264   nsHTMLDocument::GetCookie(nsAString& aCo Link Here 
1249
{
1250
{
1250
  aCookie.Truncate(); // clear current cookie in case service fails;
1251
  aCookie.Truncate(); // clear current cookie in case service fails;
1251
                      // no cookie isn't an error condition.
1252
                      // no cookie isn't an error condition.
1252
1253
1253
  if (mDisableCookieAccess) {
1254
  if (mDisableCookieAccess) {
1254
    return NS_OK;
1255
    return NS_OK;
1255
  }
1256
  }
1256
1257
1258
  // If the document's sandboxed origin flag is set, access to read cookies
1259
  // is prohibited.
1260
  if (mSandboxFlags & SANDBOXED_ORIGIN)
1261
    return NS_ERROR_DOM_SECURITY_ERR;
1262
1257
  // not having a cookie service isn't an error
1263
  // not having a cookie service isn't an error
1258
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1264
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1259
  if (service) {
1265
  if (service) {
1260
    // Get a URI from the document principal. We use the original
1266
    // Get a URI from the document principal. We use the original
1261
    // codebase in case the codebase was changed by SetDomain
1267
    // codebase in case the codebase was changed by SetDomain
1262
    nsCOMPtr<nsIURI> codebaseURI;
1268
    nsCOMPtr<nsIURI> codebaseURI;
1263
    NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
1269
    NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
1264
1270
 Lines 1279-1294   nsHTMLDocument::GetCookie(nsAString& aCo Link Here 
1279
1285
1280
NS_IMETHODIMP
1286
NS_IMETHODIMP
1281
nsHTMLDocument::SetCookie(const nsAString& aCookie)
1287
nsHTMLDocument::SetCookie(const nsAString& aCookie)
1282
{
1288
{
1283
  if (mDisableCookieAccess) {
1289
  if (mDisableCookieAccess) {
1284
    return NS_OK;
1290
    return NS_OK;
1285
  }
1291
  }
1286
1292
1293
  // If the document's sandboxed origin flag is set, access to write cookies
1294
  // is prohibited.
1295
  if (mSandboxFlags & SANDBOXED_ORIGIN)
1296
    return NS_ERROR_DOM_SECURITY_ERR;
1297
1287
  // not having a cookie service isn't an error
1298
  // not having a cookie service isn't an error
1288
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1299
  nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
1289
  if (service && mDocumentURI) {
1300
  if (service && mDocumentURI) {
1290
    nsCOMPtr<nsIPrompt> prompt;
1301
    nsCOMPtr<nsIPrompt> prompt;
1291
    nsCOMPtr<nsPIDOMWindow> window = GetWindow();
1302
    nsCOMPtr<nsPIDOMWindow> window = GetWindow();
1292
    if (window) {
1303
    if (window) {
1293
      window->GetPrompter(getter_AddRefs(prompt));
1304
      window->GetPrompter(getter_AddRefs(prompt));
1294
    }
1305
    }
(-)a/docshell/base/Makefile.in (+1 lines)
Line     Link Here 
 Lines 119-127   include $(topsrcdir)/config/config.mk Link Here 
119
include $(topsrcdir)/ipc/chromium/chromium-config.mk
119
include $(topsrcdir)/ipc/chromium/chromium-config.mk
120
include $(topsrcdir)/config/rules.mk
120
include $(topsrcdir)/config/rules.mk
121
121
122
LOCAL_INCLUDES += \
122
LOCAL_INCLUDES += \
123
  -I$(srcdir)/../shistory/src \
123
  -I$(srcdir)/../shistory/src \
124
  -I$(topsrcdir)/dom/base \
124
  -I$(topsrcdir)/dom/base \
125
  -I$(topsrcdir)/layout/base \
125
  -I$(topsrcdir)/layout/base \
126
  -I$(topsrcdir)/xpcom/ds \
126
  -I$(topsrcdir)/xpcom/ds \
127
  -I$(topsrcdir)/content/base/src \
127
  $(NULL)
128
  $(NULL)
(-)a/docshell/base/nsDocShell.cpp (-2 / +101 lines)
Line     Link Here 
 Lines 216-231    Link Here 
216
#include "nsIWebBrowserPrint.h"
216
#include "nsIWebBrowserPrint.h"
217
#endif
217
#endif
218
218
219
#include "nsPluginError.h"
219
#include "nsPluginError.h"
220
#include "nsContentUtils.h"
220
#include "nsContentUtils.h"
221
#include "nsContentErrors.h"
221
#include "nsContentErrors.h"
222
#include "nsIChannelPolicy.h"
222
#include "nsIChannelPolicy.h"
223
#include "nsIContentSecurityPolicy.h"
223
#include "nsIContentSecurityPolicy.h"
224
#include "nsSandboxFlags.h"
224
225
225
#include "nsXULAppAPI.h"
226
#include "nsXULAppAPI.h"
226
227
227
#include "nsDOMNavigationTiming.h"
228
#include "nsDOMNavigationTiming.h"
228
#include "nsITimedChannel.h"
229
#include "nsITimedChannel.h"
229
#include "mozilla/StartupTimeline.h"
230
#include "mozilla/StartupTimeline.h"
230
231
231
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
232
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
 Lines 766-781   nsDocShell::nsDocShell(): Link Here 
766
    mBusyFlags(BUSY_FLAGS_NONE),
767
    mBusyFlags(BUSY_FLAGS_NONE),
767
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
768
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
768
    mLoadType(0),
769
    mLoadType(0),
769
    mMarginWidth(-1),
770
    mMarginWidth(-1),
770
    mMarginHeight(-1),
771
    mMarginHeight(-1),
771
    mItemType(typeContent),
772
    mItemType(typeContent),
772
    mPreviousTransIndex(-1),
773
    mPreviousTransIndex(-1),
773
    mLoadedTransIndex(-1),
774
    mLoadedTransIndex(-1),
775
    mSandboxFlags(0),
774
    mCreated(false),
776
    mCreated(false),
775
    mAllowSubframes(true),
777
    mAllowSubframes(true),
776
    mAllowPlugins(true),
778
    mAllowPlugins(true),
777
    mAllowJavascript(true),
779
    mAllowJavascript(true),
778
    mAllowMetaRedirects(true),
780
    mAllowMetaRedirects(true),
779
    mAllowImages(true),
781
    mAllowImages(true),
780
    mAllowDNSPrefetch(true),
782
    mAllowDNSPrefetch(true),
781
    mAllowWindowControl(true),
783
    mAllowWindowControl(true),
 Lines 2986-3001   nsDocShell::FindItemWithName(const PRUni Link Here 
2986
            foundItem = nsnull;
2988
            foundItem = nsnull;
2987
        }
2989
        }
2988
2990
2989
        if (foundItem) {
2991
        if (foundItem) {
2990
            // We return foundItem here even if it's not an active
2992
            // We return foundItem here even if it's not an active
2991
            // item since all the names we've dealt with so far are
2993
            // item since all the names we've dealt with so far are
2992
            // special cases that we won't bother looking for further.
2994
            // special cases that we won't bother looking for further.
2993
2995
2996
            // If our document is sandboxed, we need to do some extra checks.
2997
            PRUint32 sandboxFlags = 0;
2998
2999
            nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor);
3000
3001
            if (doc) {
3002
              sandboxFlags = doc->SandboxFlags();
3003
            }
3004
3005
            if (sandboxFlags) {
3006
                nsCOMPtr<nsIDocShellTreeItem> root;
3007
                GetSameTypeRootTreeItem(getter_AddRefs(root));
3008
3009
                // Is the found item not a top level browsing context and not ourself ?
3010
                nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this);
3011
                if (foundItem != root && foundItem != selfAsItem) {
3012
                    // Are we an ancestor of the foundItem ?
3013
                    bool isAncestor = false;
3014
3015
                    nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
3016
                    GetSameTypeParent(getter_AddRefs(parentAsItem));
3017
3018
                    while (parentAsItem) {
3019
                        nsCOMPtr<nsIDocShellTreeItem> tmp;
3020
                        parentAsItem->GetParent(getter_AddRefs(tmp));
3021
3022
                        if (tmp && tmp == selfAsItem) {
3023
                            isAncestor = true;
3024
                            break;
3025
                        }
3026
                        parentAsItem = tmp;
3027
                    }
3028
3029
                    if (!isAncestor) {
3030
                        // No, we are not an ancestor and our document is
3031
                        // sandboxed, we can't allow this.
3032
                        foundItem = nsnull;
3033
                    }
3034
                } else {
3035
                    // Top level browsing context - is it an ancestor of ours ?
3036
                    nsCOMPtr<nsIDocShellTreeItem> tmp;
3037
                    GetSameTypeParent(getter_AddRefs(tmp));
3038
3039
                    while (tmp) {
3040
                        if (tmp && tmp == foundItem) {
3041
                            // This is an ancestor, and we are sandboxed.
3042
                            // Unless allow-top-navigation is set, we can't allow this.
3043
                            if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) {
3044
                              foundItem = nsnull;
3045
                            }
3046
                            break;
3047
                        }
3048
                        tmp->GetParent(getter_AddRefs(tmp));
3049
                    }
3050
                }
3051
            }
3052
2994
            foundItem.swap(*_retval);
3053
            foundItem.swap(*_retval);
2995
            return NS_OK;
3054
            return NS_OK;
2996
        }
3055
        }
2997
    }
3056
    }
2998
3057
2999
    // Keep looking
3058
    // Keep looking
3000
        
3059
        
3001
    // First we check our name.
3060
    // First we check our name.
 Lines 5026-5041   nsDocShell::SetIsAppTab(bool aIsAppTab) Link Here 
5026
NS_IMETHODIMP
5085
NS_IMETHODIMP
5027
nsDocShell::GetIsAppTab(bool *aIsAppTab)
5086
nsDocShell::GetIsAppTab(bool *aIsAppTab)
5028
{
5087
{
5029
  *aIsAppTab = mIsAppTab;
5088
  *aIsAppTab = mIsAppTab;
5030
  return NS_OK;
5089
  return NS_OK;
5031
}
5090
}
5032
5091
5033
NS_IMETHODIMP
5092
NS_IMETHODIMP
5093
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags)
5094
{
5095
  mSandboxFlags = aSandboxFlags;
5096
  return NS_OK;
5097
}
5098
5099
NS_IMETHODIMP
5100
nsDocShell::GetSandboxFlags(PRUint32  *aSandboxFlags)
5101
{
5102
  *aSandboxFlags = mSandboxFlags;
5103
  return NS_OK;
5104
}
5105
5106
NS_IMETHODIMP
5034
nsDocShell::SetVisibility(bool aVisibility)
5107
nsDocShell::SetVisibility(bool aVisibility)
5035
{
5108
{
5036
    if (!mContentViewer)
5109
    if (!mContentViewer)
5037
        return NS_OK;
5110
        return NS_OK;
5038
    if (aVisibility) {
5111
    if (aVisibility) {
5039
        mContentViewer->Show();
5112
        mContentViewer->Show();
5040
    }
5113
    }
5041
    else {
5114
    else {
 Lines 8247-8262   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
8247
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8320
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8248
        FindItemWithName(aWindowTarget, nsnull, this,
8321
        FindItemWithName(aWindowTarget, nsnull, this,
8249
                         getter_AddRefs(targetItem));
8322
                         getter_AddRefs(targetItem));
8250
8323
8251
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8324
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8252
        
8325
        
8253
        bool isNewWindow = false;
8326
        bool isNewWindow = false;
8254
        if (!targetDocShell) {
8327
        if (!targetDocShell) {
8328
            // If the docshell's document is sandboxed and was trying to
8329
            // navigate/load a frame it wasn't allowed to access, the
8330
            // FindItemWithName above will have returned null for the target
8331
            // item - we don't want to actually open a new window in this case
8332
            // though. Check if we are sandboxed and bail out here if so.
8333
            NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
8334
            nsIDocument* doc = mContentViewer->GetDocument();
8335
            PRUint32 sandboxFlags = 0;
8336
            sandboxFlags = doc->SandboxFlags();
8337
            if (sandboxFlags & SANDBOXED_NAVIGATION) {
8338
              return NS_ERROR_FAILURE;
8339
            }
8340
8255
            nsCOMPtr<nsIDOMWindow> win =
8341
            nsCOMPtr<nsIDOMWindow> win =
8256
                do_GetInterface(GetAsSupports(this));
8342
                do_GetInterface(GetAsSupports(this));
8257
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8343
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8258
8344
8259
            nsDependentString name(aWindowTarget);
8345
            nsDependentString name(aWindowTarget);
8260
            nsCOMPtr<nsIDOMWindow> newWin;
8346
            nsCOMPtr<nsIDOMWindow> newWin;
8261
            rv = win->Open(EmptyString(), // URL to load
8347
            rv = win->Open(EmptyString(), // URL to load
8262
                           name,          // window name
8348
                           name,          // window name
 Lines 9034-9051   nsDocShell::DoURILoad(nsIURI * aURI, Link Here 
9034
        }
9120
        }
9035
        // Set the referrer explicitly
9121
        // Set the referrer explicitly
9036
        if (aReferrerURI && aSendReferrer) {
9122
        if (aReferrerURI && aSendReferrer) {
9037
            // Referrer is currenly only set for link clicks here.
9123
            // Referrer is currenly only set for link clicks here.
9038
            httpChannel->SetReferrer(aReferrerURI);
9124
            httpChannel->SetReferrer(aReferrerURI);
9039
        }
9125
        }
9040
    }
9126
    }
9041
9127
9042
    nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner));
9128
    nsCOMPtr<nsIPrincipal> ownerPrincipal;
9043
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true);
9129
9130
    // If the content being loaded should be sandboxed with respect to origin
9131
    // we need to create a new null principal here, and then tell
9132
    // nsContentUtils::SetUpChannelOwner to force it to be set as the
9133
    // channel owner.
9134
    if (mSandboxFlags & SANDBOXED_ORIGIN) {
9135
      ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
9136
    } else {
9137
      // Not sandboxed - we allow the content to assume its natural owner.
9138
      ownerPrincipal = do_QueryInterface(aOwner);
9139
    }
9140
9141
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true,
9142
                                       (mSandboxFlags & SANDBOXED_ORIGIN));
9044
9143
9045
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
9144
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
9046
    if (scriptChannel) {
9145
    if (scriptChannel) {
9047
        // Allow execution against our context if the principals match
9146
        // Allow execution against our context if the principals match
9048
        scriptChannel->
9147
        scriptChannel->
9049
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
9148
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
9050
    }
9149
    }
9051
9150
(-)a/docshell/base/nsDocShell.h (+2 lines)
Line     Link Here 
 Lines 784-799   protected: Link Here 
784
    // Create() is called, the type is not expected to change.
784
    // Create() is called, the type is not expected to change.
785
    PRInt32                    mItemType;
785
    PRInt32                    mItemType;
786
786
787
    // Index into the SHTransaction list, indicating the previous and current
787
    // Index into the SHTransaction list, indicating the previous and current
788
    // transaction at the time that this DocShell begins to load
788
    // transaction at the time that this DocShell begins to load
789
    PRInt32                    mPreviousTransIndex;
789
    PRInt32                    mPreviousTransIndex;
790
    PRInt32                    mLoadedTransIndex;
790
    PRInt32                    mLoadedTransIndex;
791
791
792
    PRUint32                   mSandboxFlags;
793
792
    bool                       mCreated;
794
    bool                       mCreated;
793
    bool                       mAllowSubframes;
795
    bool                       mAllowSubframes;
794
    bool                       mAllowPlugins;
796
    bool                       mAllowPlugins;
795
    bool                       mAllowJavascript;
797
    bool                       mAllowJavascript;
796
    bool                       mAllowMetaRedirects;
798
    bool                       mAllowMetaRedirects;
797
    bool                       mAllowImages;
799
    bool                       mAllowImages;
798
    bool                       mAllowDNSPrefetch;
800
    bool                       mAllowDNSPrefetch;
799
    bool                       mAllowWindowControl;
801
    bool                       mAllowWindowControl;
(-)a/docshell/base/nsIDocShell.idl (-1 / +15 lines)
Line     Link Here 
 Lines 68-84   interface nsISHEntry; Link Here 
68
interface nsILayoutHistoryState;
68
interface nsILayoutHistoryState;
69
interface nsISecureBrowserUI;
69
interface nsISecureBrowserUI;
70
interface nsIDOMStorage;
70
interface nsIDOMStorage;
71
interface nsIPrincipal;
71
interface nsIPrincipal;
72
interface nsIWebBrowserPrint;
72
interface nsIWebBrowserPrint;
73
interface nsIVariant;
73
interface nsIVariant;
74
interface nsIPrivacyTransitionObserver;
74
interface nsIPrivacyTransitionObserver;
75
75
76
[scriptable, uuid(6f60ac96-fa2c-41a5-92b4-29aaadbd7a7b)]
76
[scriptable, uuid(9b283337-097d-4fa8-a2da-916318eaf828)]
77
interface nsIDocShell : nsISupports
77
interface nsIDocShell : nsISupports
78
{
78
{
79
  /**
79
  /**
80
   * Loads a given URI.  This will give priority to loading the requested URI
80
   * Loads a given URI.  This will give priority to loading the requested URI
81
   * in the object implementing	this interface.  If it can't be loaded here
81
   * in the object implementing	this interface.  If it can't be loaded here
82
   * however, the URL dispatcher will go through its normal process of content
82
   * however, the URL dispatcher will go through its normal process of content
83
   * loading.
83
   * loading.
84
   *
84
   *
 Lines 622-630   interface nsIDocShell : nsISupports Link Here 
622
   */
622
   */
623
  attribute bool isBrowserFrame;
623
  attribute bool isBrowserFrame;
624
624
625
  /*
625
  /*
626
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
626
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
627
   * indirectly?
627
   * indirectly?
628
   */
628
   */
629
  readonly attribute bool containedInBrowserFrame;
629
  readonly attribute bool containedInBrowserFrame;
630
631
  /**
632
   * The sandbox flags on the docshell. These reflect the value of the sandbox
633
   * attribute of the associated IFRAME or CSP-protectable content, if
634
   * existent. See the HTML5 spec for more details.
635
   * These flags on the docshell reflect the current state of the sandbox
636
   * attribute, which is modifiable. They are only used when loading new
637
   * content, sandbox flags are also immutably set on the document when it is
638
   * loaded.
639
   * The sandbox flags of a document depend on the sandbox flags on its
640
   * docshell and of its parent document, if any.
641
   * See nsSandboxFlags.h for the possible flags.
642
   */
643
  attribute unsigned long sandboxFlags;
630
};
644
};
(-)a/dom/base/nsGlobalWindow.cpp (+13 lines)
Line     Link Here 
 Lines 255-270    Link Here 
255
255
256
#include "nsRefreshDriver.h"
256
#include "nsRefreshDriver.h"
257
#include "mozAutoDocUpdate.h"
257
#include "mozAutoDocUpdate.h"
258
258
259
#include "mozilla/Telemetry.h"
259
#include "mozilla/Telemetry.h"
260
#include "nsLocation.h"
260
#include "nsLocation.h"
261
#include "nsWrapperCacheInlines.h"
261
#include "nsWrapperCacheInlines.h"
262
#include "nsDOMEventTargetHelper.h"
262
#include "nsDOMEventTargetHelper.h"
263
#include "nsSandboxFlags.h"
263
264
264
#ifdef ANDROID
265
#ifdef ANDROID
265
#include <android/log.h>
266
#include <android/log.h>
266
#endif
267
#endif
267
268
268
#ifdef PR_LOGGING
269
#ifdef PR_LOGGING
269
static PRLogModuleInfo* gDOMLeakPRLog;
270
static PRLogModuleInfo* gDOMLeakPRLog;
270
#endif
271
#endif
 Lines 7986-8001   nsGlobalWindow::GetSessionStorage(nsIDOM Link Here 
7986
  if (!mSessionStorage) {
7987
  if (!mSessionStorage) {
7987
    *aSessionStorage = nsnull;
7988
    *aSessionStorage = nsnull;
7988
7989
7989
    nsString documentURI;
7990
    nsString documentURI;
7990
    if (mDocument) {
7991
    if (mDocument) {
7991
      mDocument->GetDocumentURI(documentURI);
7992
      mDocument->GetDocumentURI(documentURI);
7992
    }
7993
    }
7993
7994
7995
    // If the document has the sandboxed origin flag set
7996
    // don't allow access to localStorage.
7997
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
7998
      return NS_ERROR_DOM_SECURITY_ERR;
7999
    }
8000
7994
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
8001
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
7995
                                                          documentURI,
8002
                                                          documentURI,
7996
                                                          true,
8003
                                                          true,
7997
                                                          getter_AddRefs(mSessionStorage));
8004
                                                          getter_AddRefs(mSessionStorage));
7998
    NS_ENSURE_SUCCESS(rv, rv);
8005
    NS_ENSURE_SUCCESS(rv, rv);
7999
8006
8000
#ifdef PR_LOGGING
8007
#ifdef PR_LOGGING
8001
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
8008
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
 Lines 8047-8062   nsGlobalWindow::GetLocalStorage(nsIDOMSt Link Here 
8047
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8054
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8048
    NS_ENSURE_SUCCESS(rv, rv);
8055
    NS_ENSURE_SUCCESS(rv, rv);
8049
8056
8050
    nsString documentURI;
8057
    nsString documentURI;
8051
    if (mDocument) {
8058
    if (mDocument) {
8052
      mDocument->GetDocumentURI(documentURI);
8059
      mDocument->GetDocumentURI(documentURI);
8053
    }
8060
    }
8054
8061
8062
    // If the document has the sandboxed origin flag set
8063
    // don't allow access to localStorage.
8064
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
8065
      return NS_ERROR_DOM_SECURITY_ERR;
8066
    }
8067
8055
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8068
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8056
                                                     documentURI,
8069
                                                     documentURI,
8057
                                                     getter_AddRefs(mLocalStorage));
8070
                                                     getter_AddRefs(mLocalStorage));
8058
    NS_ENSURE_SUCCESS(rv, rv);
8071
    NS_ENSURE_SUCCESS(rv, rv);
8059
  }
8072
  }
8060
8073
8061
  NS_ADDREF(*aLocalStorage = mLocalStorage);
8074
  NS_ADDREF(*aLocalStorage = mLocalStorage);
8062
  return NS_OK;
8075
  return NS_OK;
(-)a/dom/interfaces/html/nsIDOMHTMLIFrameElement.idl (-2 / +2 lines)
Line     Link Here 
 Lines 45-76    Link Here 
45
 *
45
 *
46
 * This interface is trying to follow the DOM Level 2 HTML specification:
46
 * This interface is trying to follow the DOM Level 2 HTML specification:
47
 * http://www.w3.org/TR/DOM-Level-2-HTML/
47
 * http://www.w3.org/TR/DOM-Level-2-HTML/
48
 *
48
 *
49
 * with changes from the work-in-progress WHATWG HTML specification:
49
 * with changes from the work-in-progress WHATWG HTML specification:
50
 * http://www.whatwg.org/specs/web-apps/current-work/
50
 * http://www.whatwg.org/specs/web-apps/current-work/
51
 */
51
 */
52
52
53
[scriptable, uuid(97E4F0E1-BD27-40EC-9287-5634DAF15B73)]
53
[scriptable, uuid(52f6244b-b1f5-4f4c-8ff3-7e146316f411)]
54
interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
54
interface nsIDOMHTMLIFrameElement : nsIDOMHTMLElement
55
{
55
{
56
           attribute DOMString        align;
56
           attribute DOMString        align;
57
           attribute DOMString        frameBorder;
57
           attribute DOMString        frameBorder;
58
           attribute DOMString        height;
58
           attribute DOMString        height;
59
           attribute DOMString        longDesc;
59
           attribute DOMString        longDesc;
60
           attribute DOMString        marginHeight;
60
           attribute DOMString        marginHeight;
61
           attribute DOMString        marginWidth;
61
           attribute DOMString        marginWidth;
62
           attribute DOMString        name;
62
           attribute DOMString        name;
63
           attribute DOMString        scrolling;
63
           attribute DOMString        scrolling;
64
           attribute DOMString        src;
64
           attribute DOMString        src;
65
           attribute DOMString        width;
65
           attribute DOMString        width;
66
  // Introduced in DOM Level 2:
66
  // Introduced in DOM Level 2:
67
  readonly attribute nsIDOMDocument   contentDocument;
67
  readonly attribute nsIDOMDocument   contentDocument;
68
  readonly attribute nsIDOMWindow     contentWindow;
68
  readonly attribute nsIDOMWindow     contentWindow;
69
69
70
70
           attribute DOMString        sandbox;
71
  // Mozilla extensions
71
  // Mozilla extensions
72
  // iframe elements require the mozAllowFullScreen attribute to be present
72
  // iframe elements require the mozAllowFullScreen attribute to be present
73
  // if they're to allow content in the sub document to go into DOM full-screen
73
  // if they're to allow content in the sub document to go into DOM full-screen
74
  // mode. See https://wiki.mozilla.org/index.php?title=Gecko:FullScreenAPI
74
  // mode. See https://wiki.mozilla.org/index.php?title=Gecko:FullScreenAPI
75
           attribute boolean          mozAllowFullScreen;
75
           attribute boolean          mozAllowFullScreen;
76
};
76
};
(-)a/dom/src/jsurl/Makefile.in (+1 lines)
Line     Link Here 
 Lines 57-72   XPIDLSRCS = \ Link Here 
57
CPPSRCS		= nsJSProtocolHandler.cpp
57
CPPSRCS		= nsJSProtocolHandler.cpp
58
58
59
EXPORTS		= $(srcdir)/nsJSProtocolHandler.h
59
EXPORTS		= $(srcdir)/nsJSProtocolHandler.h
60
60
61
LOCAL_INCLUDES += \
61
LOCAL_INCLUDES += \
62
		-I$(srcdir) \
62
		-I$(srcdir) \
63
		-I$(topsrcdir)/dom/base \
63
		-I$(topsrcdir)/dom/base \
64
		-I$(topsrcdir)/netwerk/base/src \
64
		-I$(topsrcdir)/netwerk/base/src \
65
		-I$(topsrcdir)/content/base/src \
65
66
66
ifdef BUILD_DEBUG_GC
67
ifdef BUILD_DEBUG_GC
67
DEFINES		+= -DDEBUG_GC
68
DEFINES		+= -DDEBUG_GC
68
endif
69
endif
69
70
70
DIRS            = $(NULL)
71
DIRS            = $(NULL)
71
TEST_DIRS += test
72
TEST_DIRS += test
72
73
(-)a/dom/src/jsurl/nsJSProtocolHandler.cpp (+13 lines)
Line     Link Here 
 Lines 74-89    Link Here 
74
#include "nsThreadUtils.h"
74
#include "nsThreadUtils.h"
75
#include "nsIJSContextStack.h"
75
#include "nsIJSContextStack.h"
76
#include "nsIScriptChannel.h"
76
#include "nsIScriptChannel.h"
77
#include "nsIDocument.h"
77
#include "nsIDocument.h"
78
#include "nsIObjectInputStream.h"
78
#include "nsIObjectInputStream.h"
79
#include "nsIObjectOutputStream.h"
79
#include "nsIObjectOutputStream.h"
80
#include "nsIWritablePropertyBag2.h"
80
#include "nsIWritablePropertyBag2.h"
81
#include "nsIContentSecurityPolicy.h"
81
#include "nsIContentSecurityPolicy.h"
82
#include "nsSandboxFlags.h"
82
83
83
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
84
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
84
85
85
class nsJSThunk : public nsIInputStream
86
class nsJSThunk : public nsIInputStream
86
{
87
{
87
public:
88
public:
88
    nsJSThunk();
89
    nsJSThunk();
89
90
 Lines 220-235   nsresult nsJSThunk::EvaluateScript(nsICh Link Here 
220
    // Get the global object we should be running on.
221
    // Get the global object we should be running on.
221
    nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
222
    nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
222
    if (!global) {
223
    if (!global) {
223
        return NS_ERROR_FAILURE;
224
        return NS_ERROR_FAILURE;
224
    }
225
    }
225
226
226
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
227
    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
227
228
229
    // Sandboxed document check: javascript: URI's are disabled
230
    // in a sandboxed document unless 'allow-scripts' was specified
231
232
    // REVIEW - it seems like the original inner window would be the one
233
    // that will execute the javascript with its principal - is this
234
    // assumption correct ?? (and is GetExtantDocument() the right way
235
    // to get the right document ??
236
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(aOriginalInnerWindow->GetExtantDocument());
237
    if (doc && (doc->SandboxFlags() & SANDBOXED_SCRIPTS)) {
238
      return NS_ERROR_DOM_RETVAL_UNDEFINED;
239
    }
240
228
    // Push our popup control state
241
    // Push our popup control state
229
    nsAutoPopupStatePusher popupStatePusher(win, aPopupState);
242
    nsAutoPopupStatePusher popupStatePusher(win, aPopupState);
230
243
231
    // Make sure we still have the same inner window as we used to.
244
    // Make sure we still have the same inner window as we used to.
232
    nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
245
    nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
233
246
234
    if (innerWin != aOriginalInnerWindow) {
247
    if (innerWin != aOriginalInnerWindow) {
235
        return NS_ERROR_UNEXPECTED;
248
        return NS_ERROR_UNEXPECTED;
(-)a/embedding/components/windowwatcher/src/Makefile.in (-1 / +2 lines)
Line     Link Here 
 Lines 56-66   CPPSRCS += nsDialogParamBlock.cpp \ Link Here 
56
		   $(NULL)
56
		   $(NULL)
57
endif
57
endif
58
58
59
# we don't want the shared lib, but we want to force the creation of a
59
# we don't want the shared lib, but we want to force the creation of a
60
# static lib.
60
# static lib.
61
FORCE_STATIC_LIB = 1
61
FORCE_STATIC_LIB = 1
62
62
63
# For nsJSUtils
63
# For nsJSUtils
64
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base
64
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base \
65
		  -I$(topsrcdir)/content/base/src \
65
66
66
include $(topsrcdir)/config/rules.mk
67
include $(topsrcdir)/config/rules.mk
(-)a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp (+18 lines)
Line     Link Here 
 Lines 86-101    Link Here 
86
#include "nsPIDOMStorage.h"
86
#include "nsPIDOMStorage.h"
87
#include "nsIWidget.h"
87
#include "nsIWidget.h"
88
#include "nsFocusManager.h"
88
#include "nsFocusManager.h"
89
#include "nsIPresShell.h"
89
#include "nsIPresShell.h"
90
#include "nsPresContext.h"
90
#include "nsPresContext.h"
91
#include "nsContentUtils.h"
91
#include "nsContentUtils.h"
92
#include "nsIPrefBranch.h"
92
#include "nsIPrefBranch.h"
93
#include "nsIPrefService.h"
93
#include "nsIPrefService.h"
94
#include "nsSandboxFlags.h"
94
95
95
#ifdef USEWEAKREFS
96
#ifdef USEWEAKREFS
96
#include "nsIWeakReference.h"
97
#include "nsIWeakReference.h"
97
#endif
98
#endif
98
99
99
using namespace mozilla;
100
using namespace mozilla;
100
101
101
static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
102
static const char *sJSStackContractID="@mozilla.org/js/xpc/ContextStack;1";
 Lines 603-618   nsWindowWatcher::OpenWindowJSInternal(ns Link Here 
603
  }
604
  }
604
605
605
  if (!newDocShellItem) {
606
  if (!newDocShellItem) {
606
    // We're going to either open up a new window ourselves or ask a
607
    // We're going to either open up a new window ourselves or ask a
607
    // nsIWindowProvider for one.  In either case, we'll want to set the right
608
    // nsIWindowProvider for one.  In either case, we'll want to set the right
608
    // name on it.
609
    // name on it.
609
    windowNeedsName = true;
610
    windowNeedsName = true;
610
611
612
    // If the parent trying to open a new window is sandboxed,
613
    // this is not allowed and we fail here.
614
    if (aParent) {
615
      nsCOMPtr<nsIDOMDocument> domdoc;
616
      aParent->GetDocument(getter_AddRefs(domdoc));
617
      nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
618
619
      if (doc) {
620
        PRUint32 sandboxFlags = 0;
621
        sandboxFlags = doc->SandboxFlags();
622
623
        if (sandboxFlags & SANDBOXED_NAVIGATION) {
624
          return NS_ERROR_FAILURE;
625
        }
626
      }
627
    }
628
611
    // Now check whether it's ok to ask a window provider for a window.  Don't
629
    // Now check whether it's ok to ask a window provider for a window.  Don't
612
    // do it if we're opening a dialog or if our parent is a chrome window or
630
    // do it if we're opening a dialog or if our parent is a chrome window or
613
    // if we're opening something that has modal, dialog, or chrome flags set.
631
    // if we're opening something that has modal, dialog, or chrome flags set.
614
    nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(aParent);
632
    nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(aParent);
615
    if (!aDialog && !chromeWin &&
633
    if (!aDialog && !chromeWin &&
616
        !(chromeFlags & (nsIWebBrowserChrome::CHROME_MODAL         |
634
        !(chromeFlags & (nsIWebBrowserChrome::CHROME_MODAL         |
617
                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 
635
                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 
618
                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {
636
                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {

Return to bug 341604