Attachment #616405: iframe sandbox v12 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 826-841   public: Link Here 
826
  /**
826
  /**
827
   * Get the localized string named |aKey| in properties file |aFile|.
827
   * Get the localized string named |aKey| in properties file |aFile|.
828
   */
828
   */
829
  static nsresult GetLocalizedString(PropertiesFile aFile,
829
  static nsresult GetLocalizedString(PropertiesFile aFile,
830
                                     const char* aKey,
830
                                     const char* aKey,
831
                                     nsXPIDLString& aResult);
831
                                     nsXPIDLString& aResult);
832
832
833
  /**
833
  /**
834
   * A helper function that parses a sandbox attribute (of an <iframe> or
835
   * a CSP directive) and converts it to the set of flags used internally.
836
   *
837
   * @param aAttribute 	the value of the sandbox attribute
838
   * @return 			the set of flags
839
   */
840
  static PRUint32 ParseSandboxAttributeToFlags(const nsAString&
841
                                                 sandboxAttr);
842
843
844
  /**
834
   * Fill (with the parameters given) the localized string named |aKey| in
845
   * Fill (with the parameters given) the localized string named |aKey| in
835
   * properties file |aFile|.
846
   * properties file |aFile|.
836
   */
847
   */
837
private:
848
private:
838
  static nsresult FormatLocalizedString(PropertiesFile aFile,
849
  static nsresult FormatLocalizedString(PropertiesFile aFile,
839
                                        const char* aKey,
850
                                        const char* aKey,
840
                                        const PRUnichar** aParams,
851
                                        const PRUnichar** aParams,
841
                                        PRUint32 aParamsLength,
852
                                        PRUint32 aParamsLength,
 Lines 1929-1970   public: Link Here 
1929
   * from the document it comes from.
1940
   * from the document it comes from.
1930
   */
1941
   */
1931
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1942
  static nsresult URIInheritsSecurityContext(nsIURI *aURI, bool *aResult);
1932
1943
1933
  /**
1944
  /**
1934
   * Set the given principal as the owner of the given channel, if
1945
   * Set the given principal as the owner of the given channel, if
1935
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1946
   * needed.  aURI must be the URI of aChannel.  aPrincipal may be
1936
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1947
   * null.  If aSetUpForAboutBlank is true, then about:blank will get
1937
   * the principal set up on it.
1948
   * the principal set up on it. If aForceOwner is true, the owner
1938
   *
1949
   * will be set on the channel, even if the principal can be determined
1950
   * from the channel.
1939
   * The return value is whether the principal was set up as the owner
1951
   * The return value is whether the principal was set up as the owner
1940
   * of the channel.
1952
   * of the channel.
1941
   */
1953
   */
1942
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1954
  static bool SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
1943
                                nsIChannel* aChannel,
1955
                                nsIChannel* aChannel,
1944
                                nsIURI* aURI,
1956
                                nsIURI* aURI,
1945
                                bool aSetUpForAboutBlank);
1957
                                bool aSetUpForAboutBlank,
1958
                                bool aForceOwner = false);
1946
1959
1947
  static nsresult Btoa(const nsAString& aBinaryData,
1960
  static nsresult Btoa(const nsAString& aBinaryData,
1948
                       nsAString& aAsciiBase64String);
1961
                       nsAString& aAsciiBase64String);
1949
1962
1950
  static nsresult Atob(const nsAString& aAsciiString,
1963
  static nsresult Atob(const nsAString& aAsciiString,
1951
                       nsAString& aBinaryData);
1964
                       nsAString& aBinaryData);
1952
1965
1953
  /** If aJSArray is a Javascript array, this method iterates over its
1966
  /** If aJSArray is a Javascript array, this method iterates over its
1954
   *  elements and appends values to aRetVal as nsIAtoms.
1967
   *  elements and appends values to aRetVal as nsIAtoms.
1955
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1968
   *  @throw NS_ERROR_ILLEGAL_VALUE if aJSArray isn't a JS array.
1956
   */ 
1969
   */ 
1957
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1970
  static nsresult JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
1958
                                     nsCOMArray<nsIAtom>& aRetVal);
1971
                                     nsCOMArray<nsIAtom>& aRetVal);
1959
1972
1960
  /**
1973
  /**
1961
   * Returns whether the input element passed in parameter has the autocomplete
1974
   * Returns whether the input element passed in parameter has the autocomplete
1962
   * functionnality enabled. It is taking into account the form owner.
1975
   * functionality enabled. It is taking into account the form owner.
1963
   * NOTE: the caller has to make sure autocomplete makes sense for the
1976
   * NOTE: the caller has to make sure autocomplete makes sense for the
1964
   * element's type.
1977
   * element's type.
1965
   *
1978
   *
1966
   * @param aInput the input element to check. NOTE: aInput can't be null.
1979
   * @param aInput the input element to check. NOTE: aInput can't be null.
1967
   * @return whether the input element has autocomplete enabled.
1980
   * @return whether the input element has autocomplete enabled.
1968
   */
1981
   */
1969
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
1982
  static bool IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput);
1970
1983
(-)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 209-224   static NS_DEFINE_CID(kXTFServiceCID, NS_ Link Here 
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 "nsIDOMWindowUtils.h"
215
#include "nsIDOMWindowUtils.h"
216
#include "nsCharSeparatedTokenizer.h"
216
#include "nsCharSeparatedTokenizer.h"
217
#include "nsSandboxFlags.h"
217
218
218
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
219
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
219
                                      const char** next, PRUnichar* result);
220
                                      const char** next, PRUnichar* result);
220
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
221
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
221
                                 int ns_aware, const char** colon);
222
                                 int ns_aware, const char** colon);
222
223
223
using namespace mozilla::dom;
224
using namespace mozilla::dom;
224
using namespace mozilla::layers;
225
using namespace mozilla::layers;
 Lines 917-932   nsContentUtils::GetParserService() Link Here 
917
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
918
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
918
    if (NS_FAILED(rv)) {
919
    if (NS_FAILED(rv)) {
919
      sParserService = nsnull;
920
      sParserService = nsnull;
920
    }
921
    }
921
  }
922
  }
922
923
923
  return sParserService;
924
  return sParserService;
924
}
925
}
926
/**
927
 * A helper function that parses a sandbox attribute (of an <iframe> or
928
 * a CSP directive) and converts it to the set of flags used internally.
929
 *
930
 * @param aAttribute    the value of the sandbox attribute
931
 * @return              the set of flags
932
 */
933
PRUint32
934
nsContentUtils::ParseSandboxAttributeToFlags(const nsAString& sandboxAttrValue)
935
{
936
  // If there's a sandbox attribute at all (and there is if this is being
937
  // called), start off by setting all the restriction flags.
938
  PRUint32 out = SANDBOXED_NAVIGATION |
939
    SANDBOXED_TOPLEVEL_NAVIGATION |
940
    SANDBOXED_PLUGINS | SANDBOXED_ORIGIN |
941
    SANDBOXED_FORMS | SANDBOXED_SCRIPTS |
942
    SANDBOXED_AUTOMATIC_FEATURES;
943
944
  if (!sandboxAttrValue.IsEmpty()) {
945
    // The separator optional flag is used because the HTML5 spec says any
946
    // whitespace is ok as a separator, which is what this does.
947
    HTMLSplitOnSpacesTokenizer tokenizer(sandboxAttrValue, ' ',
948
      nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>::SEPARATOR_OPTIONAL);
949
950
    while (tokenizer.hasMoreTokens()) {
951
      nsDependentSubstring token = tokenizer.nextToken();
952
953
      if (token.LowerCaseEqualsLiteral("allow-scripts")) {
954
        out &= ~SANDBOXED_SCRIPTS;
955
      } else if (token.LowerCaseEqualsLiteral("allow-same-origin")) {
956
        out &= ~SANDBOXED_ORIGIN;
957
      } else if (token.LowerCaseEqualsLiteral("allow-forms")) {
958
        out &= ~SANDBOXED_FORMS;
959
      } else if (token.LowerCaseEqualsLiteral("allow-scripts")) {
960
        // allow-scripts removes both SANDBOXED_SCRIPTS and
961
        // SANDBOXED_AUTOMATIC_FEATURES.
962
        out &= ~SANDBOXED_SCRIPTS;
963
        out &= ~SANDBOXED_AUTOMATIC_FEATURES;
964
      } else if (token.LowerCaseEqualsLiteral("allow-top-navigation")) {
965
        out &= ~SANDBOXED_TOPLEVEL_NAVIGATION;
966
      }
967
    }
968
  }
969
970
  return out;
971
}
925
972
926
#ifdef MOZ_XTF
973
#ifdef MOZ_XTF
927
nsIXTFService*
974
nsIXTFService*
928
nsContentUtils::GetXTFService()
975
nsContentUtils::GetXTFService()
929
{
976
{
930
  if (!sXTFService) {
977
  if (!sXTFService) {
931
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
978
    nsresult rv = CallGetService(kXTFServiceCID, &sXTFService);
932
    if (NS_FAILED(rv)) {
979
    if (NS_FAILED(rv)) {
 Lines 6383-6399   nsContentUtils::URIInheritsSecurityConte Link Here 
6383
                             aResult);
6430
                             aResult);
6384
}
6431
}
6385
6432
6386
// static
6433
// static
6387
bool
6434
bool
6388
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6435
nsContentUtils::SetUpChannelOwner(nsIPrincipal* aLoadingPrincipal,
6389
                                  nsIChannel* aChannel,
6436
                                  nsIChannel* aChannel,
6390
                                  nsIURI* aURI,
6437
                                  nsIURI* aURI,
6391
                                  bool aSetUpForAboutBlank)
6438
                                  bool aSetUpForAboutBlank,
6439
                                  bool aForceOwner)
6392
{
6440
{
6393
  //
6441
  //
6394
  // Set the owner of the channel, but only for channels that can't
6442
  // Set the owner of the channel, but only for channels that can't
6395
  // provide their own security context.
6443
  // provide their own security context.
6396
  //
6444
  //
6397
  // XXX: It seems wrong that the owner is ignored - even if one is
6445
  // XXX: It seems wrong that the owner is ignored - even if one is
6398
  //      supplied) unless the URI is javascript or data or about:blank.
6446
  //      supplied) unless the URI is javascript or data or about:blank.
6399
  // XXX: If this is ever changed, check all callers for what owners
6447
  // XXX: If this is ever changed, check all callers for what owners
 Lines 6401-6423   nsContentUtils::SetUpChannelOwner(nsIPri Link Here 
6401
  //      comments in nsDocShell::LoadURI where we fall back on
6449
  //      comments in nsDocShell::LoadURI where we fall back on
6402
  //      inheriting the owner if called from chrome.  That would be
6450
  //      inheriting the owner if called from chrome.  That would be
6403
  //      very wrong if this code changed anything but channels that
6451
  //      very wrong if this code changed anything but channels that
6404
  //      can't provide their own security context!
6452
  //      can't provide their own security context!
6405
  //
6453
  //
6406
  //      (Currently chrome URIs set the owner when they are created!
6454
  //      (Currently chrome URIs set the owner when they are created!
6407
  //      So setting a NULL owner would be bad!)
6455
  //      So setting a NULL owner would be bad!)
6408
  //
6456
  //
6457
  // If aForceOwner is true, the owner will be set, even for a channel that
6458
  // can provide its own security context. This is used for the HTML5 IFRAME
6459
  // sandbox attribute, so we can force the channel (and its document) to
6460
  // explicitly have a null principal.
6409
  bool inherit;
6461
  bool inherit;
6410
  // We expect URIInheritsSecurityContext to return success for an
6462
  // We expect URIInheritsSecurityContext to return success for an
6411
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6463
  // about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
6412
  // This condition needs to match the one in nsDocShell::InternalLoad where
6464
  // This condition needs to match the one in nsDocShell::InternalLoad where
6413
  // we're checking for things that will use the owner.
6465
  // we're checking for things that will use the owner.
6414
  if (NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6466
  if (aForceOwner || ((NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherit)) &&
6415
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))) {
6467
      (inherit || (aSetUpForAboutBlank && NS_IsAboutBlank(aURI)))))) {
6416
    aChannel->SetOwner(aLoadingPrincipal);
6468
    aChannel->SetOwner(aLoadingPrincipal);
6417
    return true;
6469
    return true;
6418
  }
6470
  }
6419
6471
6420
  //
6472
  //
6421
  // file: uri special-casing
6473
  // file: uri special-casing
6422
  //
6474
  //
6423
  // If this is a file: load opened from another file: then it may need
6475
  // 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 468-483   nsFrameLoader::ReallyStartLoadingInterna Link Here 
468
  // Just to be safe, recheck uri.
471
  // Just to be safe, recheck uri.
469
  rv = CheckURILoad(mURIToLoad);
472
  rv = CheckURILoad(mURIToLoad);
470
  NS_ENSURE_SUCCESS(rv, rv);
473
  NS_ENSURE_SUCCESS(rv, rv);
471
474
472
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
475
  nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
473
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
476
  mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
474
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
477
  NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
475
478
479
  // Is this an <iframe> with a sandbox attribute or a parent which is
480
  // sandboxed ?
481
  nsHTMLIFrameElement * iframe =
482
    nsHTMLIFrameElement::FromContent(mOwnerContent);
483
484
  PRUint32 sandboxFlags = 0;
485
486
  if (iframe) {
487
    sandboxFlags = iframe->GetSandboxFlags();
488
489
    PRUint32 parentSandboxFlags = 0;
490
491
    // Get the parent's sandbox flags, they're needed to determine if the
492
    // frame being loaded needs to be sandboxed.
493
    nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
494
    nsCOMPtr<nsIDocShellTreeItem> curDocShellItem = do_QueryInterface(mDocShell);
495
496
    if (NS_SUCCEEDED(curDocShellItem->GetParent(getter_AddRefs(parentDocShellItem)))) {
497
      nsCOMPtr<nsIDocument> parentDoc = do_GetInterface(parentDocShellItem);
498
499
      if (parentDoc) {
500
        parentSandboxFlags = parentDoc->SandboxFlags();
501
      }
502
    }
503
504
    if (sandboxFlags || parentSandboxFlags) {
505
      if (parentSandboxFlags) {
506
        // The child can only add restrictions, not remove them.
507
        sandboxFlags |= parentSandboxFlags;
508
      }
509
510
      mDocShell->SetSandboxFlags(sandboxFlags);
511
512
      // Set up the actual sandboxing for plugins as specified.
513
      if (sandboxFlags & SANDBOXED_PLUGINS) {
514
        mDocShell->SetAllowPlugins(false);
515
      }
516
    }
517
  }
518
519
  // If this is an <iframe> and it's sandboxed with respect to origin
520
  // we will set it up with a null principal later in nsDocShell::DoURILoad.
521
  // We do it there to correctly sandbox content that was loaded into
522
  // the iframe via other methods than the src attribute.
476
  // We'll use our principal, not that of the document loaded inside us.  This
523
  // We'll use our principal, not that of the document loaded inside us.  This
477
  // is very important; needed to prevent XSS attacks on documents loaded in
524
  // is very important; needed to prevent XSS attacks on documents loaded in
478
  // subframes!
525
  // subframes!
479
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
526
  loadInfo->SetOwner(mOwnerContent->NodePrincipal());
480
527
481
  nsCOMPtr<nsIURI> referrer;
528
  nsCOMPtr<nsIURI> referrer;
482
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
529
  rv = mOwnerContent->NodePrincipal()->GetURI(getter_AddRefs(referrer));
483
  NS_ENSURE_SUCCESS(rv, rv);
530
  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 674-689   nsScriptLoader::ProcessScriptElement(nsI Link Here 
674
        "There can be only one parser-blocking script at a time");
681
        "There can be only one parser-blocking script at a time");
675
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
682
    NS_ASSERTION(mXSLTRequests.IsEmpty(),
676
        "Parser-blocking scripts and XSLT scripts in the same doc!");
683
        "Parser-blocking scripts and XSLT scripts in the same doc!");
677
    mParserBlockingRequest = request;
684
    mParserBlockingRequest = request;
678
    return true;
685
    return true;
679
  }
686
  }
680
687
681
  // inline script
688
  // inline script
689
  // Is this document sandboxed without 'allow-scripts'?
690
  if (mDocument->SandboxFlags() & SANDBOXED_SCRIPTS) {
691
    return false;
692
  }
693
682
  nsCOMPtr<nsIContentSecurityPolicy> csp;
694
  nsCOMPtr<nsIContentSecurityPolicy> csp;
683
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
695
  rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
684
  NS_ENSURE_SUCCESS(rv, false);
696
  NS_ENSURE_SUCCESS(rv, false);
685
697
686
  if (csp) {
698
  if (csp) {
687
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
699
    PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("New ScriptLoader i ****with CSP****"));
688
    bool inlineOK;
700
    bool inlineOK;
689
    rv = csp->GetAllowsInlineScript(&inlineOK);
701
    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 568-583   nsEventListenerManager::AddScriptEventLi Link Here 
568
    // loaded as data.
569
    // loaded as data.
569
    return NS_OK;
570
    return NS_OK;
570
  }
571
  }
571
572
572
  nsresult rv = NS_OK;
573
  nsresult rv = NS_OK;
573
  // return early preventing the event listener from being added
574
  // return early preventing the event listener from being added
574
  // 'doc' is fetched above
575
  // 'doc' is fetched above
575
  if (doc) {
576
  if (doc) {
577
    // Don't allow adding an event listener if the document is sandboxed
578
    // without 'allow-scripts'.
579
    if (doc->SandboxFlags() & SANDBOXED_SCRIPTS) {
580
      return NS_ERROR_DOM_SECURITY_ERR;
581
    }
582
576
    nsCOMPtr<nsIContentSecurityPolicy> csp;
583
    nsCOMPtr<nsIContentSecurityPolicy> csp;
577
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
584
    rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
578
    NS_ENSURE_SUCCESS(rv, rv);
585
    NS_ENSURE_SUCCESS(rv, rv);
579
586
580
    if (csp) {
587
    if (csp) {
581
      bool inlineOK;
588
      bool inlineOK;
582
      rv = csp->GetAllowsInlineScript(&inlineOK);
589
      rv = csp->GetAllowsInlineScript(&inlineOK);
583
      NS_ENSURE_SUCCESS(rv, rv);
590
      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 684-700   nsHTMLFormElement::DoSubmitOrReset(nsEve Link Here 
684
    return DoReset();
685
    return DoReset();
685
  }
686
  }
686
687
687
  if (NS_FORM_SUBMIT == aMessage) {
688
  if (NS_FORM_SUBMIT == aMessage) {
688
    // Don't submit if we're not in a document.
689
    // Don't submit if we're not in a document.
689
    if (!doc) {
690
    if (!doc) {
690
      return NS_OK;
691
      return NS_OK;
691
    }
692
    }
692
    return DoSubmit(aEvent);
693
    // Don't submit if we're in a sandboxed frame and form submit
694
    // is disabled.
695
    PRUint32 sandboxFlags = doc->SandboxFlags();
696
697
    if (!(sandboxFlags & SANDBOXED_FORMS)) {
698
      return DoSubmit(aEvent);
699
    }
700
701
    return NS_OK;
693
  }
702
  }
694
703
695
  MOZ_ASSERT(false);
704
  MOZ_ASSERT(false);
696
  return NS_OK;
705
  return NS_OK;
697
}
706
}
698
707
699
nsresult
708
nsresult
700
nsHTMLFormElement::DoReset()
709
nsHTMLFormElement::DoReset()
 Lines 1685-1700   nsHTMLFormElement::CheckValidFormSubmiss Link Here 
1685
   * TODO: the check for observer should be removed later when HTML5 Forms will
1694
   * TODO: the check for observer should be removed later when HTML5 Forms will
1686
   * be spread enough and authors will assume forms can't be submitted when
1695
   * be spread enough and authors will assume forms can't be submitted when
1687
   * invalid. See bug 587671.
1696
   * invalid. See bug 587671.
1688
   */
1697
   */
1689
1698
1690
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1699
  NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
1691
               "We shouldn't be there if novalidate is set!");
1700
               "We shouldn't be there if novalidate is set!");
1692
1701
1702
  // Don't do validation for a form submit done by a sandboxed document that
1703
  // doesn't have 'allow-forms', the submit will have been blocked and the
1704
  // HTML5 spec says we shouldn't validate in this case.
1705
  nsIDocument* doc = GetCurrentDoc();
1706
  if (doc) {
1707
    PRUint32 sandboxFlags = doc->SandboxFlags();
1708
1709
    if (sandboxFlags & SANDBOXED_FORMS) {
1710
      return true;
1711
    }
1712
  }
1713
1693
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1714
  // When .submit() is called aEvent = nsnull so we can rely on that to know if
1694
  // we have to check the validity of the form.
1715
  // we have to check the validity of the form.
1695
  nsCOMPtr<nsIObserverService> service =
1716
  nsCOMPtr<nsIObserverService> service =
1696
    mozilla::services::GetObserverService();
1717
    mozilla::services::GetObserverService();
1697
  if (!service) {
1718
  if (!service) {
1698
    NS_WARNING("No observer service available!");
1719
    NS_WARNING("No observer service available!");
1699
    return true;
1720
    return true;
1700
  }
1721
  }
(-)a/content/html/content/src/nsHTMLIFrameElement.cpp (-51 / +31 lines)
Line     Link Here 
 Lines 33-105    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
};
93
94
95
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
46
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(IFrame)
96
47
97
98
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
48
nsHTMLIFrameElement::nsHTMLIFrameElement(already_AddRefed<nsINodeInfo> aNodeInfo,
99
                                         FromParser aFromParser)
49
                                         FromParser aFromParser)
100
  : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
50
  : nsGenericHTMLFrameElement(aNodeInfo, aFromParser)
101
{
51
{
102
}
52
}
103
53
104
nsHTMLIFrameElement::~nsHTMLIFrameElement()
54
nsHTMLIFrameElement::~nsHTMLIFrameElement()
105
{
55
{
 Lines 131-146   NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Link Here 
131
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
81
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
132
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
82
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
133
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
83
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginWidth, marginwidth)
134
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
84
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Name, name)
135
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
85
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Scrolling, scrolling)
136
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
86
NS_IMPL_URI_ATTR(nsHTMLIFrameElement, Src, src)
137
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
87
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
138
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
88
NS_IMPL_BOOL_ATTR(nsHTMLIFrameElement, MozAllowFullScreen, mozallowfullscreen)
89
NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Sandbox, sandbox)
139
90
140
NS_IMETHODIMP
91
NS_IMETHODIMP
141
nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
92
nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
142
{
93
{
143
  return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
94
  return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
144
}
95
}
145
96
146
NS_IMETHODIMP
97
NS_IMETHODIMP
 Lines 268-275   nsHTMLIFrameElement::IsAttributeMapped(c Link Here 
268
219
269
220
270
nsMapRuleToAttributesFunc
221
nsMapRuleToAttributesFunc
271
nsHTMLIFrameElement::GetAttributeMappingFunction() const
222
nsHTMLIFrameElement::GetAttributeMappingFunction() const
272
{
223
{
273
  return &MapAttributesIntoRule;
224
  return &MapAttributesIntoRule;
274
}
225
}
275
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 (+113 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
92
  virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
93
                                  const nsAttrValue* aValue,
94
                                  bool aNotify);
95
96
  PRUint32 GetSandboxFlags() {
97
    nsAutoString sandboxAttr;
98
99
    if (GetAttr(kNameSpaceID_None, nsGkAtoms::sandbox, sandboxAttr)) {
100
      return nsContentUtils::ParseSandboxAttributeToFlags(sandboxAttr);
101
    }
102
103
    // No sandbox attribute, no sandbox flags.
104
    return 0;
105
  }
106
107
  static nsHTMLIFrameElement* FromContent(nsIContent *aContent)
108
  {
109
    if (aContent->IsHTML(nsGkAtoms::iframe))
110
      return static_cast<nsHTMLIFrameElement*>(aContent);
111
    return nsnull;
112
  }
113
};
(-)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 116-124   FORCE_STATIC_LIB = 1 Link Here 
116
116
117
include $(topsrcdir)/config/rules.mk
117
include $(topsrcdir)/config/rules.mk
118
118
119
LOCAL_INCLUDES += \
119
LOCAL_INCLUDES += \
120
  -I$(srcdir)/../shistory/src \
120
  -I$(srcdir)/../shistory/src \
121
  -I$(topsrcdir)/dom/base \
121
  -I$(topsrcdir)/dom/base \
122
  -I$(topsrcdir)/layout/base \
122
  -I$(topsrcdir)/layout/base \
123
  -I$(topsrcdir)/xpcom/ds \
123
  -I$(topsrcdir)/xpcom/ds \
124
  -I$(topsrcdir)/content/base/src \
124
  $(NULL)
125
  $(NULL)
(-)a/docshell/base/nsDocShell.cpp (-2 / +101 lines)
Line     Link Here 
 Lines 214-229    Link Here 
214
#include "nsIWebBrowserPrint.h"
214
#include "nsIWebBrowserPrint.h"
215
#endif
215
#endif
216
216
217
#include "nsPluginError.h"
217
#include "nsPluginError.h"
218
#include "nsContentUtils.h"
218
#include "nsContentUtils.h"
219
#include "nsContentErrors.h"
219
#include "nsContentErrors.h"
220
#include "nsIChannelPolicy.h"
220
#include "nsIChannelPolicy.h"
221
#include "nsIContentSecurityPolicy.h"
221
#include "nsIContentSecurityPolicy.h"
222
#include "nsSandboxFlags.h"
222
223
223
#include "nsXULAppAPI.h"
224
#include "nsXULAppAPI.h"
224
225
225
#include "nsDOMNavigationTiming.h"
226
#include "nsDOMNavigationTiming.h"
226
#include "nsITimedChannel.h"
227
#include "nsITimedChannel.h"
227
#include "mozilla/StartupTimeline.h"
228
#include "mozilla/StartupTimeline.h"
228
229
229
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
230
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
 Lines 744-759   nsDocShell::nsDocShell(): Link Here 
744
    mBusyFlags(BUSY_FLAGS_NONE),
745
    mBusyFlags(BUSY_FLAGS_NONE),
745
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
746
    mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
746
    mLoadType(0),
747
    mLoadType(0),
747
    mMarginWidth(-1),
748
    mMarginWidth(-1),
748
    mMarginHeight(-1),
749
    mMarginHeight(-1),
749
    mItemType(typeContent),
750
    mItemType(typeContent),
750
    mPreviousTransIndex(-1),
751
    mPreviousTransIndex(-1),
751
    mLoadedTransIndex(-1),
752
    mLoadedTransIndex(-1),
753
    mSandboxFlags(0),
752
    mCreated(false),
754
    mCreated(false),
753
    mAllowSubframes(true),
755
    mAllowSubframes(true),
754
    mAllowPlugins(true),
756
    mAllowPlugins(true),
755
    mAllowJavascript(true),
757
    mAllowJavascript(true),
756
    mAllowMetaRedirects(true),
758
    mAllowMetaRedirects(true),
757
    mAllowImages(true),
759
    mAllowImages(true),
758
    mAllowDNSPrefetch(true),
760
    mAllowDNSPrefetch(true),
759
    mAllowWindowControl(true),
761
    mAllowWindowControl(true),
 Lines 2935-2950   nsDocShell::FindItemWithName(const PRUni Link Here 
2935
            foundItem = nsnull;
2937
            foundItem = nsnull;
2936
        }
2938
        }
2937
2939
2938
        if (foundItem) {
2940
        if (foundItem) {
2939
            // We return foundItem here even if it's not an active
2941
            // We return foundItem here even if it's not an active
2940
            // item since all the names we've dealt with so far are
2942
            // item since all the names we've dealt with so far are
2941
            // special cases that we won't bother looking for further.
2943
            // special cases that we won't bother looking for further.
2942
2944
2945
            // If our document is sandboxed, we need to do some extra checks.
2946
            PRUint32 sandboxFlags = 0;
2947
2948
            nsCOMPtr<nsIDocument> doc = do_GetInterface(aOriginalRequestor);
2949
2950
            if (doc) {
2951
              sandboxFlags = doc->SandboxFlags();
2952
            }
2953
2954
            if (sandboxFlags) {
2955
                nsCOMPtr<nsIDocShellTreeItem> root;
2956
                GetSameTypeRootTreeItem(getter_AddRefs(root));
2957
2958
                // Is the found item not a top level browsing context and not ourself ?
2959
                nsCOMPtr<nsIDocShellTreeItem> selfAsItem = static_cast<nsIDocShellTreeItem *>(this);
2960
                if (foundItem != root && foundItem != selfAsItem) {
2961
                    // Are we an ancestor of the foundItem ?
2962
                    bool isAncestor = false;
2963
2964
                    nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
2965
                    GetSameTypeParent(getter_AddRefs(parentAsItem));
2966
2967
                    while (parentAsItem) {
2968
                        nsCOMPtr<nsIDocShellTreeItem> tmp;
2969
                        parentAsItem->GetParent(getter_AddRefs(tmp));
2970
2971
                        if (tmp && tmp == selfAsItem) {
2972
                            isAncestor = true;
2973
                            break;
2974
                        }
2975
                        parentAsItem = tmp;
2976
                    }
2977
2978
                    if (!isAncestor) {
2979
                        // No, we are not an ancestor and our document is
2980
                        // sandboxed, we can't allow this.
2981
                        foundItem = nsnull;
2982
                    }
2983
                } else {
2984
                    // Top level browsing context - is it an ancestor of ours ?
2985
                    nsCOMPtr<nsIDocShellTreeItem> tmp;
2986
                    GetSameTypeParent(getter_AddRefs(tmp));
2987
2988
                    while (tmp) {
2989
                        if (tmp && tmp == foundItem) {
2990
                            // This is an ancestor, and we are sandboxed.
2991
                            // Unless allow-top-navigation is set, we can't allow this.
2992
                            if (sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) {
2993
                              foundItem = nsnull;
2994
                            }
2995
                            break;
2996
                        }
2997
                        tmp->GetParent(getter_AddRefs(tmp));
2998
                    }
2999
                }
3000
            }
3001
2943
            foundItem.swap(*_retval);
3002
            foundItem.swap(*_retval);
2944
            return NS_OK;
3003
            return NS_OK;
2945
        }
3004
        }
2946
    }
3005
    }
2947
3006
2948
    // Keep looking
3007
    // Keep looking
2949
        
3008
        
2950
    // First we check our name.
3009
    // First we check our name.
 Lines 4971-4986   nsDocShell::SetIsAppTab(bool aIsAppTab) Link Here 
4971
NS_IMETHODIMP
5030
NS_IMETHODIMP
4972
nsDocShell::GetIsAppTab(bool *aIsAppTab)
5031
nsDocShell::GetIsAppTab(bool *aIsAppTab)
4973
{
5032
{
4974
  *aIsAppTab = mIsAppTab;
5033
  *aIsAppTab = mIsAppTab;
4975
  return NS_OK;
5034
  return NS_OK;
4976
}
5035
}
4977
5036
4978
NS_IMETHODIMP
5037
NS_IMETHODIMP
5038
nsDocShell::SetSandboxFlags(PRUint32 aSandboxFlags)
5039
{
5040
  mSandboxFlags = aSandboxFlags;
5041
  return NS_OK;
5042
}
5043
5044
NS_IMETHODIMP
5045
nsDocShell::GetSandboxFlags(PRUint32  *aSandboxFlags)
5046
{
5047
  *aSandboxFlags = mSandboxFlags;
5048
  return NS_OK;
5049
}
5050
5051
NS_IMETHODIMP
4979
nsDocShell::SetVisibility(bool aVisibility)
5052
nsDocShell::SetVisibility(bool aVisibility)
4980
{
5053
{
4981
    if (!mContentViewer)
5054
    if (!mContentViewer)
4982
        return NS_OK;
5055
        return NS_OK;
4983
    if (aVisibility) {
5056
    if (aVisibility) {
4984
        mContentViewer->Show();
5057
        mContentViewer->Show();
4985
    }
5058
    }
4986
    else {
5059
    else {
 Lines 8172-8187   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
8172
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8245
        nsCOMPtr<nsIDocShellTreeItem> targetItem;
8173
        FindItemWithName(aWindowTarget, nsnull, this,
8246
        FindItemWithName(aWindowTarget, nsnull, this,
8174
                         getter_AddRefs(targetItem));
8247
                         getter_AddRefs(targetItem));
8175
8248
8176
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8249
        nsCOMPtr<nsIDocShell> targetDocShell = do_QueryInterface(targetItem);
8177
        
8250
        
8178
        bool isNewWindow = false;
8251
        bool isNewWindow = false;
8179
        if (!targetDocShell) {
8252
        if (!targetDocShell) {
8253
            // If the docshell's document is sandboxed and was trying to
8254
            // navigate/load a frame it wasn't allowed to access, the
8255
            // FindItemWithName above will have returned null for the target
8256
            // item - we don't want to actually open a new window in this case
8257
            // though. Check if we are sandboxed and bail out here if so.
8258
            NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
8259
            nsIDocument* doc = mContentViewer->GetDocument();
8260
            PRUint32 sandboxFlags = 0;
8261
            sandboxFlags = doc->SandboxFlags();
8262
            if (sandboxFlags & SANDBOXED_NAVIGATION) {
8263
              return NS_ERROR_FAILURE;
8264
            }
8265
8180
            nsCOMPtr<nsIDOMWindow> win =
8266
            nsCOMPtr<nsIDOMWindow> win =
8181
                do_GetInterface(GetAsSupports(this));
8267
                do_GetInterface(GetAsSupports(this));
8182
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8268
            NS_ENSURE_TRUE(win, NS_ERROR_NOT_AVAILABLE);
8183
8269
8184
            nsDependentString name(aWindowTarget);
8270
            nsDependentString name(aWindowTarget);
8185
            nsCOMPtr<nsIDOMWindow> newWin;
8271
            nsCOMPtr<nsIDOMWindow> newWin;
8186
            rv = win->Open(EmptyString(), // URL to load
8272
            rv = win->Open(EmptyString(), // URL to load
8187
                           name,          // window name
8273
                           name,          // window name
 Lines 8959-8976   nsDocShell::DoURILoad(nsIURI * aURI, Link Here 
8959
        }
9045
        }
8960
        // Set the referrer explicitly
9046
        // Set the referrer explicitly
8961
        if (aReferrerURI && aSendReferrer) {
9047
        if (aReferrerURI && aSendReferrer) {
8962
            // Referrer is currenly only set for link clicks here.
9048
            // Referrer is currenly only set for link clicks here.
8963
            httpChannel->SetReferrer(aReferrerURI);
9049
            httpChannel->SetReferrer(aReferrerURI);
8964
        }
9050
        }
8965
    }
9051
    }
8966
9052
8967
    nsCOMPtr<nsIPrincipal> ownerPrincipal(do_QueryInterface(aOwner));
9053
    nsCOMPtr<nsIPrincipal> ownerPrincipal;
8968
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true);
9054
9055
    // If the content being loaded should be sandboxed with respect to origin
9056
    // we need to create a new null principal here, and then tell
9057
    // nsContentUtils::SetUpChannelOwner to force it to be set as the
9058
    // channel owner.
9059
    if (mSandboxFlags & SANDBOXED_ORIGIN) {
9060
      ownerPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
9061
    } else {
9062
      // Not sandboxed - we allow the content to assume its natural owner.
9063
      ownerPrincipal = do_QueryInterface(aOwner);
9064
    }
9065
9066
    nsContentUtils::SetUpChannelOwner(ownerPrincipal, channel, aURI, true,
9067
                                       (mSandboxFlags & SANDBOXED_ORIGIN));
8969
9068
8970
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
9069
    nsCOMPtr<nsIScriptChannel> scriptChannel = do_QueryInterface(channel);
8971
    if (scriptChannel) {
9070
    if (scriptChannel) {
8972
        // Allow execution against our context if the principals match
9071
        // Allow execution against our context if the principals match
8973
        scriptChannel->
9072
        scriptChannel->
8974
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
9073
            SetExecutionPolicy(nsIScriptChannel::EXECUTE_NORMAL);
8975
    }
9074
    }
8976
9075
(-)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 67-83   interface nsIRequest; Link Here 
67
interface nsISHEntry;
67
interface nsISHEntry;
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
74
75
[scriptable, uuid(c7325422-817e-4321-957a-c0bdd764941d)]
75
[scriptable, uuid(9b283337-097d-4fa8-a2da-916318eaf828)]
76
interface nsIDocShell : nsISupports
76
interface nsIDocShell : nsISupports
77
{
77
{
78
  /**
78
  /**
79
   * Loads a given URI.  This will give priority to loading the requested URI
79
   * Loads a given URI.  This will give priority to loading the requested URI
80
   * in the object implementing	this interface.  If it can't be loaded here
80
   * in the object implementing	this interface.  If it can't be loaded here
81
   * however, the URL dispatcher will go through its normal process of content
81
   * however, the URL dispatcher will go through its normal process of content
82
   * loading.
82
   * loading.
83
   *
83
   *
 Lines 615-623   interface nsIDocShell : nsISupports Link Here 
615
   */
615
   */
616
  attribute bool isBrowserFrame;
616
  attribute bool isBrowserFrame;
617
617
618
  /*
618
  /*
619
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
619
   * Is this docshell contained in an <iframe mozbrowser>, either directly or
620
   * indirectly?
620
   * indirectly?
621
   */
621
   */
622
  readonly attribute bool containedInBrowserFrame;
622
  readonly attribute bool containedInBrowserFrame;
623
624
  /**
625
   * The sandbox flags on the docshell. These reflect the value of the sandbox
626
   * attribute of the associated IFRAME or CSP-protectable content, if
627
   * existent. See the HTML5 spec for more details.
628
   * These flags on the docshell reflect the current state of the sandbox
629
   * attribute, which is modifiable. They are only used when loading new
630
   * content, sandbox flags are also immutably set on the document when it is
631
   * loaded.
632
   * The sandbox flags of a document depend on the sandbox flags on its
633
   * docshell and of its parent document, if any.
634
   * See nsSandboxFlags.h for the possible flags.
635
   */
636
  attribute unsigned long sandboxFlags;
623
};
637
};
(-)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 8231-8246   nsGlobalWindow::GetSessionStorage(nsIDOM Link Here 
8231
  if (!mSessionStorage) {
8232
  if (!mSessionStorage) {
8232
    *aSessionStorage = nsnull;
8233
    *aSessionStorage = nsnull;
8233
8234
8234
    nsString documentURI;
8235
    nsString documentURI;
8235
    if (mDocument) {
8236
    if (mDocument) {
8236
      mDocument->GetDocumentURI(documentURI);
8237
      mDocument->GetDocumentURI(documentURI);
8237
    }
8238
    }
8238
8239
8240
    // If the document has the sandboxed origin flag set
8241
    // don't allow access to localStorage.
8242
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
8243
      return NS_ERROR_DOM_SECURITY_ERR;
8244
    }
8245
8239
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
8246
    nsresult rv = docShell->GetSessionStorageForPrincipal(principal,
8240
                                                          documentURI,
8247
                                                          documentURI,
8241
                                                          true,
8248
                                                          true,
8242
                                                          getter_AddRefs(mSessionStorage));
8249
                                                          getter_AddRefs(mSessionStorage));
8243
    NS_ENSURE_SUCCESS(rv, rv);
8250
    NS_ENSURE_SUCCESS(rv, rv);
8244
8251
8245
#ifdef PR_LOGGING
8252
#ifdef PR_LOGGING
8246
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
8253
    if (PR_LOG_TEST(gDOMLeakPRLog, PR_LOG_DEBUG)) {
 Lines 8292-8307   nsGlobalWindow::GetLocalStorage(nsIDOMSt Link Here 
8292
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8299
      do_GetService("@mozilla.org/dom/storagemanager;1", &rv);
8293
    NS_ENSURE_SUCCESS(rv, rv);
8300
    NS_ENSURE_SUCCESS(rv, rv);
8294
8301
8295
    nsString documentURI;
8302
    nsString documentURI;
8296
    if (mDocument) {
8303
    if (mDocument) {
8297
      mDocument->GetDocumentURI(documentURI);
8304
      mDocument->GetDocumentURI(documentURI);
8298
    }
8305
    }
8299
8306
8307
    // If the document has the sandboxed origin flag set
8308
    // don't allow access to localStorage.
8309
    if (mDoc && (mDoc->SandboxFlags() & SANDBOXED_ORIGIN)) {
8310
      return NS_ERROR_DOM_SECURITY_ERR;
8311
    }
8312
8300
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8313
    rv = storageManager->GetLocalStorageForPrincipal(principal,
8301
                                                     documentURI,
8314
                                                     documentURI,
8302
                                                     getter_AddRefs(mLocalStorage));
8315
                                                     getter_AddRefs(mLocalStorage));
8303
    NS_ENSURE_SUCCESS(rv, rv);
8316
    NS_ENSURE_SUCCESS(rv, rv);
8304
  }
8317
  }
8305
8318
8306
  NS_ADDREF(*aLocalStorage = mLocalStorage);
8319
  NS_ADDREF(*aLocalStorage = mLocalStorage);
8307
  return NS_OK;
8320
  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