Changeset 118585 in webkit
- Timestamp:
- May 25, 2012, 4:29:45 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 28 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r118584 r118585 1 2012-05-25 Mike West <mkwst@chromium.org> 2 3 Inline script and style blocked by Content Security Policy should provide more detailed console errors. 4 https://bugs.webkit.org/show_bug.cgi?id=86848 5 6 Reviewed by Adam Barth. 7 8 * http/tests/security/contentSecurityPolicy/combine-multiple-policies-expected.txt: 9 * http/tests/security/contentSecurityPolicy/default-src-inline-blocked-expected.txt: 10 * http/tests/security/contentSecurityPolicy/injected-inline-script-allowed-expected.txt: Added. 11 * http/tests/security/contentSecurityPolicy/injected-inline-script-allowed.html: Added. 12 * http/tests/security/contentSecurityPolicy/injected-inline-script-blocked-expected.txt: Copied from LayoutTests/http/tests/security/contentSecurityPolicy/inline-script-blocked-expected.txt. 13 * http/tests/security/contentSecurityPolicy/injected-inline-script-blocked.html: Added. 14 * http/tests/security/contentSecurityPolicy/injected-inline-style-allowed-expected.txt: Added. 15 * http/tests/security/contentSecurityPolicy/injected-inline-style-allowed.html: Added. 16 * http/tests/security/contentSecurityPolicy/injected-inline-style-blocked-expected.txt: Added. 17 * http/tests/security/contentSecurityPolicy/injected-inline-style-blocked.html: Added. 18 * http/tests/security/contentSecurityPolicy/inline-script-blocked-expected.txt: 19 * http/tests/security/contentSecurityPolicy/inline-script-blocked-goofy-expected.txt: 20 * http/tests/security/contentSecurityPolicy/inline-script-blocked-javascript-url-expected.txt: 21 * http/tests/security/contentSecurityPolicy/inline-style-attribute-blocked-expected.txt: 22 * http/tests/security/contentSecurityPolicy/inline-style-blocked-expected.txt: 23 * http/tests/security/contentSecurityPolicy/javascript-url-blocked-expected.txt: 24 * http/tests/security/contentSecurityPolicy/report-and-enforce-expected.txt: 25 * http/tests/security/contentSecurityPolicy/report-only-expected.txt: 26 * http/tests/security/contentSecurityPolicy/report-only-from-header-expected.txt: 27 * http/tests/security/contentSecurityPolicy/report-uri-expected.txt: 28 * http/tests/security/contentSecurityPolicy/report-uri-from-child-frame-expected.txt: 29 * http/tests/security/contentSecurityPolicy/resources/inject-script.js: Added. 30 * http/tests/security/contentSecurityPolicy/resources/inject-style.js: Added. 31 * http/tests/security/contentSecurityPolicy/script-src-none-inline-event-expected.txt: 32 * http/tests/security/contentSecurityPolicy/srcdoc-doesnt-bypass-script-src-expected.txt: 33 1 34 2012-05-25 Joshua Bell <jsbell@chromium.org> 2 35 -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/combine-multiple-policies-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 11: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 CONSOLE MESSAGE: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'".3 CONSOLE MESSAGE: line 14: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'". 4 4 5 5 This test checks that we enforce all the supplied policies. This test passes if it doesn't alert fail and if the style doesn't apply. -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-inline-blocked-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'".1 CONSOLE MESSAGE: line 9: Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". 2 2 3 3 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/injected-inline-script-blocked-expected.txt
r118584 r118585 3 3 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". 4 4 5 This test passes if it doesn't alert fail. 5 -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/inline-script-blocked-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*".1 CONSOLE MESSAGE: line 9: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". 2 2 3 3 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/inline-script-blocked-goofy-expected.txt
r117006 r118585 1 1 CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'options'. 2 2 3 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*".3 CONSOLE MESSAGE: line 9: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". 4 4 5 CONSOLE MESSAGE: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*".5 CONSOLE MESSAGE: line 7: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". 6 6 7 7 This test passes if it doesn't alert fail. -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/inline-script-blocked-javascript-url-expected.txt
r117006 r118585 5 5 CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'options'. 6 6 7 CONSOLE MESSAGE: Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*".7 CONSOLE MESSAGE: line 1: Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src http://127.0.0.1:*". 8 8 9 9 This test passes if it doesn't alert fail. -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/inline-style-attribute-blocked-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'".1 CONSOLE MESSAGE: line 10: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'". 2 2 3 3 PASS -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/inline-style-blocked-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'".1 CONSOLE MESSAGE: line 5: Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'none'". 2 2 3 3 PASS -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/javascript-url-blocked-expected.txt
r117006 r118585 5 5 CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'allow'. 6 6 7 CONSOLE MESSAGE: Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'none'".7 CONSOLE MESSAGE: line 1: Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'none'". 8 8 9 9 CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'allow'. -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-and-enforce-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 3: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 ALERT: PASS -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 2: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 ALERT: PASS -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-from-header-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 1: [Report Only] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 ALERT: PASS -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-uri-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 2: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 CSP report received: -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-uri-from-child-frame-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 2: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/script-src-none-inline-event-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'none'".1 CONSOLE MESSAGE: line 3: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'none'". 2 2 3 3 -
trunk/LayoutTests/http/tests/security/contentSecurityPolicy/srcdoc-doesnt-bypass-script-src-expected.txt
r117006 r118585 1 CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".1 CONSOLE MESSAGE: line 1: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". 2 2 3 3 This test passes if it doesn't alert fail. -
trunk/Source/WebCore/ChangeLog
r118583 r118585 1 2012-05-25 Mike West <mkwst@chromium.org> 2 3 Inline script and style blocked by Content Security Policy should provide more detailed console errors. 4 https://bugs.webkit.org/show_bug.cgi?id=86848 5 6 Reviewed by Adam Barth. 7 8 This change adds a URL and line number for context to each call to 9 `ContentSecurityPolicy::allowInline*`, and pipes it through to the 10 console message generation in `CSPDirectiveList::reportViolation`. 11 12 Line numbers are not added for injected scripts (`document.write(...)`, 13 `document.body.appendChild`, and etc.). 14 15 Tests: http/tests/security/contentSecurityPolicy/injected-inline-script-allowed.html 16 http/tests/security/contentSecurityPolicy/injected-inline-script-blocked.html 17 http/tests/security/contentSecurityPolicy/injected-inline-style-allowed.html 18 http/tests/security/contentSecurityPolicy/injected-inline-style-blocked.html 19 20 * bindings/ScriptControllerBase.cpp: 21 (WebCore::ScriptController::executeIfJavaScriptURL): 22 * bindings/js/JSLazyEventListener.cpp: 23 (WebCore::JSLazyEventListener::initializeJSFunction): 24 * bindings/v8/V8LazyEventListener.cpp: 25 (WebCore::V8LazyEventListener::prepareListenerObject): 26 * dom/ScriptElement.cpp: 27 (WebCore::ScriptElement::ScriptElement): 28 (WebCore::ScriptElement::executeScript): 29 * dom/ScriptElement.h: 30 (ScriptElement): 31 * dom/StyleElement.cpp: 32 (WebCore::StyleElement::StyleElement): 33 (WebCore::StyleElement::createSheet): 34 * dom/StyleElement.h: 35 (StyleElement): 36 * dom/StyledElement.cpp: 37 (WebCore::StyledElement::StyledElement): 38 (WebCore): 39 (WebCore::StyledElement::style): 40 (WebCore::StyledElement::styleAttributeChanged): 41 * dom/StyledElement.h: 42 (StyledElement): 43 * page/ContentSecurityPolicy.cpp: 44 (CSPDirectiveList): 45 (WebCore::CSPDirectiveList::reportViolation): 46 (WebCore::CSPDirectiveList::checkInlineAndReportViolation): 47 (WebCore::CSPDirectiveList::checkEvalAndReportViolation): 48 (WebCore::CSPDirectiveList::allowJavaScriptURLs): 49 (WebCore::CSPDirectiveList::allowInlineEventHandlers): 50 (WebCore::CSPDirectiveList::allowInlineScript): 51 (WebCore::CSPDirectiveList::allowInlineStyle): 52 (WebCore::CSPDirectiveList::allowEval): 53 (WebCore): 54 (WebCore::isAllowedByAllWithCallStack): 55 (WebCore::isAllowedByAllWithContext): 56 (WebCore::ContentSecurityPolicy::allowJavaScriptURLs): 57 (WebCore::ContentSecurityPolicy::allowInlineEventHandlers): 58 (WebCore::ContentSecurityPolicy::allowInlineScript): 59 (WebCore::ContentSecurityPolicy::allowInlineStyle): 60 * page/ContentSecurityPolicy.h: 61 (WTF): 62 1 63 2012-05-25 Tim Horton <timothy_horton@apple.com> 2 64 -
trunk/Source/WebCore/bindings/ScriptControllerBase.cpp
r106043 r118585 33 33 #include "Settings.h" 34 34 #include "UserGestureIndicator.h" 35 #include <wtf/text/TextPosition.h> 35 36 36 37 namespace WebCore { … … 76 77 if (!m_frame->page() 77 78 || !m_frame->page()->javaScriptURLsAreAllowed() 78 || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs( )79 || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs(m_frame->document()->url(), eventHandlerPosition().m_line) 79 80 || m_frame->inViewSourceMode()) 80 81 return true; -
trunk/Source/WebCore/bindings/js/JSLazyEventListener.cpp
r113387 r118585 81 81 return 0; 82 82 83 if (!document->contentSecurityPolicy()->allowInlineEventHandlers( ))83 if (!document->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line)) 84 84 return 0; 85 85 -
trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp
r117928 r118585 106 106 return; 107 107 108 if (context->isDocument() && !static_cast<Document*>(context)->contentSecurityPolicy()->allowInlineEventHandlers( ))108 if (context->isDocument() && !static_cast<Document*>(context)->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line)) 109 109 return; 110 110 -
trunk/Source/WebCore/dom/ScriptElement.cpp
r118192 r118585 42 42 #include "ScriptSourceCode.h" 43 43 #include "ScriptValue.h" 44 #include "ScriptableDocumentParser.h" 44 45 #include "SecurityOrigin.h" 45 46 #include "Settings.h" … … 48 49 #include <wtf/text/StringBuilder.h> 49 50 #include <wtf/text/StringHash.h> 51 #include <wtf/text/TextPosition.h> 50 52 51 53 #if ENABLE(SVG) … … 59 61 : m_element(element) 60 62 , m_cachedScript(0) 63 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) 61 64 , m_parserInserted(parserInserted) 62 65 , m_isExternalScript(false) … … 71 74 { 72 75 ASSERT(m_element); 76 if (parserInserted && m_element->document()->scriptableDocumentParser() && !m_element->document()->isInDocumentWrite()) 77 m_startLineNumber = m_element->document()->scriptableDocumentParser()->lineNumber(); 73 78 } 74 79 … … 277 282 return; 278 283 279 if (!m_isExternalScript && !m_element->document()->contentSecurityPolicy()->allowInlineScript( ))284 if (!m_isExternalScript && !m_element->document()->contentSecurityPolicy()->allowInlineScript(m_element->document()->url(), m_startLineNumber)) 280 285 return; 281 286 -
trunk/Source/WebCore/dom/ScriptElement.h
r118192 r118585 94 94 Element* m_element; 95 95 CachedResourceHandle<CachedScript> m_cachedScript; 96 WTF::OrdinalNumber m_startLineNumber; 96 97 bool m_parserInserted : 1; 97 98 bool m_isExternalScript : 1; -
trunk/Source/WebCore/dom/StyleElement.cpp
r118336 r118585 31 31 #include "StyleSheetContents.h" 32 32 #include <wtf/text/StringBuilder.h> 33 #include <wtf/text/TextPosition.h> 33 34 34 35 namespace WebCore { … … 49 50 : m_createdByParser(createdByParser) 50 51 , m_loading(false) 51 , m_startLineNumber( 0)52 { 53 if (createdByParser && document && document->scriptableDocumentParser() )54 m_startLineNumber = document->scriptableDocumentParser()->lineNumber() .zeroBasedInt();52 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) 53 { 54 if (createdByParser && document && document->scriptableDocumentParser() && !document->isInDocumentWrite()) 55 m_startLineNumber = document->scriptableDocumentParser()->lineNumber(); 55 56 } 56 57 … … 145 146 } 146 147 147 void StyleElement::createSheet(Element* e, intstartLineNumber, const String& text)148 void StyleElement::createSheet(Element* e, WTF::OrdinalNumber startLineNumber, const String& text) 148 149 { 149 150 ASSERT(e); … … 158 159 // If type is empty or CSS, this is a CSS style sheet. 159 160 const AtomicString& type = this->type(); 160 if (document->contentSecurityPolicy()->allowInlineStyle( ) && isCSS(e, type)) {161 if (document->contentSecurityPolicy()->allowInlineStyle(e->document()->url(), startLineNumber) && isCSS(e, type)) { 161 162 RefPtr<MediaQuerySet> mediaQueries; 162 163 if (e->isHTMLElement()) … … 174 175 m_sheet->setMediaQueries(mediaQueries.release()); 175 176 m_sheet->setTitle(e->title()); 176 177 m_sheet->contents()->parseStringAtLine(text, startLineNumber); 177 m_sheet->contents()->parseStringAtLine(text, startLineNumber.zeroBasedInt()); 178 178 179 179 m_loading = false; -
trunk/Source/WebCore/dom/StyleElement.h
r113887 r118585 23 23 24 24 #include "CSSStyleSheet.h" 25 #include <wtf/text/TextPosition.h> 25 26 26 27 namespace WebCore { … … 53 54 54 55 private: 55 void createSheet(Element*, intstartLineNumber, const String& text = String());56 void createSheet(Element*, WTF::OrdinalNumber startLineNumber, const String& text = String()); 56 57 void process(Element*); 57 58 void clearSheet(); … … 59 60 bool m_createdByParser; 60 61 bool m_loading; 61 intm_startLineNumber;62 WTF::OrdinalNumber m_startLineNumber; 62 63 }; 63 64 -
trunk/Source/WebCore/dom/StyledElement.cpp
r118194 r118585 38 38 #include "HTMLNames.h" 39 39 #include "HTMLParserIdioms.h" 40 #include "ScriptableDocumentParser.h" 40 41 #include "StylePropertySet.h" 41 42 #include "StyleResolver.h" 42 43 #include <wtf/HashFunctions.h> 44 #include <wtf/text/TextPosition.h> 43 45 44 46 using namespace std; … … 127 129 } 128 130 131 StyledElement::StyledElement(const QualifiedName& name, Document* document, ConstructionType type) 132 : Element(name, document, type) 133 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) 134 { 135 if (document && document->scriptableDocumentParser() && !document->isInDocumentWrite()) 136 m_startLineNumber = document->scriptableDocumentParser()->lineNumber(); 137 } 138 129 139 StyledElement::~StyledElement() 130 140 { … … 132 142 } 133 143 134 CSSStyleDeclaration* StyledElement::style() 135 { 144 CSSStyleDeclaration* StyledElement::style() 145 { 136 146 return ensureAttributeData()->ensureMutableInlineStyle(this)->ensureInlineCSSStyleDeclaration(this); 137 147 } … … 174 184 if (newStyleString.isNull()) 175 185 destroyInlineStyle(); 176 else if (document()->contentSecurityPolicy()->allowInlineStyle( ))186 else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), m_startLineNumber)) 177 187 ensureAttributeData()->updateInlineStyleAvoidingMutation(this, newStyleString); 178 188 setIsStyleAttributeValid(); -
trunk/Source/WebCore/dom/StyledElement.h
r117323 r118585 28 28 #include "Element.h" 29 29 #include "StylePropertySet.h" 30 #include <wtf/text/TextPosition.h> 30 31 31 32 namespace WebCore { … … 63 64 64 65 protected: 65 StyledElement(const QualifiedName& name, Document* document, ConstructionType type) 66 : Element(name, document, type) 67 { 68 } 66 StyledElement(const QualifiedName&, Document*, ConstructionType); 69 67 70 68 virtual void attributeChanged(const Attribute&) OVERRIDE; … … 96 94 attributeData()->destroyInlineStyle(this); 97 95 } 96 97 WTF::OrdinalNumber m_startLineNumber; 98 98 }; 99 99 -
trunk/Source/WebCore/page/ContentSecurityPolicy.cpp
r117826 r118585 32 32 #include "FormDataList.h" 33 33 #include "Frame.h" 34 #include "InspectorInstrumentation.h" 34 35 #include "InspectorValues.h" 35 36 #include "PingLoader.h" … … 37 38 #include "SecurityOrigin.h" 38 39 #include "TextEncoding.h" 40 #include <wtf/text/TextPosition.h> 39 41 #include <wtf/text/WTFString.h> 40 42 … … 491 493 ContentSecurityPolicy::HeaderType headerType() const { return m_reportOnly ? ContentSecurityPolicy::ReportOnly : ContentSecurityPolicy::EnforcePolicy; } 492 494 493 bool allowJavaScriptURLs( ) const;494 bool allowInlineEventHandlers( ) const;495 bool allowInlineScript( ) const;496 bool allowInlineStyle( ) const;495 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 496 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 497 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 498 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 497 499 bool allowEval(PassRefPtr<ScriptCallStack>) const; 498 500 … … 519 521 520 522 CSPDirective* operativeDirective(CSPDirective*) const; 521 void reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL = KURL(), PassRefPtr<ScriptCallStack> = 0) const;523 void reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL = KURL(), const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const; 522 524 void logUnrecognizedDirective(const String& name) const; 523 525 bool checkEval(CSPDirective*) const; 524 526 525 bool checkInlineAndReportViolation(CSPDirective*, const String& consoleMessage ) const;526 bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, PassRefPtr<ScriptCallStack>) const;527 bool checkInlineAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 528 bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const; 527 529 bool checkSourceAndReportViolation(CSPDirective*, const KURL&, const String& type) const; 528 530 … … 576 578 } 577 579 578 void CSPDirectiveList::reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL, PassRefPtr<ScriptCallStack> callStack) const580 void CSPDirectiveList::reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const 579 581 { 580 582 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleMessage; 581 m_scriptExecutionContext->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, String(), 0, callStack);583 m_scriptExecutionContext->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, contextURL, contextLine.oneBasedInt(), callStack); 582 584 583 585 if (m_reportURIs.isEmpty()) … … 639 641 } 640 642 641 bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage ) const643 bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const 642 644 { 643 645 if (!directive || directive->allowInline()) 644 646 return true; 645 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n" );647 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine); 646 648 return denyIfEnforcingPolicy(); 647 649 } 648 650 649 bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, PassRefPtr<ScriptCallStack> callStack) const651 bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const 650 652 { 651 653 if (checkEval(directive)) 652 654 return true; 653 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), c allStack);655 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack); 654 656 return denyIfEnforcingPolicy(); 655 657 } … … 664 666 } 665 667 666 bool CSPDirectiveList::allowJavaScriptURLs( ) const668 bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 667 669 { 668 670 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute JavaScript URL because it violates the following Content Security Policy directive: ")); 669 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage );670 } 671 672 bool CSPDirectiveList::allowInlineEventHandlers( ) const671 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine); 672 } 673 674 bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 673 675 { 674 676 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline event handler because it violates the following Content Security Policy directive: ")); 675 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage );676 } 677 678 bool CSPDirectiveList::allowInlineScript( ) const677 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine); 678 } 679 680 bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 679 681 { 680 682 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline script because it violates the following Content Security Policy directive: ")); 681 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage );682 } 683 684 bool CSPDirectiveList::allowInlineStyle( ) const683 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine); 684 } 685 686 bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 685 687 { 686 688 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to apply inline style because it violates the following Content Security Policy directive: ")); 687 return checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage );689 return checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine); 688 690 } 689 691 … … 691 693 { 692 694 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to evaluate script because it violates the following Content Security Policy directive: ")); 693 return checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, callStack);695 return checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, String(), WTF::OrdinalNumber::beforeFirst(), callStack); 694 696 } 695 697 … … 924 926 } 925 927 926 template<bool (CSPDirectiveList::*allowed)() const>927 bool isAllowedByAll(const CSPDirectiveListVector& policies)928 {929 for (size_t i = 0; i < policies.size(); ++i) {930 if (!(policies[i].get()->*allowed)())931 return false;932 }933 return true;934 }935 936 928 template<bool (CSPDirectiveList::*allowed)(PassRefPtr<ScriptCallStack>) const> 937 929 bool isAllowedByAllWithCallStack(const CSPDirectiveListVector& policies, PassRefPtr<ScriptCallStack> callStack) … … 944 936 } 945 937 938 template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&) const> 939 bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine) 940 { 941 for (size_t i = 0; i < policies.size(); ++i) { 942 if (!(policies[i].get()->*allowed)(contextURL, contextLine)) 943 return false; 944 } 945 return true; 946 } 947 946 948 template<bool (CSPDirectiveList::*allowFromURL)(const KURL&) const> 947 949 bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& url) … … 954 956 } 955 957 956 bool ContentSecurityPolicy::allowJavaScriptURLs( ) const957 { 958 return isAllowedByAll <&CSPDirectiveList::allowJavaScriptURLs>(m_policies);959 } 960 961 bool ContentSecurityPolicy::allowInlineEventHandlers( ) const962 { 963 return isAllowedByAll <&CSPDirectiveList::allowInlineEventHandlers>(m_policies);964 } 965 966 bool ContentSecurityPolicy::allowInlineScript( ) const967 { 968 return isAllowedByAll <&CSPDirectiveList::allowInlineScript>(m_policies);969 } 970 971 bool ContentSecurityPolicy::allowInlineStyle( ) const958 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 959 { 960 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine); 961 } 962 963 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 964 { 965 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine); 966 } 967 968 bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 969 { 970 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine); 971 } 972 973 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const 972 974 { 973 975 if (m_overrideInlineStyleAllowed) 974 976 return true; 975 return isAllowedByAll <&CSPDirectiveList::allowInlineStyle>(m_policies);977 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine); 976 978 } 977 979 -
trunk/Source/WebCore/page/ContentSecurityPolicy.h
r117826 r118585 32 32 #include <wtf/text/WTFString.h> 33 33 34 namespace WTF { 35 class OrdinalNumber; 36 } 37 34 38 namespace WebCore { 35 39 … … 63 67 HeaderType deprecatedHeaderType() const; 64 68 65 bool allowJavaScriptURLs( ) const;66 bool allowInlineEventHandlers( ) const;67 bool allowInlineScript( ) const;68 bool allowInlineStyle( ) const;69 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 70 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 71 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 72 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const; 69 73 bool allowEval(PassRefPtr<ScriptCallStack>) const; 70 74
Note:
See TracChangeset
for help on using the changeset viewer.