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

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 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..c5298fc773a3fcf8252e943827f33b6efab37c0e 100644
--- a/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp
@@ -579,6 +579,18 @@ bool SourceListDirective::hasSourceMatchInList(
return false;
}
+bool SourceListDirective::allowAllInline() {
+ const ContentSecurityPolicy::DirectiveType& type =
+ ContentSecurityPolicy::getDirectiveType(m_directiveName);
+ if (type != ContentSecurityPolicy::DirectiveType::StyleSrc &&
+ type != ContentSecurityPolicy::DirectiveType::ScriptSrc) {
+ return false;
+ }
+ return m_allowInline && !isHashOrNoncePresent() &&
Mike West 2016/11/28 15:38:16 Can we use this when responding to `allowInline()`
amalika 2016/11/29 09:42:29 Made changes to call allowAllInline with comments
+ (type != ContentSecurityPolicy::DirectiveType::ScriptSrc ||
+ !m_allowDynamic);
+}
+
bool SourceListDirective::subsumes(
HeapVector<Member<SourceListDirective>> other) {
// TODO(amalika): Handle here special keywords.
@@ -592,8 +604,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;
+ 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