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

Side by Side Diff: Source/core/frame/csp/CSPDirectiveList.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/CSPDirectiveList.h ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/frame/csp/CSPDirectiveList.h" 6 #include "core/frame/csp/CSPDirectiveList.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
(...skipping 19 matching lines...) Expand all
30 PassOwnPtr<CSPDirectiveList> CSPDirectiveList::create(ContentSecurityPolicy* pol icy, const UChar* begin, const UChar* end, ContentSecurityPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) 30 PassOwnPtr<CSPDirectiveList> CSPDirectiveList::create(ContentSecurityPolicy* pol icy, const UChar* begin, const UChar* end, ContentSecurityPolicyHeaderType type, ContentSecurityPolicyHeaderSource source)
31 { 31 {
32 OwnPtr<CSPDirectiveList> directives = adoptPtr(new CSPDirectiveList(policy, type, source)); 32 OwnPtr<CSPDirectiveList> directives = adoptPtr(new CSPDirectiveList(policy, type, source));
33 directives->parse(begin, end); 33 directives->parse(begin, end);
34 34
35 if (!directives->checkEval(directives->operativeDirective(directives->m_scri ptSrc.get()))) { 35 if (!directives->checkEval(directives->operativeDirective(directives->m_scri ptSrc.get()))) {
36 String message = "Refused to evaluate a string as JavaScript because 'un safe-eval' is not an allowed source of script in the following Content Security Policy directive: \"" + directives->operativeDirective(directives->m_scriptSrc.g et())->text() + "\".\n"; 36 String message = "Refused to evaluate a string as JavaScript because 'un safe-eval' is not an allowed source of script in the following Content Security Policy directive: \"" + directives->operativeDirective(directives->m_scriptSrc.g et())->text() + "\".\n";
37 directives->setEvalDisabledErrorMessage(message); 37 directives->setEvalDisabledErrorMessage(message);
38 } 38 }
39 39
40 if (directives->isReportOnly() && directives->reportURIs().isEmpty()) 40 if (directives->isReportOnly() && directives->reportEndpoints().isEmpty())
41 policy->reportMissingReportURI(String(begin, end - begin)); 41 policy->reportMissingReportURI(String(begin, end - begin));
42 42
43 return directives.release(); 43 return directives.release();
44 } 44 }
45 45
46 void CSPDirectiveList::reportViolation(const String& directiveText, const String & effectiveDirective, const String& consoleMessage, const KURL& blockedURL) cons t 46 void CSPDirectiveList::reportViolation(const String& directiveText, const String & effectiveDirective, const String& consoleMessage, const KURL& blockedURL) cons t
47 { 47 {
48 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM essage; 48 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM essage;
49 m_policy->logToConsole(ConsoleMessage::create(SecurityMessageSource, ErrorMe ssageLevel, message)); 49 m_policy->logToConsole(ConsoleMessage::create(SecurityMessageSource, ErrorMe ssageLevel, message));
50 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportURIs, m_header); 50 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportEndpoints, m_header);
51 } 51 }
52 52
53 void CSPDirectiveList::reportViolationWithLocation(const String& directiveText, const String& effectiveDirective, const String& consoleMessage, const KURL& bloc kedURL, const String& contextURL, const WTF::OrdinalNumber& contextLine) const 53 void CSPDirectiveList::reportViolationWithLocation(const String& directiveText, const String& effectiveDirective, const String& consoleMessage, const KURL& bloc kedURL, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
54 { 54 {
55 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM essage; 55 String message = m_reportOnly ? "[Report Only] " + consoleMessage : consoleM essage;
56 m_policy->logToConsole(ConsoleMessage::create(SecurityMessageSource, ErrorMe ssageLevel, message, contextURL, contextLine.oneBasedInt())); 56 m_policy->logToConsole(ConsoleMessage::create(SecurityMessageSource, ErrorMe ssageLevel, message, contextURL, contextLine.oneBasedInt()));
57 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportURIs, m_header); 57 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportEndpoints, m_header);
58 } 58 }
59 59
60 void CSPDirectiveList::reportViolationWithState(const String& directiveText, con st String& effectiveDirective, const String& message, const KURL& blockedURL, Sc riptState* scriptState) const 60 void CSPDirectiveList::reportViolationWithState(const String& directiveText, con st String& effectiveDirective, const String& message, const KURL& blockedURL, Sc riptState* scriptState) const
61 { 61 {
62 String reportMessage = m_reportOnly ? "[Report Only] " + message : message; 62 String reportMessage = m_reportOnly ? "[Report Only] " + message : message;
63 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(S ecurityMessageSource, ErrorMessageLevel, reportMessage); 63 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(S ecurityMessageSource, ErrorMessageLevel, reportMessage);
64 consoleMessage->setScriptState(scriptState); 64 consoleMessage->setScriptState(scriptState);
65 m_policy->logToConsole(consoleMessage.release()); 65 m_policy->logToConsole(consoleMessage.release());
66 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportURIs, m_header); 66 m_policy->reportViolation(directiveText, effectiveDirective, message, blocke dURL, m_reportEndpoints, m_header);
67 } 67 }
68 68
69 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const 69 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const
70 { 70 {
71 return !directive || directive->allowEval(); 71 return !directive || directive->allowEval();
72 } 72 }
73 73
74 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const 74 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const
75 { 75 {
76 return !directive || (directive->allowInline() && !directive->isHashOrNonceP resent()); 76 return !directive || (directive->allowInline() && !directive->isHashOrNonceP resent());
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // The directive-value may be empty. 469 // The directive-value may be empty.
470 if (valueBegin == position) 470 if (valueBegin == position)
471 return true; 471 return true;
472 472
473 value = String(valueBegin, position - valueBegin); 473 value = String(valueBegin, position - valueBegin);
474 return true; 474 return true;
475 } 475 }
476 476
477 void CSPDirectiveList::parseReportURI(const String& name, const String& value) 477 void CSPDirectiveList::parseReportURI(const String& name, const String& value)
478 { 478 {
479 if (!m_reportURIs.isEmpty()) { 479 if (!m_reportEndpoints.isEmpty()) {
480 m_policy->reportDuplicateDirective(name); 480 m_policy->reportDuplicateDirective(name);
481 return; 481 return;
482 } 482 }
483 483
484 Vector<UChar> characters; 484 Vector<UChar> characters;
485 value.appendTo(characters); 485 value.appendTo(characters);
486 486
487 const UChar* position = characters.data(); 487 const UChar* position = characters.data();
488 const UChar* end = position + characters.size(); 488 const UChar* end = position + characters.size();
489 489
490 while (position < end) { 490 while (position < end) {
491 skipWhile<UChar, isASCIISpace>(position, end); 491 skipWhile<UChar, isASCIISpace>(position, end);
492 492
493 const UChar* urlBegin = position; 493 const UChar* urlBegin = position;
494 skipWhile<UChar, isNotASCIISpace>(position, end); 494 skipWhile<UChar, isNotASCIISpace>(position, end);
495 495
496 if (urlBegin < position) { 496 if (urlBegin < position) {
497 String url = String(urlBegin, position - urlBegin); 497 String url = String(urlBegin, position - urlBegin);
498 m_reportURIs.append(m_policy->completeURL(url)); 498 m_reportEndpoints.append(url);
499 } 499 }
500 } 500 }
501 } 501 }
502 502
503 503
504 template<class CSPDirectiveType> 504 template<class CSPDirectiveType>
505 void CSPDirectiveList::setCSPDirective(const String& name, const String& value, OwnPtr<CSPDirectiveType>& directive) 505 void CSPDirectiveList::setCSPDirective(const String& name, const String& value, OwnPtr<CSPDirectiveType>& directive)
506 { 506 {
507 if (directive) { 507 if (directive) {
508 m_policy->reportDuplicateDirective(name); 508 m_policy->reportDuplicateDirective(name);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 parseReferrer(name, value); 674 parseReferrer(name, value);
675 else 675 else
676 m_policy->reportUnsupportedDirective(name); 676 m_policy->reportUnsupportedDirective(name);
677 } else { 677 } else {
678 m_policy->reportUnsupportedDirective(name); 678 m_policy->reportUnsupportedDirective(name);
679 } 679 }
680 } 680 }
681 681
682 682
683 } // namespace blink 683 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/csp/CSPDirectiveList.h ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698