Changeset 34753 in webkit


Ignore:
Timestamp:
Jun 23, 2008 8:00:21 PM (16 years ago)
Author:
abarth@webkit.org
Message:

2008-06-23 Adam Barth <abarth@webkit.org>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=16756

Move isAllowedToLoadLocalResources into SecurityOrigin.

  • dom/Document.cpp: (WebCore::Document::Document): (WebCore::Document::setURL): (WebCore::Document::initSecurityContext):
  • dom/Document.h:
  • loader/FrameLoader.cpp: (WebCore::FrameLoader::canLoad):
  • platform/SecurityOrigin.cpp: (WebCore::SecurityOrigin::SecurityOrigin): (WebCore::SecurityOrigin::isLocal):
  • platform/SecurityOrigin.h: (WebCore::SecurityOrigin::protocol): (WebCore::SecurityOrigin::host): (WebCore::SecurityOrigin::domain): (WebCore::SecurityOrigin::port): (WebCore::SecurityOrigin::canLoadLocalResources): (WebCore::SecurityOrigin::grantLoadLocalResources):
  • xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::setRequestHeader):
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r34752 r34753  
     12008-06-23  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=16756
     6
     7        Move isAllowedToLoadLocalResources into SecurityOrigin.
     8
     9        * dom/Document.cpp:
     10        (WebCore::Document::Document):
     11        (WebCore::Document::setURL):
     12        (WebCore::Document::initSecurityContext):
     13        * dom/Document.h:
     14        * loader/FrameLoader.cpp:
     15        (WebCore::FrameLoader::canLoad):
     16        * platform/SecurityOrigin.cpp:
     17        (WebCore::SecurityOrigin::SecurityOrigin):
     18        (WebCore::SecurityOrigin::isLocal):
     19        * platform/SecurityOrigin.h:
     20        (WebCore::SecurityOrigin::protocol):
     21        (WebCore::SecurityOrigin::host):
     22        (WebCore::SecurityOrigin::domain):
     23        (WebCore::SecurityOrigin::port):
     24        (WebCore::SecurityOrigin::canLoadLocalResources):
     25        (WebCore::SecurityOrigin::grantLoadLocalResources):
     26        * xml/XMLHttpRequest.cpp:
     27        (WebCore::XMLHttpRequest::setRequestHeader):
     28
    1292008-06-23  Mark Rowe  <mrowe@apple.com>
    230
  • trunk/WebCore/dom/Document.cpp

    r34739 r34753  
    288288    , m_createRenderers(true)
    289289    , m_inPageCache(false)
    290     , m_isAllowedToLoadLocalResources(false)
    291290    , m_useSecureKeyboardEntryWhenActive(false)
    292291    , m_isXHTML(isXHTML)
     
    17061705    m_url = newURL;
    17071706    m_documentURI = m_url.string();
    1708     m_isAllowedToLoadLocalResources = shouldBeAllowedToLoadLocalResources();
    17091707    updateBaseURL();
    1710 }
    1711  
    1712 bool Document::shouldBeAllowedToLoadLocalResources() const
    1713 {
    1714     if (FrameLoader::shouldTreatURLAsLocal(m_url.string()))
    1715         return true;
    1716 
    1717     Frame* frame = this->frame();
    1718     if (!frame)
    1719         return false;
    1720    
    1721     DocumentLoader* documentLoader = frame->loader()->documentLoader();
    1722     if (!documentLoader)
    1723         return false;
    1724 
    1725     if (m_url == blankURL() && frame->loader()->opener() && frame->loader()->opener()->document()->isAllowedToLoadLocalResources())
    1726         return true;
    1727    
    1728     return documentLoader->substituteData().isValid();
    17291708}
    17301709
     
    39463925    m_securityOrigin = SecurityOrigin::create(url);
    39473926
     3927    // If this document was loaded with substituteData, then the document can
     3928    // load local resources.  See https://bugs.webkit.org/show_bug.cgi?id=16756
     3929    // for further discussion.
     3930    DocumentLoader* documentLoader = m_frame->loader()->documentLoader();
     3931    if (documentLoader && documentLoader->substituteData().isValid())
     3932        m_securityOrigin->grantLoadLocalResources();
     3933
    39483934    if (!m_securityOrigin->isEmpty())
    39493935        return;
  • trunk/WebCore/dom/Document.h

    r34637 r34753  
    730730    void setIconURL(const String& iconURL, const String& type);
    731731
    732     bool isAllowedToLoadLocalResources() const { return m_isAllowedToLoadLocalResources; }
    733 
    734732    void setUseSecureKeyboardEntryWhenActive(bool);
    735733    bool useSecureKeyboardEntryWhenActive() const;
     
    965963
    966964private:
    967     bool shouldBeAllowedToLoadLocalResources() const;
    968 
    969965    void updateTitle();
    970966    void removeAllDisconnectedNodeEventListeners();
     
    10211017    HashSet<Element*> m_pageCacheCallbackElements;
    10221018
    1023     bool m_isAllowedToLoadLocalResources;
    1024 
    10251019    bool m_useSecureKeyboardEntryWhenActive;
    10261020
  • trunk/WebCore/loader/FrameLoader.cpp

    r34733 r34753  
    22632263        return true;
    22642264
    2265     return doc && doc->isAllowedToLoadLocalResources();
     2265    return doc && doc->securityOrigin()->canLoadLocalResources();
    22662266}
    22672267
     
    22712271        return true;
    22722272
    2273     return doc && doc->isAllowedToLoadLocalResources();
     2273    return doc && doc->securityOrigin()->canLoadLocalResources();
    22742274}
    22752275
  • trunk/WebCore/platform/SecurityOrigin.cpp

    r34532 r34753  
    7070    m_domain = m_host;
    7171
     72    // By default, only local SecurityOrigins can load local resources.
     73    m_canLoadLocalResources = isLocal();
     74
    7275    if (isDefaultPortForProtocol(m_port, m_protocol))
    7376        m_port = 0;
     
    8184    , m_noAccess(other->m_noAccess)
    8285    , m_domainWasSetInDOM(other->m_domainWasSetInDOM)
     86    , m_canLoadLocalResources(other->m_canLoadLocalResources)
    8387{
    8488}
     
    112116bool SecurityOrigin::canAccess(const SecurityOrigin* other) const
    113117
    114     if (FrameLoader::shouldTreatSchemeAsLocal(m_protocol))
     118    if (isLocal())
    115119        return true;
    116120
     
    153157bool SecurityOrigin::canRequest(const KURL& url) const
    154158{
    155     if (FrameLoader::shouldTreatSchemeAsLocal(m_protocol))
     159    if (isLocal())
    156160        return true;
    157161
     
    164168    // to ignore document.domain effects.
    165169    return isSameSchemeHostPort(targetOrigin.get());
     170}
     171
     172bool SecurityOrigin::isLocal() const
     173{
     174    return FrameLoader::shouldTreatSchemeAsLocal(m_protocol);
    166175}
    167176
  • trunk/WebCore/platform/SecurityOrigin.h

    r34532 r34753  
    4747        static PassRefPtr<SecurityOrigin> createEmpty();
    4848
     49        // Create a deep copy of this SecurityOrigin.  This method is useful
     50        // when marshalling a SecurityOrigin to another thread.
    4951        PassRefPtr<SecurityOrigin> copy();
    5052
     53        // Set the domain property of this security origin to newDomain.  This
     54        // function does not check whether newDomain is a suffix of the current
     55        // domain.  The caller is responsible for validating newDomain.
    5156        void setDomainFromDOM(const String& newDomain);
     57
    5258        String protocol() const { return m_protocol; }
    5359        String host() const { return m_host; }
     
    5662
    5763        // Returns true if this SecurityOrigin can script objects in the given
    58         // SecurityOrigin.
     64        // SecurityOrigin.  For example, call this function before allowing
     65        // script from one security origin to read or write objects from
     66        // another SecurityOrigin.
    5967        bool canAccess(const SecurityOrigin*) const;
    6068
    6169        // Returns true if this SecurityOrigin can read content retrieved from
    62         // the given URL. For example, call this function before issuing
     70        // the given URL.  For example, call this function before issuing
    6371        // XMLHttpRequests.
    6472        bool canRequest(const KURL&) const;
    6573
     74        // Returns true if this SecurityOrigin can load local resources, such
     75        // as images, iframes, and style sheets, and can link to local URLs.
     76        // For example, call this function before creating an iframe to a
     77        // file:// URL.
     78        //
     79        // Note: A SecurityOrigin might be allowed to load local resources
     80        //       without being able to issue an XMLHttpRequest for a local URL.
     81        //       To determine whether the SecurityOrigin can issue an
     82        //       XMLHttpRequest for a URL, call canRequest(url).
     83        bool canLoadLocalResources() const { return m_canLoadLocalResources; }
     84
     85        // Explicitly grant the ability to load local resources to this
     86        // SecurityOrigin.
     87        void grantLoadLocalResources() { m_canLoadLocalResources = true; }
     88
    6689        bool isSecureTransitionTo(const KURL&) const;
    6790
     91        // The local SecurityOrigin is the most privileged SecurityOrigin.
     92        // The local SecurityOrigin can script any document, navigate to local
     93        // resources, and can set arbitrary headers on XMLHttpRequests.
     94        bool isLocal() const;
     95
     96        // The empty SecurityOrigin is the least privileged SecurityOrigin.
    6897        bool isEmpty() const;
     98
     99        // Convert this SecurityOrigin into a string.  The string
     100        // representation of a SecurityOrigin is similar to a URL, except it
     101        // lacks a path component.  The string representation does not encode
     102        // the value of the SecurityOrigin's domain property.  The empty
     103        // SecurityOrigin is represented with the null string.
    69104        String toString() const;
    70105
     
    95130        bool m_noAccess;
    96131        bool m_domainWasSetInDOM;
     132        bool m_canLoadLocalResources;
    97133    };
    98134
  • trunk/WebCore/xml/XMLHttpRequest.cpp

    r34742 r34753  
    703703       
    704704    // A privileged script (e.g. a Dashboard widget) can set any headers.
    705     if (!m_doc->isAllowedToLoadLocalResources() && !isSafeRequestHeader(name)) {
     705    if (!m_doc->securityOrigin()->canLoadLocalResources() && !isSafeRequestHeader(name)) {
    706706        if (m_doc && m_doc->frame())
    707707            m_doc->frame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Refused to set unsafe header " + name, 1, String());
Note: See TracChangeset for help on using the changeset viewer.