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

Side by Side Diff: Source/core/frame/csp/ContentSecurityPolicy.cpp

Issue 561693002: CSP: Resolve report endpoints at reporting time, not at parse time. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/csp/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 const ScriptCallFrame& callFrame = stack->at(0); 612 const ScriptCallFrame& callFrame = stack->at(0);
613 613
614 if (callFrame.lineNumber()) { 614 if (callFrame.lineNumber()) {
615 KURL source = KURL(ParsedURLString, callFrame.sourceURL()); 615 KURL source = KURL(ParsedURLString, callFrame.sourceURL());
616 init.sourceFile = stripURLForUseInReport(document, source); 616 init.sourceFile = stripURLForUseInReport(document, source);
617 init.lineNumber = callFrame.lineNumber(); 617 init.lineNumber = callFrame.lineNumber();
618 init.columnNumber = callFrame.columnNumber(); 618 init.columnNumber = callFrame.columnNumber();
619 } 619 }
620 } 620 }
621 621
622 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header) 622 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<String>& reportEndpoints, const String& header)
623 { 623 {
624 // FIXME: Support sending reports from worker. 624 // FIXME: Support sending reports from worker.
625 Document* document = this->document(); 625 Document* document = this->document();
626 if (!document) 626 if (!document)
627 return; 627 return;
628 628
629 LocalFrame* frame = document->frame(); 629 LocalFrame* frame = document->frame();
630 if (!frame) 630 if (!frame)
631 return; 631 return;
632 632
633 SecurityPolicyViolationEventInit violationData; 633 SecurityPolicyViolationEventInit violationData;
634 gatherSecurityPolicyViolationEventData(violationData, document, directiveTex t, effectiveDirective, blockedURL, header); 634 gatherSecurityPolicyViolationEventData(violationData, document, directiveTex t, effectiveDirective, blockedURL, header);
635 635
636 if (experimentalFeaturesEnabled()) 636 if (experimentalFeaturesEnabled())
637 frame->domWindow()->enqueueDocumentEvent(SecurityPolicyViolationEvent::c reate(EventTypeNames::securitypolicyviolation, violationData)); 637 frame->domWindow()->enqueueDocumentEvent(SecurityPolicyViolationEvent::c reate(EventTypeNames::securitypolicyviolation, violationData));
638 638
639 if (reportURIs.isEmpty()) 639 if (reportEndpoints.isEmpty())
640 return; 640 return;
641 641
642 // We need to be careful here when deciding what information to send to the 642 // We need to be careful here when deciding what information to send to the
643 // report-uri. Currently, we send only the current document's URL and the 643 // report-uri. Currently, we send only the current document's URL and the
644 // directive that was violated. The document's URL is safe to send because 644 // directive that was violated. The document's URL is safe to send because
645 // it's the document itself that's requesting that it be sent. You could 645 // it's the document itself that's requesting that it be sent. You could
646 // make an argument that we shouldn't send HTTPS document URLs to HTTP 646 // make an argument that we shouldn't send HTTPS document URLs to HTTP
647 // report-uris (for the same reasons that we supress the Referer in that 647 // report-uris (for the same reasons that we supress the Referer in that
648 // case), but the Referer is sent implicitly whereas this request is only 648 // case), but the Referer is sent implicitly whereas this request is only
649 // sent explicitly. As for which directive was violated, that's pretty 649 // sent explicitly. As for which directive was violated, that's pretty
(...skipping 16 matching lines...) Expand all
666 666
667 RefPtr<JSONObject> reportObject = JSONObject::create(); 667 RefPtr<JSONObject> reportObject = JSONObject::create();
668 reportObject->setObject("csp-report", cspReport.release()); 668 reportObject->setObject("csp-report", cspReport.release());
669 String stringifiedReport = reportObject->toJSONString(); 669 String stringifiedReport = reportObject->toJSONString();
670 670
671 if (!shouldSendViolationReport(stringifiedReport)) 671 if (!shouldSendViolationReport(stringifiedReport))
672 return; 672 return;
673 673
674 RefPtr<FormData> report = FormData::create(stringifiedReport.utf8()); 674 RefPtr<FormData> report = FormData::create(stringifiedReport.utf8());
675 675
676 for (size_t i = 0; i < reportURIs.size(); ++i) 676 for (size_t i = 0; i < reportEndpoints.size(); ++i)
677 PingLoader::sendViolationReport(frame, reportURIs[i], report, PingLoader ::ContentSecurityPolicyViolationReport); 677 PingLoader::sendViolationReport(frame, completeURL(reportEndpoints[i]), report, PingLoader::ContentSecurityPolicyViolationReport);
678 678
679 didSendViolationReport(stringifiedReport); 679 didSendViolationReport(stringifiedReport);
680 } 680 }
681 681
682 void ContentSecurityPolicy::reportInvalidReferrer(const String& invalidValue) 682 void ContentSecurityPolicy::reportInvalidReferrer(const String& invalidValue)
683 { 683 {
684 logToConsole("The 'referrer' Content Security Policy directive has the inval id value \"" + invalidValue + "\". Valid values are \"always\", \"default\", \"n ever\", and \"origin\"."); 684 logToConsole("The 'referrer' Content Security Policy directive has the inval id value \"" + invalidValue + "\". Valid values are \"always\", \"default\", \"n ever\", and \"origin\".");
685 } 685 }
686 686
687 void ContentSecurityPolicy::reportReportOnlyInMeta(const String& header) 687 void ContentSecurityPolicy::reportReportOnlyInMeta(const String& header)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 837 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
838 return !m_violationReportsSent.contains(report.impl()->hash()); 838 return !m_violationReportsSent.contains(report.impl()->hash());
839 } 839 }
840 840
841 void ContentSecurityPolicy::didSendViolationReport(const String& report) 841 void ContentSecurityPolicy::didSendViolationReport(const String& report)
842 { 842 {
843 m_violationReportsSent.add(report.impl()->hash()); 843 m_violationReportsSent.add(report.impl()->hash());
844 } 844 }
845 845
846 } // namespace blink 846 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/csp/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698