Changeset 145348 in webkit


Ignore:
Timestamp:
Mar 11, 2013 2:48:14 AM (11 years ago)
Author:
mkwst@chromium.org
Message:

XSSAuditor doesn't need a copy of the original document's body.
https://bugs.webkit.org/show_bug.cgi?id=111946

Reviewed by Darin Adler.

The XSSAuditor currently copies the original HTTP body of the document
that's being audited in order to include it into a violation report if
reflected XSS is detected. We don't actually need to do this, as we
have access to the original request information from inside the
XSSAuditorDelegate where the report is generated.
XSSAuditorDelegate::didBlockScript ASSERTs that it's running on the
main thread, so it should be safe to reach through the document's
loader to get that information directly, rather than passing it from
thread to thread via XSSInfo object properties.

  • html/parser/XSSAuditor.h:
  • html/parser/XSSAuditor.cpp:

(WebCore::XSSAuditor::init):
(WebCore::XSSAuditor::filterToken):
(WebCore::XSSAuditor::isSafeToSendToAnotherThread):

  • html/parser/XSSAuditorDelegate.h:

(WebCore::XSSInfo::create):
(WebCore::XSSInfo::XSSInfo):

  • html/parser/XSSAuditorDelegate.cpp:

(WebCore::XSSInfo::isSafeToSendToAnotherThread):

Drop the XSSInfo and XSSAuditor properties that held an
isolatedCopy of the the original HTTP body. Depending on the
document's size, this could be a significant savings.

(WebCore::XSSAuditorDelegate::didBlockScript):

Reach into the document's loader's original request in order to
grab the body as a String, and feed that into the violation report
object.

As a drive-by, this patch creates a FrameLoader* temporary
variable to minimize repetition in this area of the code. We use
the loader a few times, but should only have to grab it once.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145347 r145348  
     12013-03-11  Mike West  <mkwst@chromium.org>
     2
     3        XSSAuditor doesn't need a copy of the original document's body.
     4        https://bugs.webkit.org/show_bug.cgi?id=111946
     5
     6        Reviewed by Darin Adler.
     7
     8        The XSSAuditor currently copies the original HTTP body of the document
     9        that's being audited in order to include it into a violation report if
     10        reflected XSS is detected. We don't actually need to do this, as we
     11        have access to the original request information from inside the
     12        XSSAuditorDelegate where the report is generated.
     13        XSSAuditorDelegate::didBlockScript ASSERTs that it's running on the
     14        main thread, so it should be safe to reach through the document's
     15        loader to get that information directly, rather than passing it from
     16        thread to thread via XSSInfo object properties.
     17
     18        * html/parser/XSSAuditor.h:
     19        * html/parser/XSSAuditor.cpp:
     20        (WebCore::XSSAuditor::init):
     21        (WebCore::XSSAuditor::filterToken):
     22        (WebCore::XSSAuditor::isSafeToSendToAnotherThread):
     23        * html/parser/XSSAuditorDelegate.h:
     24        (WebCore::XSSInfo::create):
     25        (WebCore::XSSInfo::XSSInfo):
     26        * html/parser/XSSAuditorDelegate.cpp:
     27        (WebCore::XSSInfo::isSafeToSendToAnotherThread):
     28            Drop the XSSInfo and XSSAuditor properties that held an
     29            isolatedCopy of the the original HTTP body. Depending on the
     30            document's size, this could be a significant savings.
     31        (WebCore::XSSAuditorDelegate::didBlockScript):
     32            Reach into the document's loader's original request in order to
     33            grab the body as a String, and feed that into the violation report
     34            object.
     35
     36            As a drive-by, this patch creates a FrameLoader* temporary
     37            variable to minimize repetition in this area of the code. We use
     38            the loader a few times, but should only have to grab it once.
     39
    1402013-03-11  Silvia Pfeiffer  <silviapf@chromium.org>
    241
  • trunk/Source/WebCore/html/parser/XSSAuditor.cpp

    r145331 r145348  
    312312        return;
    313313    }
    314 
    315     if (!m_reportURL.isEmpty())
    316         m_originalHTTPBody = httpBodyAsString;
    317314}
    318315
     
    335332    if (didBlockScript) {
    336333        bool didBlockEntirePage = (m_xssProtection == ContentSecurityPolicy::BlockReflectedXSS);
    337         OwnPtr<XSSInfo> xssInfo = XSSInfo::create(m_reportURL, m_originalHTTPBody, didBlockEntirePage);
    338         if (!m_reportURL.isEmpty()) {
    339             m_reportURL = KURL();
    340             m_originalHTTPBody = String();
    341         }
     334        OwnPtr<XSSInfo> xssInfo = XSSInfo::create(m_reportURL, didBlockEntirePage);
     335        m_reportURL = KURL();
    342336        return xssInfo.release();
    343337    }
     
    728722{
    729723    return m_documentURL.isSafeToSendToAnotherThread()
    730         && m_originalHTTPBody.isSafeToSendToAnotherThread()
    731724        && m_decodedURL.isSafeToSendToAnotherThread()
    732725        && m_decodedHTTPBody.isSafeToSendToAnotherThread()
  • trunk/Source/WebCore/html/parser/XSSAuditor.h

    r145331 r145348  
    106106    ContentSecurityPolicy::ReflectedXSSDisposition m_xssProtection;
    107107
    108     String m_originalHTTPBody;
    109108    String m_decodedURL;
    110109    String m_decodedHTTPBody;
  • trunk/Source/WebCore/html/parser/XSSAuditorDelegate.cpp

    r145331 r145348  
    3030#include "DOMWindow.h"
    3131#include "Document.h"
     32#include "DocumentLoader.h"
    3233#include "FormData.h"
    3334#include "Frame.h"
     
    4344bool XSSInfo::isSafeToSendToAnotherThread() const
    4445{
    45     return m_reportURL.isSafeToSendToAnotherThread()
    46         && m_originalHTTPBody.isSafeToSendToAnotherThread();
     46    return m_reportURL.isSafeToSendToAnotherThread();
    4747}
    4848
     
    6363    m_document->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, consoleMessage);
    6464
     65    FrameLoader* frameLoader = m_document->frame()->loader();
     66
    6567    if (xssInfo.m_didBlockEntirePage)
    66         m_document->frame()->loader()->stopAllLoaders();
     68        frameLoader->stopAllLoaders();
    6769
    6870    if (!m_didNotifyClient) {
    69         m_document->frame()->loader()->client()->didDetectXSS(m_document->url(), xssInfo.m_didBlockEntirePage);
     71        frameLoader->client()->didDetectXSS(m_document->url(), xssInfo.m_didBlockEntirePage);
    7072        m_didNotifyClient = true;
    7173    }
     
    7476        RefPtr<InspectorObject> reportDetails = InspectorObject::create();
    7577        reportDetails->setString("request-url", m_document->url().string());
    76         reportDetails->setString("request-body", xssInfo.m_originalHTTPBody);
     78
     79        String httpBody;
     80        if (frameLoader->documentLoader()) {
     81            if (FormData* formData = frameLoader->documentLoader()->originalRequest().httpBody())
     82                httpBody = formData->flattenToString();
     83        }
     84        reportDetails->setString("request-body", httpBody);
    7785
    7886        RefPtr<InspectorObject> reportObject = InspectorObject::create();
  • trunk/Source/WebCore/html/parser/XSSAuditorDelegate.h

    r145331 r145348  
    4040class XSSInfo {
    4141public:
    42     static PassOwnPtr<XSSInfo> create(const KURL& reportURL, const String& originalHTTPBody, bool didBlockEntirePage)
     42    static PassOwnPtr<XSSInfo> create(const KURL& reportURL, bool didBlockEntirePage)
    4343    {
    44         return adoptPtr(new XSSInfo(reportURL, originalHTTPBody, didBlockEntirePage));
     44        return adoptPtr(new XSSInfo(reportURL, didBlockEntirePage));
    4545    }
    4646
     
    4848
    4949    KURL m_reportURL;
    50     String m_originalHTTPBody;
    5150    bool m_didBlockEntirePage;
    5251    TextPosition m_textPosition;
    5352
    5453private:
    55     XSSInfo(const KURL& reportURL, const String& originalHTTPBody, bool didBlockEntirePage)
     54    XSSInfo(const KURL& reportURL, bool didBlockEntirePage)
    5655        : m_reportURL(reportURL)
    57         , m_originalHTTPBody(originalHTTPBody)
    5856        , m_didBlockEntirePage(didBlockEntirePage)
    5957    { }
Note: See TracChangeset for help on using the changeset viewer.