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

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: tests. Created 7 years, 4 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
« no previous file with comments | « Source/core/page/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/ContentSecurityPolicy.cpp
diff --git a/Source/core/page/ContentSecurityPolicy.cpp b/Source/core/page/ContentSecurityPolicy.cpp
index 941543170e464d2178bc842d0cb8a653fadd9452..a5892ddb12acf7e51b1437c6538f39e46b3b13b8 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);
@@ -1772,11 +1772,17 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
RefPtr<JSONObject> reportObject = JSONObject::create();
reportObject->setObject("csp-report", cspReport.release());
+ String stringifiedReport = reportObject->toJSONString();
- RefPtr<FormData> report = FormData::create(reportObject->toJSONString().utf8());
+ if (!shouldSendViolationReport(stringifiedReport))
+ return;
+
+ RefPtr<FormData> report = FormData::create(stringifiedReport.utf8());
for (size_t i = 0; i < reportURIs.size(); ++i)
PingLoader::sendViolationReport(frame, reportURIs[i], report, PingLoader::ContentSecurityPolicyViolationReport);
+
+ didSendViolationReport(stringifiedReport);
}
void ContentSecurityPolicy::reportUnsupportedDirective(const String& name) const
@@ -1892,4 +1898,15 @@ bool ContentSecurityPolicy::shouldBypassMainWorld(ScriptExecutionContext* contex
return false;
}
+bool ContentSecurityPolicy::shouldSendViolationReport(const String& report) const
+{
+ // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
+ return !m_violationReportsSent.contains(report.impl()->hash());
+}
+
+void ContentSecurityPolicy::didSendViolationReport(const String& report)
+{
+ m_violationReportsSent.add(report.impl()->hash());
}
+
+} // namespace WebCore
« no previous file with comments | « Source/core/page/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698