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

Unified Diff: third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp

Issue 2536713002: Part 3.3: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: Rebasing on master (that includes part3.2 changes) Created 4 years 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: third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp b/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
index 223967d5bc2ee35e167789bfed7d86c1825245a3..2f85ce3ebce121fe8463280416738918d98fe997 100644
--- a/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
@@ -579,6 +579,19 @@ bool SourceListDirective::hasSourceMatchInList(
return false;
}
+bool SourceListDirective::allowAllInline() {
+ const ContentSecurityPolicy::DirectiveType& type =
+ ContentSecurityPolicy::getDirectiveType(m_directiveName);
+ if (type != ContentSecurityPolicy::DirectiveType::DefaultSrc &&
+ type != ContentSecurityPolicy::DirectiveType::StyleSrc &&
+ type != ContentSecurityPolicy::DirectiveType::ScriptSrc) {
+ return false;
+ }
+ return m_allowInline && !isHashOrNoncePresent() &&
+ (type != ContentSecurityPolicy::DirectiveType::ScriptSrc ||
+ !m_allowDynamic);
+}
+
bool SourceListDirective::subsumes(
HeapVector<Member<SourceListDirective>> other) {
// TODO(amalika): Handle here special keywords.
@@ -592,8 +605,27 @@ bool SourceListDirective::subsumes(
HeapVector<Member<CSPSource>> normalizedB = other[0]->m_list;
if (other[0]->m_allowSelf && other[0]->m_policy->getSelfSource())
normalizedB.append(other[0]->m_policy->getSelfSource());
- for (size_t i = 1; i < other.size(); i++)
+
+ bool allowInlineOther = other[0]->m_allowInline;
+ bool allowDynamicOther = other[0]->m_allowDynamic;
+ bool isHashOrNoncePresentOther = other[0]->isHashOrNoncePresent();
+
+ for (size_t i = 1; i < other.size(); i++) {
+ allowInlineOther = allowInlineOther && other[i]->m_allowInline;
+ allowDynamicOther = allowDynamicOther && other[i]->m_allowDynamic;
+ isHashOrNoncePresentOther =
+ isHashOrNoncePresentOther && other[i]->isHashOrNoncePresent();
normalizedB = other[i]->getIntersectCSPSources(normalizedB);
+ }
+
+ const ContentSecurityPolicy::DirectiveType type =
+ ContentSecurityPolicy::getDirectiveType(m_directiveName);
+ bool allowAllInlineOther =
+ allowInlineOther && !isHashOrNoncePresentOther &&
+ (type != ContentSecurityPolicy::DirectiveType::ScriptSrc ||
+ !allowDynamicOther);
+ if (!allowAllInline() && allowAllInlineOther)
+ return false;
return CSPSource::firstSubsumesSecond(normalizedA, normalizedB);
}

Powered by Google App Engine
This is Rietveld 408576698