Diff
Modified: trunk/LayoutTests/ChangeLog (128702 => 128703)
--- trunk/LayoutTests/ChangeLog 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/LayoutTests/ChangeLog 2012-09-16 05:17:36 UTC (rev 128703)
@@ -1,3 +1,28 @@
+2012-09-15 Mike West <[email protected]>
+
+ Break on inline scripts blocked by CSP.
+ https://bugs.webkit.org/show_bug.cgi?id=93865
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/debugger/debugger-pause-on-blocked-event-handler-expected.txt: Added.
+ * inspector/debugger/debugger-pause-on-blocked-event-handler.html: Added.
+ * inspector/debugger/debugger-pause-on-blocked-script-injection-expected.txt: Added.
+ * inspector/debugger/debugger-pause-on-blocked-script-injection.html: Added.
+ * inspector/debugger/debugger-pause-on-blocked-script-url-expected.txt: Added.
+ * inspector/debugger/debugger-pause-on-blocked-script-url.html: Added.
+ * inspector/debugger/resources/pause-on-blocked-by-csp.js: Added.
+ (test.setStatus):
+ (test.step1):
+ (test.step2):
+ (test):
+ * inspector/debugger/resources/pause-on-blocked-event-handler.js: Added.
+ (testAction):
+ * inspector/debugger/resources/pause-on-blocked-script-injection.js: Added.
+ (testAction):
+ * inspector/debugger/resources/pause-on-blocked-script-url.js: Added.
+ (testAction):
+
2012-09-15 Florin Malita <[email protected]>
<use> not working when the SVG doc is embedded as <object> data
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler-expected.txt (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler-expected.txt 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 13: Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'".
+
+Tests that pause on exception works for inline event handlers blocked by CSP.
+
+Button
+Debugger was enabled.
+Script execution paused.
+Call stack:
+ 0) testAction (pause-on-blocked-event-handler.js:4)
+Script execution resumed.
+Debugger was disabled.
+
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler.html (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler.html (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-event-handler.html 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv="X-WebKit-CSP" content="script-src 'self';">
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p>
+Tests that pause on exception works for inline event handlers blocked by CSP.
+</p>
+<button id="test" _onclick_="alert('FAIL!');">Button</button>
+</body>
+</html>
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection-expected.txt (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection-expected.txt 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".
+
+Tests that pause on exception works for inline scripts blocked by CSP.
+
+Debugger was enabled.
+Script execution paused.
+Call stack:
+ 0) testAction (pause-on-blocked-script-injection.js:5)
+Script execution resumed.
+Debugger was disabled.
+
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection.html (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection.html (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-injection.html 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta http-equiv="X-WebKit-CSP" content="script-src 'self';">
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p>
+Tests that pause on exception works for inline scripts blocked by CSP.
+</p>
+</body>
+</html>
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url-expected.txt (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url-expected.txt 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: line 1: Refused to execute _javascript_ URL because it violates the following Content Security Policy directive: "script-src 'self'".
+
+Tests that pause on exception works for inline script URLs blocked by CSP.
+
+Debugger was enabled.
+Script execution paused.
+Call stack:
+ 0) testAction (pause-on-blocked-script-url.js:6)
+Script execution resumed.
+Debugger was disabled.
+
Added: trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url.html (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url.html (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-pause-on-blocked-script-url.html 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta http-equiv="X-WebKit-CSP" content="script-src 'self';">
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p>
+Tests that pause on exception works for inline script URLs blocked by CSP.
+</p>
+</body>
+</html>
Added: trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-by-csp.js (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-by-csp.js (rev 0)
+++ trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-by-csp.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,30 @@
+function test()
+{
+ WebInspector.showPanel("scripts");
+
+ InspectorTest.addSniffer(WebInspector.CallStackSidebarPane.prototype, "setStatus", setStatus, false);
+
+ function setStatus(status)
+ {
+ // FIXME: For whatever reason, this isn't getting called consistently.
+ // Commenting it out to avoid flakeyness. https://bugs.webkit.org/show_bug.cgi?id=96867
+ // InspectorTest.addResult("Callstack status set to: '" + status + "'.");
+ }
+
+ InspectorTest.startDebuggerTest(step1);
+
+ function step1()
+ {
+ DebuggerAgent.setPauseOnExceptions(WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnUncaughtExceptions);
+ InspectorTest.evaluateInPage("setTimeout(testAction, 0);");
+ InspectorTest.waitUntilPaused(step2);
+ }
+
+ function step2(callFrames)
+ {
+ InspectorTest.captureStackTrace(callFrames);
+ InspectorTest.completeDebuggerTest();
+ }
+}
+
+window.addEventListener('load', runTest);
Added: trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-event-handler.js (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-event-handler.js (rev 0)
+++ trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-event-handler.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,5 @@
+function testAction()
+{
+ var button = document.getElementById('test');
+ button.click();
+}
Added: trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-injection.js (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-injection.js (rev 0)
+++ trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-injection.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,6 @@
+function testAction()
+{
+ var script = document.createElement('script');
+ script.innerText = "alert('FAIL!');";
+ document.body.appendChild(script);
+}
Added: trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-url.js (0 => 128703)
--- trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-url.js (rev 0)
+++ trunk/LayoutTests/inspector/debugger/resources/pause-on-blocked-script-url.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -0,0 +1,7 @@
+function testAction()
+{
+ var a = document.createElement('a');
+ a.setAttribute('href', '_javascript_:alert("FAIL!");');
+ document.body.appendChild(a);
+ a.click();
+}
Modified: trunk/Source/WebCore/ChangeLog (128702 => 128703)
--- trunk/Source/WebCore/ChangeLog 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/ChangeLog 2012-09-16 05:17:36 UTC (rev 128703)
@@ -1,3 +1,73 @@
+2012-09-15 Mike West <[email protected]>
+
+ Pause inspector when inline scripts are blocked by Content Security Policy.
+ https://bugs.webkit.org/show_bug.cgi?id=93865
+
+ Reviewed by Pavel Feldman.
+
+ When Content Security Policy blocks an inline script that's been
+ injected after the document is parsed, a fairly unhelpful console
+ warning is generated; it points at line 1, regardless of where the error
+ occurred. This patch adjusts CSP to not only warn on the console, but
+ also to notify the inspector that it should pause execution if the
+ developer has toggled "Break on Exceptions". Developers will have a
+ better chance of tracking down the error, as they'll have a complete
+ call stack to work with.
+
+ Tests: inspector/debugger/debugger-pause-on-blocked-event-handler.html
+ inspector/debugger/debugger-pause-on-blocked-script-injection.html
+ inspector/debugger/debugger-pause-on-blocked-script-url.html
+
+ * English.lproj/localizedStrings.js:
+ Adding localizable string for the new friendly pause message.
+ * inspector/Inspector.json:
+ Add CSPViolation as a recognized reason for pausing execution.
+ * inspector/InspectorDebuggerAgent.cpp:
+ (WebCore::InspectorDebuggerAgent::scriptExecutionBlockedByCSP):
+ Teach the InspectorDebuggerAgent about script blocking. If pause on
+ exceptions is enabled, call 'InspectorDebuggerAgent::breakProgram',
+ and pass in an error object with a description that points to CSP
+ as the culprit.
+ (WebCore):
+ * inspector/InspectorDebuggerAgent.h:
+ (InspectorDebuggerAgent):
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore):
+ (WebCore::InspectorInstrumentation::scriptExecutionBlockedByCSPImpl):
+ Wire 'InspectorInstrumentation::scriptExecutionBlockedByCSP' to
+ the InspectorDebuggerAgent backend.
+ * inspector/InspectorInstrumentation.h:
+ (InspectorInstrumentation):
+ (WebCore::InspectorInstrumentation::scriptExecutionBlockedByCSP):
+ The public interface that should be kicked whenever CSP blocks
+ script execution.
+ (WebCore):
+ * inspector/front-end/DebuggerModel.js:
+ Add CSPViolation as a recognized reason for pausing execution.
+ * inspector/front-end/ScriptsPanel.js:
+ Add a friendly call stack status message for CSP violations.
+ * page/ContentSecurityPolicy.cpp:
+ (CSPDirectiveList):
+ (WebCore::CSPDirectiveList::checkNonceAndReportViolation):
+ If script is blocked because the nonce doesn't match, report the
+ blocked script to the inspector.
+ (WebCore::CSPDirectiveList::checkInlineAndReportViolation):
+ If inline script is blocked, report the blocked script to the
+ inspector. This requires adding a bool parameter to differentiate
+ blocking inline script from inline style.
+ (WebCore::CSPDirectiveList::allowJavaScriptURLs):
+ Tell 'checkInlineAndReportViolation' that we're dealing with script.
+ (WebCore::CSPDirectiveList::allowInlineEventHandlers):
+ Tell 'checkInlineAndReportViolation' that we're dealing with script.
+ (WebCore::CSPDirectiveList::allowInlineScript):
+ Tell 'checkInlineAndReportViolation' that we're dealing with script.
+ (WebCore::CSPDirectiveList::allowInlineStyle):
+ Tell 'checkInlineAndReportViolation' that we're not dealing with script.
+ (WebCore::ContentSecurityPolicy::reportBlockedScriptExecutionToInspector):
+ Public interface for the various CSP* classes to poke the inspector.
+ (WebCore):
+ * page/ContentSecurityPolicy.h:
+
2012-09-15 Florin Malita <[email protected]>
<use> not working when the SVG doc is embedded as <object> data
Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (128702 => 128703)
--- trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -495,6 +495,7 @@
localizedStrings["Paused on a XMLHttpRequest."] = "Paused on a XMLHttpRequest.";
localizedStrings["Paused on a \"%s\" Event Listener."] = "Paused on a \"%s\" Event Listener.";
localizedStrings["Paused on a _javascript_ breakpoint."] = "Paused on a _javascript_ breakpoint.";
+localizedStrings["Paused on a script blocked due to Content Security Policy directive: \"%s\"."] = "Paused on a script blocked due to Content Security Policy directive: \"%s\".";
localizedStrings["URL contains \"%s\""] = "URL contains \"%s\"";
localizedStrings["Network"] = "Network";
localizedStrings["Status"] = "Status";
Modified: trunk/Source/WebCore/inspector/Inspector.json (128702 => 128703)
--- trunk/Source/WebCore/inspector/Inspector.json 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/Inspector.json 2012-09-16 05:17:36 UTC (rev 128703)
@@ -2767,7 +2767,7 @@
"name": "paused",
"parameters": [
{ "name": "callFrames", "type": "array", "items": { "$ref": "CallFrame" }, "description": "Call stack the virtual machine stopped on." },
- { "name": "reason", "type": "string", "enum": [ "XHR", "DOM", "EventListener", "exception", "assert", "other" ], "description": "Pause reason." },
+ { "name": "reason", "type": "string", "enum": [ "XHR", "DOM", "EventListener", "exception", "assert", "CSPViolation", "other" ], "description": "Pause reason." },
{ "name": "data", "type": "object", "optional": true, "description": "Object containing break-specific auxiliary properties." }
],
"description": "Fired when the virtual machine stopped on breakpoint or exception or any other stop criteria."
Modified: trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp (128702 => 128703)
--- trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp 2012-09-16 05:17:36 UTC (rev 128703)
@@ -580,6 +580,15 @@
{
}
+void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directiveText)
+{
+ if (scriptDebugServer().pauseOnExceptionsState() != ScriptDebugServer::DontPauseOnExceptions) {
+ RefPtr<InspectorObject> directive = InspectorObject::create();
+ directive->setString("directiveText", directiveText);
+ breakProgram(InspectorFrontend::Debugger::Reason::CSPViolation, directive.release());
+ }
+}
+
PassRefPtr<Array<TypeBuilder::Debugger::CallFrame> > InspectorDebuggerAgent::currentCallFrames()
{
if (!m_pausedScriptState)
Modified: trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h (128702 => 128703)
--- trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h 2012-09-16 05:17:36 UTC (rev 128703)
@@ -94,9 +94,6 @@
virtual void restartFrame(ErrorString*, const String& callFrameId, RefPtr<TypeBuilder::Array<TypeBuilder::Debugger::CallFrame> >& newCallFrames, RefPtr<InspectorObject>& result);
virtual void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource);
virtual void getFunctionDetails(ErrorString*, const String& functionId, RefPtr<TypeBuilder::Debugger::FunctionDetails>&);
- void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
- void cancelPauseOnNextStatement();
- void breakProgram(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
virtual void pause(ErrorString*);
virtual void resume(ErrorString*);
virtual void stepOver(ErrorString*);
@@ -116,6 +113,11 @@
void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown);
virtual void setOverlayMessage(ErrorString*, const String*);
+ void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
+ void cancelPauseOnNextStatement();
+ void breakProgram(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<InspectorObject> data);
+ virtual void scriptExecutionBlockedByCSP(const String& directiveText);
+
class Listener {
public:
virtual ~Listener() { }
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (128702 => 128703)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-09-16 05:17:36 UTC (rev 128703)
@@ -813,6 +813,14 @@
resourceAgent->setInitialScriptContent(identifier, sourceString);
}
+void InspectorInstrumentation::scriptExecutionBlockedByCSPImpl(InstrumentingAgents* instrumentingAgents, const String& directiveText)
+{
+#if ENABLE(_javascript__DEBUGGER)
+ if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
+ debuggerAgent->scriptExecutionBlockedByCSP(directiveText);
+#endif
+}
+
void InspectorInstrumentation::didReceiveScriptResponseImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier)
{
if (InspectorResourceAgent* resourceAgent = instrumentingAgents->inspectorResourceAgent())
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (128702 => 128703)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-09-16 05:17:36 UTC (rev 128703)
@@ -192,6 +192,7 @@
static void willLoadXHRSynchronously(ScriptExecutionContext*);
static void didLoadXHRSynchronously(ScriptExecutionContext*);
static void scriptImported(ScriptExecutionContext*, unsigned long identifier, const String& sourceString);
+ static void scriptExecutionBlockedByCSP(ScriptExecutionContext*, const String& directiveText);
static void didReceiveScriptResponse(ScriptExecutionContext*, unsigned long identifier);
static void domContentLoadedEventFired(Frame*);
static void loadEventFired(Frame*);
@@ -374,6 +375,7 @@
static void willLoadXHRSynchronouslyImpl(InstrumentingAgents*);
static void didLoadXHRSynchronouslyImpl(InstrumentingAgents*);
static void scriptImportedImpl(InstrumentingAgents*, unsigned long identifier, const String& sourceString);
+ static void scriptExecutionBlockedByCSPImpl(InstrumentingAgents*, const String& directiveText);
static void didReceiveScriptResponseImpl(InstrumentingAgents*, unsigned long identifier);
static void domContentLoadedEventFiredImpl(InstrumentingAgents*, Frame*);
static void loadEventFiredImpl(InstrumentingAgents*, Frame*);
@@ -1240,6 +1242,14 @@
#endif
}
+inline void InspectorInstrumentation::scriptExecutionBlockedByCSP(ScriptExecutionContext* context, const String& directiveText)
+{
+#if ENABLE(INSPECTOR)
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
+ scriptExecutionBlockedByCSPImpl(instrumentingAgents, directiveText);
+#endif
+}
+
inline void InspectorInstrumentation::didReceiveScriptResponse(ScriptExecutionContext* context, unsigned long identifier)
{
#if ENABLE(INSPECTOR)
Modified: trunk/Source/WebCore/inspector/front-end/DebuggerModel.js (128702 => 128703)
--- trunk/Source/WebCore/inspector/front-end/DebuggerModel.js 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerModel.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -95,7 +95,8 @@
EventListener: "EventListener",
XHR: "XHR",
Exception: "exception",
- Assert: "assert"
+ Assert: "assert",
+ CSPViolation: "CSPViolation"
}
WebInspector.DebuggerModel.prototype = {
Modified: trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js (128702 => 128703)
--- trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js 2012-09-16 05:17:36 UTC (rev 128703)
@@ -298,6 +298,8 @@
this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on exception: '%s'.", details.auxData.description));
else if (details.reason === WebInspector.DebuggerModel.BreakReason.Assert)
this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on assertion."));
+ else if (details.reason === WebInspector.DebuggerModel.BreakReason.CSPViolation)
+ this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a script blocked due to Content Security Policy directive: \"%s\".", details.auxData.directiveText));
else {
function didGetUILocation(uiLocation)
{
Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.cpp (128702 => 128703)
--- trunk/Source/WebCore/page/ContentSecurityPolicy.cpp 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.cpp 2012-09-16 05:17:36 UTC (rev 128703)
@@ -755,8 +755,9 @@
void setEvalDisabledErrorMessage(const String& errorMessage) { m_evalDisabledErrorMessage = errorMessage; }
bool checkEvalAndReportViolation(SourceListDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
- bool checkInlineAndReportViolation(SourceListDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
+ bool checkInlineAndReportViolation(SourceListDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, bool isScript) const;
bool checkNonceAndReportViolation(NonceDirective*, const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
+
bool checkSourceAndReportViolation(SourceListDirective*, const KURL&, const String& type) const;
bool checkMediaTypeAndReportViolation(MediaListDirective*, const String& type, const String& typeAttribute, const String& consoleMessage) const;
@@ -862,7 +863,11 @@
if (checkEval(directive))
return true;
reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack);
- return denyIfEnforcingPolicy();
+ if (!m_reportOnly) {
+ m_policy->reportBlockedScriptExecutionToInspector(directive->text());
+ return false;
+ }
+ return true;
}
bool CSPDirectiveList::checkNonceAndReportViolation(NonceDirective* directive, const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
@@ -886,12 +891,18 @@
return denyIfEnforcingPolicy();
}
-bool CSPDirectiveList::checkInlineAndReportViolation(SourceListDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
+bool CSPDirectiveList::checkInlineAndReportViolation(SourceListDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, bool isScript) const
{
if (checkInline(directive))
return true;
reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine);
- return denyIfEnforcingPolicy();
+
+ if (!m_reportOnly) {
+ if (isScript)
+ m_policy->reportBlockedScriptExecutionToInspector(directive->text());
+ return false;
+ }
+ return true;
}
bool CSPDirectiveList::checkSourceAndReportViolation(SourceListDirective* directive, const KURL& url, const String& type) const
@@ -913,7 +924,7 @@
{
DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execute _javascript_ URL because it violates the following Content Security Policy directive: ")));
if (reportingStatus == ContentSecurityPolicy::SendReport) {
- return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
+ return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine, true)
&& checkNonceAndReportViolation(m_scriptNonce.get(), String(), consoleMessage, contextURL, contextLine));
} else {
return (checkInline(operativeDirective(m_scriptSrc.get()))
@@ -925,7 +936,7 @@
{
DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execute inline event handler because it violates the following Content Security Policy directive: ")));
if (reportingStatus == ContentSecurityPolicy::SendReport) {
- return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
+ return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine, true)
&& checkNonceAndReportViolation(m_scriptNonce.get(), String(), consoleMessage, contextURL, contextLine));
} else {
return (checkInline(operativeDirective(m_scriptSrc.get()))
@@ -937,7 +948,7 @@
{
DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execute inline script because it violates the following Content Security Policy directive: ")));
return reportingStatus == ContentSecurityPolicy::SendReport ?
- checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine) :
+ checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine, true) :
checkInline(operativeDirective(m_scriptSrc.get()));
}
@@ -945,7 +956,7 @@
{
DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to apply inline style because it violates the following Content Security Policy directive: ")));
return reportingStatus == ContentSecurityPolicy::SendReport ?
- checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine) :
+ checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine, false) :
checkInline(operativeDirective(m_styleSrc.get()));
}
@@ -1556,4 +1567,9 @@
m_scriptExecutionContext->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, contextURL, contextLine.oneBasedInt(), callStack);
}
+void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String& directiveText) const
+{
+ InspectorInstrumentation::scriptExecutionBlockedByCSP(m_scriptExecutionContext, directiveText);
}
+
+}
Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.h (128702 => 128703)
--- trunk/Source/WebCore/page/ContentSecurityPolicy.h 2012-09-16 05:03:43 UTC (rev 128702)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.h 2012-09-16 05:17:36 UTC (rev 128703)
@@ -108,6 +108,8 @@
void reportUnrecognizedDirective(const String&) const;
void reportViolation(const String& directiveText, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
+ void reportBlockedScriptExecutionToInspector(const String& directiveText) const;
+
const KURL& url() const;
KURL completeURL(const String&) const;
SecurityOrigin* securityOrigin() const;