Chromium Code Reviews

Side by Side 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, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google, Inc. All rights reserved. 2 * Copyright (C) 2011 Google, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1705 matching lines...)
1716 const ScriptCallFrame& callFrame = stack->at(0); 1716 const ScriptCallFrame& callFrame = stack->at(0);
1717 1717
1718 if (callFrame.lineNumber()) { 1718 if (callFrame.lineNumber()) {
1719 KURL source = KURL(ParsedURLString, callFrame.sourceURL()); 1719 KURL source = KURL(ParsedURLString, callFrame.sourceURL());
1720 init.sourceFile = stripURLForUseInReport(document, source); 1720 init.sourceFile = stripURLForUseInReport(document, source);
1721 init.lineNumber = callFrame.lineNumber(); 1721 init.lineNumber = callFrame.lineNumber();
1722 init.columnNumber = callFrame.columnNumber(); 1722 init.columnNumber = callFrame.columnNumber();
1723 } 1723 }
1724 } 1724 }
1725 1725
1726 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL, const WTF::OrdinalNumber& contextLine, ScriptState* state) const 1726 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header, const String& contextURL, const WTF::OrdinalNumber& contextLine, ScriptState* state)
1727 { 1727 {
1728 logToConsole(consoleMessage, contextURL, contextLine, state); 1728 logToConsole(consoleMessage, contextURL, contextLine, state);
1729 1729
1730 // FIXME: Support sending reports from worker. 1730 // FIXME: Support sending reports from worker.
1731 if (!m_scriptExecutionContext->isDocument()) 1731 if (!m_scriptExecutionContext->isDocument())
1732 return; 1732 return;
1733 1733
1734 Document* document = toDocument(m_scriptExecutionContext); 1734 Document* document = toDocument(m_scriptExecutionContext);
1735 Frame* frame = document->frame(); 1735 Frame* frame = document->frame();
1736 if (!frame) 1736 if (!frame)
(...skipping 29 matching lines...)
1766 if (!violationData.sourceFile.isEmpty() && violationData.lineNumber) { 1766 if (!violationData.sourceFile.isEmpty() && violationData.lineNumber) {
1767 cspReport->setString("source-file", violationData.sourceFile); 1767 cspReport->setString("source-file", violationData.sourceFile);
1768 cspReport->setNumber("line-number", violationData.lineNumber); 1768 cspReport->setNumber("line-number", violationData.lineNumber);
1769 cspReport->setNumber("column-number", violationData.columnNumber); 1769 cspReport->setNumber("column-number", violationData.columnNumber);
1770 } 1770 }
1771 cspReport->setNumber("status-code", violationData.statusCode); 1771 cspReport->setNumber("status-code", violationData.statusCode);
1772 1772
1773 RefPtr<JSONObject> reportObject = JSONObject::create(); 1773 RefPtr<JSONObject> reportObject = JSONObject::create();
1774 reportObject->setObject("csp-report", cspReport.release()); 1774 reportObject->setObject("csp-report", cspReport.release());
1775 1775
1776 if (!shouldSendViolationReport(reportObject))
1777 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
1778
1776 RefPtr<FormData> report = FormData::create(reportObject->toJSONString().utf8 ()); 1779 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.
1777 1780
1778 for (size_t i = 0; i < reportURIs.size(); ++i) 1781 for (size_t i = 0; i < reportURIs.size(); ++i)
1779 PingLoader::sendViolationReport(frame, reportURIs[i], report, PingLoader ::ContentSecurityPolicyViolationReport); 1782 PingLoader::sendViolationReport(frame, reportURIs[i], report, PingLoader ::ContentSecurityPolicyViolationReport);
1783
1784 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.
1780 } 1785 }
1781 1786
1782 void ContentSecurityPolicy::reportUnsupportedDirective(const String& name) const 1787 void ContentSecurityPolicy::reportUnsupportedDirective(const String& name) const
1783 { 1788 {
1784 DEFINE_STATIC_LOCAL(String, allow, (ASCIILiteral("allow"))); 1789 DEFINE_STATIC_LOCAL(String, allow, (ASCIILiteral("allow")));
1785 DEFINE_STATIC_LOCAL(String, options, (ASCIILiteral("options"))); 1790 DEFINE_STATIC_LOCAL(String, options, (ASCIILiteral("options")));
1786 DEFINE_STATIC_LOCAL(String, policyURI, (ASCIILiteral("policy-uri"))); 1791 DEFINE_STATIC_LOCAL(String, policyURI, (ASCIILiteral("policy-uri")));
1787 DEFINE_STATIC_LOCAL(String, allowMessage, (ASCIILiteral("The 'allow' directi ve has been replaced with 'default-src'. Please use that directive instead, as ' allow' has no effect."))); 1792 DEFINE_STATIC_LOCAL(String, allowMessage, (ASCIILiteral("The 'allow' directi ve has been replaced with 'default-src'. Please use that directive instead, as ' allow' has no effect.")));
1788 DEFINE_STATIC_LOCAL(String, optionsMessage, (ASCIILiteral("The 'options' dir ective has been replaced with 'unsafe-inline' and 'unsafe-eval' source expressio ns for the 'script-src' and 'style-src' directives. Please use those directives instead, as 'options' has no effect."))); 1793 DEFINE_STATIC_LOCAL(String, optionsMessage, (ASCIILiteral("The 'options' dir ective has been replaced with 'unsafe-inline' and 'unsafe-eval' source expressio ns for the 'script-src' and 'style-src' directives. Please use those directives instead, as 'options' has no effect.")));
1789 DEFINE_STATIC_LOCAL(String, policyURIMessage, (ASCIILiteral("The 'policy-uri ' directive has been removed from the specification. Please specify a complete p olicy via the Content-Security-Policy header."))); 1794 DEFINE_STATIC_LOCAL(String, policyURIMessage, (ASCIILiteral("The 'policy-uri ' directive has been removed from the specification. Please specify a complete p olicy via the Content-Security-Policy header.")));
(...skipping 95 matching lines...)
1885 bool ContentSecurityPolicy::shouldBypassMainWorld(ScriptExecutionContext* contex t) 1890 bool ContentSecurityPolicy::shouldBypassMainWorld(ScriptExecutionContext* contex t)
1886 { 1891 {
1887 if (context && context->isDocument()) { 1892 if (context && context->isDocument()) {
1888 Document* document = toDocument(context); 1893 Document* document = toDocument(context);
1889 if (document->frame()) 1894 if (document->frame())
1890 return document->frame()->script()->shouldBypassMainWorldContentSecu rityPolicy(); 1895 return document->frame()->script()->shouldBypassMainWorldContentSecu rityPolicy();
1891 } 1896 }
1892 return false; 1897 return false;
1893 } 1898 }
1894 1899
1900 bool ContentSecurityPolicy::shouldSendViolationReport(PassRefPtr<JSONObject> rep ort) 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.
1901 {
1902 return !m_violationReportsSent.contains(report->toJSONString().impl()->hash( ));
1895 } 1903 }
1904
1905 void ContentSecurityPolicy::didSendViolationReport(PassRefPtr<JSONObject> report )
1906 {
1907 m_violationReportsSent.add(report->toJSONString().impl()->hash());
1908 }
1909
1910 } // namespace WebCore
OLDNEW
« 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