Changeset 99138 in webkit


Ignore:
Timestamp:
Nov 2, 2011 9:39:32 PM (12 years ago)
Author:
abarth@webkit.org
Message:

Implement allow-popups for iframe@sandbox
https://bugs.webkit.org/show_bug.cgi?id=66505

Reviewed by Eric Seidel.

Source/WebCore:

There's been some discussion in the HTML working group about adding an
allow-popups directive to the iframe sandbox. Microsoft has added it
to IE10 platform preview and is fairly adamant about this feature
because it's needed by one or their products that's planning to use
iframe sandbox. Hixie says he'll add it to the spec once we implement
it, so here's our implementation. (See discussion in the W3C linked in
the bug for more details.)

Tests: http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control.html

http/tests/security/popup-allowed-by-sandbox-is-sandboxed.html
http/tests/security/popup-allowed-by-sandbox-when-allowed.html

  • html/HTMLIFrameElement.cpp:

(WebCore::HTMLIFrameElement::parseMappedAttribute):

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::setOpener):
(WebCore::createWindow):

  • loader/FrameLoader.h:

(WebCore::FrameLoader::forceSandboxFlags):

  • loader/FrameLoaderTypes.h:
  • loader/PolicyChecker.cpp:

(WebCore::PolicyChecker::checkNewWindowPolicy):

  • page/SecurityOrigin.cpp:

(WebCore::SecurityOrigin::parseSandboxPolicy):

  • page/SecurityOrigin.h:

(WebCore::SecurityOrigin::sandboxFlags):

  • svg/graphics/SVGImage.cpp:

(WebCore::SVGImage::dataChanged):

LayoutTests:

Test that the allow-popups directive works as expected. Note:
no-popup-from-sandbox.html verifies that we still block popups without
the directive.

  • http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control-expected.txt: Added.
  • http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control.html: Added.
  • http/tests/security/popup-allowed-by-sandbox-is-sandboxed-expected.txt: Added.
  • http/tests/security/popup-allowed-by-sandbox-is-sandboxed.html: Added.
  • http/tests/security/popup-allowed-by-sandbox-when-allowed-expected.txt: Added.
  • http/tests/security/popup-allowed-by-sandbox-when-allowed.html: Added.
Location:
trunk
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r99136 r99138  
     12011-11-02  Adam Barth  <abarth@webkit.org>
     2
     3        Implement allow-popups for iframe@sandbox
     4        https://bugs.webkit.org/show_bug.cgi?id=66505
     5
     6        Reviewed by Eric Seidel.
     7
     8        Test that the allow-popups directive works as expected.  Note:
     9        no-popup-from-sandbox.html verifies that we still block popups without
     10        the directive.
     11
     12        * http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control-expected.txt: Added.
     13        * http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control.html: Added.
     14        * http/tests/security/popup-allowed-by-sandbox-is-sandboxed-expected.txt: Added.
     15        * http/tests/security/popup-allowed-by-sandbox-is-sandboxed.html: Added.
     16        * http/tests/security/popup-allowed-by-sandbox-when-allowed-expected.txt: Added.
     17        * http/tests/security/popup-allowed-by-sandbox-when-allowed.html: Added.
     18
    1192011-11-02  Sam Weinig  <sam@webkit.org>
    220
  • trunk/Source/WebCore/ChangeLog

    r99137 r99138  
     12011-11-02  Adam Barth  <abarth@webkit.org>
     2
     3        Implement allow-popups for iframe@sandbox
     4        https://bugs.webkit.org/show_bug.cgi?id=66505
     5
     6        Reviewed by Eric Seidel.
     7
     8        There's been some discussion in the HTML working group about adding an
     9        allow-popups directive to the iframe sandbox.  Microsoft has added it
     10        to IE10 platform preview and is fairly adamant about this feature
     11        because it's needed by one or their products that's planning to use
     12        iframe sandbox.  Hixie says he'll add it to the spec once we implement
     13        it, so here's our implementation.  (See discussion in the W3C linked in
     14        the bug for more details.)
     15
     16        Tests: http/tests/security/popup-allowed-by-sandbox-is-sandboxed-control.html
     17               http/tests/security/popup-allowed-by-sandbox-is-sandboxed.html
     18               http/tests/security/popup-allowed-by-sandbox-when-allowed.html
     19
     20        * html/HTMLIFrameElement.cpp:
     21        (WebCore::HTMLIFrameElement::parseMappedAttribute):
     22        * loader/FrameLoader.cpp:
     23        (WebCore::FrameLoader::setOpener):
     24        (WebCore::createWindow):
     25        * loader/FrameLoader.h:
     26        (WebCore::FrameLoader::forceSandboxFlags):
     27        * loader/FrameLoaderTypes.h:
     28        * loader/PolicyChecker.cpp:
     29        (WebCore::PolicyChecker::checkNewWindowPolicy):
     30        * page/SecurityOrigin.cpp:
     31        (WebCore::SecurityOrigin::parseSandboxPolicy):
     32        * page/SecurityOrigin.h:
     33        (WebCore::SecurityOrigin::sandboxFlags):
     34        * svg/graphics/SVGImage.cpp:
     35        (WebCore::SVGImage::dataChanged):
     36
    1372011-11-02  Sam Weinig  <sam@webkit.org>
    238
  • trunk/Source/WebCore/html/HTMLIFrameElement.cpp

    r98300 r99138  
    3333#include "NodeRenderingContext.h"
    3434#include "RenderIFrame.h"
     35#include "SecurityOrigin.h"
    3536
    3637namespace WebCore {
     
    6970}
    7071
    71 static SandboxFlags parseSandboxAttribute(Attribute* attribute)
    72 {
    73     if (attribute->isNull())
    74         return SandboxNone;
    75 
    76     // Parse the unordered set of unique space-separated tokens.
    77     SandboxFlags flags = SandboxAll;
    78     const UChar* characters = attribute->value().characters();
    79     unsigned length = attribute->value().length();
    80     unsigned start = 0;
    81     while (true) {
    82         while (start < length && isASCIISpace(characters[start]))
    83             ++start;
    84         if (start >= length)
    85             break;
    86         unsigned end = start + 1;
    87         while (end < length && !isASCIISpace(characters[end]))
    88             ++end;
    89 
    90         // Turn off the corresponding sandbox flag if it's set as "allowed".
    91         String sandboxToken = String(characters + start, end - start);
    92         if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
    93             flags &= ~SandboxOrigin;
    94         else if (equalIgnoringCase(sandboxToken, "allow-forms"))
    95             flags &= ~SandboxForms;
    96         else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
    97             flags &= ~SandboxScripts;
    98         else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
    99             flags &= ~SandboxTopNavigation;
    100 
    101         start = end + 1;
    102     }
    103 
    104     return flags;
    105 }
    106 
    10772void HTMLIFrameElement::parseMappedAttribute(Attribute* attr)
    10873{
     
    12893            addCSSLength(attr, CSSPropertyBorderWidth, "0");
    12994    } else if (attr->name() == sandboxAttr)
    130         setSandboxFlags(parseSandboxAttribute(attr));
     95        setSandboxFlags(attr->isNull() ? SandboxNone : SecurityOrigin::parseSandboxPolicy(attr->value()));
    13196    else
    13297        HTMLFrameElementBase::parseMappedAttribute(attr);
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r97716 r99138  
    946946    if (opener)
    947947        opener->loader()->m_openedFrames.add(m_frame);
     948
    948949    m_opener = opener;
     950
     951    if (m_opener && !m_frame->tree()->parent())
     952        forceSandboxFlags(m_opener->document()->securityOrigin()->sandboxFlags());
    949953
    950954    if (m_frame->document()) {
     
    32693273
    32703274    // Sandboxed frames cannot open new auxiliary browsing contexts.
    3271     if (isDocumentSandboxed(openerFrame, SandboxNavigation))
     3275    if (isDocumentSandboxed(openerFrame, SandboxPopups))
    32723276        return 0;
    32733277
  • trunk/Source/WebCore/loader/FrameLoader.h

    r95593 r99138  
    216216    // The following sandbox flags will be forced, regardless of changes to
    217217    // the sandbox attribute of any parent frames.
    218     void setForcedSandboxFlags(SandboxFlags flags) { m_forcedSandboxFlags = flags; m_sandboxFlags |= flags; }
     218    void forceSandboxFlags(SandboxFlags flags) { m_forcedSandboxFlags |= flags; m_sandboxFlags |= flags; }
    219219
    220220    // Mixed content related functions.
  • trunk/Source/WebCore/loader/FrameLoaderTypes.h

    r96060 r99138  
    101101        SandboxScripts = 1 << 4,
    102102        SandboxTopNavigation = 1 << 5,
     103        SandboxPopups = 1 << 6,
    103104        SandboxAll = -1 // Mask with all bits set to 1.
    104105    };
  • trunk/Source/WebCore/loader/PolicyChecker.cpp

    r97716 r99138  
    9494    const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, void* argument)
    9595{
    96     if (m_frame->document() && m_frame->document()->securityOrigin()->isSandboxed(SandboxNavigation))
     96    if (m_frame->document() && m_frame->document()->securityOrigin()->isSandboxed(SandboxPopups))
    9797        return continueAfterNavigationPolicy(PolicyIgnore);
    9898
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r98316 r99138  
    544544}
    545545
     546SandboxFlags SecurityOrigin::parseSandboxPolicy(const String& policy)
     547{
     548    // Parse the unordered set of unique space-separated tokens.
     549    SandboxFlags flags = SandboxAll;
     550    const UChar* characters = policy.characters();
     551    unsigned length = policy.length();
     552    unsigned start = 0;
     553    while (true) {
     554        while (start < length && isASCIISpace(characters[start]))
     555            ++start;
     556        if (start >= length)
     557            break;
     558        unsigned end = start + 1;
     559        while (end < length && !isASCIISpace(characters[end]))
     560            ++end;
     561
     562        // Turn off the corresponding sandbox flag if it's set as "allowed".
     563        String sandboxToken = String(characters + start, end - start);
     564        if (equalIgnoringCase(sandboxToken, "allow-same-origin"))
     565            flags &= ~SandboxOrigin;
     566        else if (equalIgnoringCase(sandboxToken, "allow-forms"))
     567            flags &= ~SandboxForms;
     568        else if (equalIgnoringCase(sandboxToken, "allow-scripts"))
     569            flags &= ~SandboxScripts;
     570        else if (equalIgnoringCase(sandboxToken, "allow-top-navigation"))
     571            flags &= ~SandboxTopNavigation;
     572        else if (equalIgnoringCase(sandboxToken, "allow-popups"))
     573            flags &= ~SandboxPopups;
     574
     575        start = end + 1;
     576    }
     577
     578    return flags;
     579}
     580
    546581void SecurityOrigin::setLocalLoadPolicy(LocalLoadPolicy policy)
    547582{
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r98316 r99138  
    5757    bool domainWasSetInDOM() const { return m_domainWasSetInDOM; }
    5858
     59    // FIXME: This should move to SchemeRegistry.
    5960    static void setDomainRelaxationForbiddenForURLScheme(bool forbidden, const String&);
    6061    static bool isDomainRelaxationForbiddenForURLScheme(const String&);
     
    115116
    116117    bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; }
     118    SandboxFlags sandboxFlags() const { return m_sandboxFlags; }
    117119
    118120    bool canAccessDatabase() const { return !isUnique(); }
     
    178180    // (and whether it was set) but considering the host. It is used for postMessage.
    179181    bool isSameSchemeHostPort(const SecurityOrigin*) const;
     182
     183    static SandboxFlags parseSandboxPolicy(const String& policy);
    180184
    181185    static bool shouldHideReferrer(const KURL&, const String& referrer);
  • trunk/Source/WebCore/svg/graphics/SVGImage.cpp

    r98852 r99138  
    314314        frame->init();
    315315        FrameLoader* loader = frame->loader();
    316         loader->setForcedSandboxFlags(SandboxAll);
     316        loader->forceSandboxFlags(SandboxAll);
    317317
    318318        frame->view()->setCanHaveScrollbars(false); // SVG Images will always synthesize a viewBox, if it's not available, and thus never see scrollbars.
Note: See TracChangeset for help on using the changeset viewer.