Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Unified Diff: Source/core/page/ContentSecurityPolicy.cpp

Issue 21789002: CSP: Deduplicate violation reports before sending. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/page/ContentSecurityPolicy.cpp
diff --git a/Source/core/page/ContentSecurityPolicy.cpp b/Source/core/page/ContentSecurityPolicy.cpp
index 941543170e464d2178bc842d0cb8a653fadd9452..2b4511fdb08a92939495f797a3463a102415ba35 100644
--- a/Source/core/page/ContentSecurityPolicy.cpp
+++ b/Source/core/page/ContentSecurityPolicy.cpp
@@ -1723,7 +1723,7 @@ static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventI
}
}
-void ContentSecurityPolicy::reportViolation(const String& directiveText, const String& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL, const WTF::OrdinalNumber& contextLine, ScriptState* state) const
+void ContentSecurityPolicy::reportViolation(const String& directiveText, const String& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL, const WTF::OrdinalNumber& contextLine, ScriptState* state)
{
logToConsole(consoleMessage, contextURL, contextLine, state);
@@ -1773,10 +1773,15 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
RefPtr<JSONObject> reportObject = JSONObject::create();
reportObject->setObject("csp-report", cspReport.release());
+ if (!shouldSendViolationReport(reportObject))
+ return;
Tom Sepez 2013/08/02 18:03:22 Maybe count number of times we are suppressed here
Mike West 2013/08/05 08:21:29 I think I'd be annoyed. :) What do you think abou
+
RefPtr<FormData> report = FormData::create(reportObject->toJSONString().utf8());
abarth-chromium 2013/08/02 18:04:28 Rather than calling toJSONString() three times (on
Mike West 2013/08/05 08:21:29 Done.
for (size_t i = 0; i < reportURIs.size(); ++i)
PingLoader::sendViolationReport(frame, reportURIs[i], report, PingLoader::ContentSecurityPolicyViolationReport);
+
+ didSendViolationReport(reportObject);
Tom Sepez 2013/08/02 18:03:22 Seems like a shame to have to hash the same string
Mike West 2013/08/05 08:21:29 Done.
}
void ContentSecurityPolicy::reportUnsupportedDirective(const String& name) const
@@ -1892,4 +1897,14 @@ bool ContentSecurityPolicy::shouldBypassMainWorld(ScriptExecutionContext* contex
return false;
}
+bool ContentSecurityPolicy::shouldSendViolationReport(PassRefPtr<JSONObject> report) const
Tom Sepez 2013/08/02 18:11:40 Maybe add a comment that we don't care about colli
Mike West 2013/08/05 08:21:29 Done.
+{
+ return !m_violationReportsSent.contains(report->toJSONString().impl()->hash());
+}
+
+void ContentSecurityPolicy::didSendViolationReport(PassRefPtr<JSONObject> report)
+{
+ m_violationReportsSent.add(report->toJSONString().impl()->hash());
}
+
+} // namespace WebCore
« Source/core/page/ContentSecurityPolicy.h ('K') | « Source/core/page/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698