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

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: Using allowAllInline() Created 4 years, 1 month 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 06f2e17e0903170f6234295edb44f5de445e0172..79cbfa20062664e1c59f98a8965f8009ef47324e 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 &&
amalika 2016/11/29 09:42:29 Added default-src since otherwise unspecified scri
+ 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)
normalizedB.append(other[0]->m_policy->getSelfSource());
- for (size_t i = 1; i < other.size(); i++)
+
+ bool allowInlineOther = other[0]->m_allowInline;
Mike West 2016/11/29 12:00:50 Why do you need these three variables? Don't they
amalika 2016/11/29 12:27:33 To call `allowAllInline()` is a method on SourceLi
Mike West 2016/11/30 09:57:19 Hrm. Ok. But you only need them to check `allowAll
amalika 2016/11/30 10:06:06 I dont think this would give an expected behavior
+ 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