Source/WebCore/ChangeLog

 12012-08-07 Mike West <mkwst@chromium.org>
 2
 3 Implement the plugin-types Content Security Policy directive.
 4 https://bugs.webkit.org/show_bug.cgi?id=91919
 5
 6 Reviewed by Adam Barth.
 7
 8 The CSP 1.1 editor's draft defines the 'plugin-types' directive as a
 9 mechanism for whitelisting only specific types of plugin content on a
 10 page. A protected resource might trust only Flash content, for instance,
 11 and could enforce that preference via a Content Security Policy of
 12 'plugin-types application/x-shockwave-flash'. Flash would load, no other
 13 plugin type would.
 14
 15 Specification details available at: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#plugin-types--experimental
 16
 17 This experimental directive is gated on the ENABLE_CSP_NEXT flag, which
 18 is currently only enabled in Chromium.
 19
 20 Tests: http/tests/security/contentSecurityPolicy/1.1/plugintypes-invalid.html
 21 http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-data.html
 22 http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-url.html
 23 http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-data.html
 24 http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-url.html
 25 http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-allowed.html
 26 http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-blocked.html
 27 http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-01.html
 28 http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-02.html
 29
 30 * loader/SubframeLoader.cpp:
 31 (WebCore::SubframeLoader::pluginIsLoadable):
 32 Adding a check against 'allowPluginType', and passing in both the
 33 MIME type of the plugin, as well as the declared MIME type from the
 34 object/embed element (ensuring that we do this correctly, even if
 35 we're inside a PluginDocument).
 36 (WebCore::SubframeLoader::createJavaAppletWidget):
 37 Same as 'pluginIsLoadable', but hard-coded to
 38 'application/x-java-applet'.
 39 * page/ContentSecurityPolicy.cpp:
 40 (CSPDirectiveList):
 41 (WebCore::CSPDirectiveList::logInvalidPluginTypes):
 42 Plugin types that don't match the grammar ('not/a/mime/type') are
 43 logged to the console, and ignored for purposes of matching.
 44 (WebCore):
 45 (WebCore::CSPDirectiveList::checkPluginType):
 46 Given both the plugin type and the declared type attribute, returns
 47 true if both types match, and are contained in the list of accepted
 48 plugin types.
 49 (WebCore::CSPDirectiveList::checkPluginTypeAndReportViolation):
 50 Calls out to checkPluginType, and reports a violation if that check
 51 fails.
 52 (WebCore::CSPDirectiveList::allowPluginType):
 53 Analog to the other 'CSPDirectiveList::allowXXX' methods, this
 54 branches between simply checking the type against the policy, and
 55 checking against the policy and then reporting violations.
 56 (WebCore::CSPDirectiveList::parsePluginTypes):
 57 Given a directive value, parse out the media types contained within
 58 by splitting on spaces, and validating each token. Valid tokens are
 59 added to 'm_pluginTypes' for use in 'checkPluginType'.
 60 (WebCore::CSPDirectiveList::addDirective):
 61 Wire up 'plugin-types' as a valid directive (if the ENABLE_CSP_NEXT
 62 flag is set). This has been combined with the other implemented 1.1
 63 header, 'script-nonce'.
 64 (WebCore::ContentSecurityPolicy::allowPluginType):
 65 The public interface to this set of functionality.
 66 * page/ContentSecurityPolicy.h:
 67
1682012-08-07 Marcelo Lira <marcelo.lira@openbossa.org>
269
370 [Qt] Add support for the Gamepad API

Source/WebCore/loader/SubframeLoader.cpp

@@bool SubframeLoader::pluginIsLoadable(HTMLPlugInImageElement* pluginElement, con
126126 return false;
127127 }
128128
129  if (!document()->contentSecurityPolicy()->allowObjectFromSource(url)) {
 129 String declaredMimeType = document()->isPluginDocument() ?
 130 document()->ownerElement()->fastGetAttribute(HTMLNames::typeAttr) :
 131 pluginElement->fastGetAttribute(HTMLNames::typeAttr);
 132 if (!document()->contentSecurityPolicy()->allowObjectFromSource(url)
 133 || !document()->contentSecurityPolicy()->allowPluginType(mimeType, declaredMimeType, url)) {
130134 RenderEmbeddedObject* renderer = pluginElement->renderEmbeddedObject();
131135 renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy);
132136 return false;

@@PassRefPtr<Widget> SubframeLoader::createJavaAppletWidget(const IntSize& size, H
293297 return 0;
294298 }
295299
296  if (!element->document()->contentSecurityPolicy()->allowObjectFromSource(codeBaseURL))
 300 const char javaAppletMimeType[] = "application/x-java-applet";
 301 if (!element->document()->contentSecurityPolicy()->allowObjectFromSource(codeBaseURL)
 302 || !element->document()->contentSecurityPolicy()->allowPluginType(javaAppletMimeType, javaAppletMimeType, codeBaseURL))
297303 return 0;
298304 }
299305

Source/WebCore/page/ContentSecurityPolicy.cpp

4040#include "ScriptCallStack.h"
4141#include "SecurityOrigin.h"
4242#include "TextEncoding.h"
 43#include <wtf/HashSet.h>
4344#include <wtf/text/TextPosition.h>
4445#include <wtf/text/WTFString.h>
4546

@@bool isNotColonOrSlash(UChar c)
8586 return c != ':' && c != '/';
8687}
8788
 89bool isMediaTypeCharacter(UChar c)
 90{
 91 return !isASCIISpace(c) && c != '/';
 92}
 93
8894} // namespace
8995
9096static bool skipExactly(const UChar*& position, const UChar* end, UChar delimiter)

@@public:
553559 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
554560 bool allowEval(PassRefPtr<ScriptCallStack>, ContentSecurityPolicy::ReportingStatus) const;
555561 bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL&) const;
 562 bool allowPluginType(const String& type, const String& typeAttribute, const KURL&, ContentSecurityPolicy::ReportingStatus) const;
556563
557564 bool allowScriptFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
558565 bool allowObjectFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;

@@private:
573580 bool parseDirective(const UChar* begin, const UChar* end, String& name, String& value);
574581 void parseReportURI(const String& name, const String& value);
575582 void parseScriptNonce(const String& name, const String& value);
 583 void parsePluginTypes(const String& name, const String& value);
576584 void addDirective(const String& name, const String& value);
577585 void applySandboxPolicy(const String& name, const String& sandboxPolicy);
578586

@@private:
583591 void logUnrecognizedDirective(const String& name) const;
584592 void logDuplicateDirective(const String& name) const;
585593 void logInvalidNonce(const String& nonce) const;
 594 void logInvalidPluginTypes(const String& directiveText) const;
586595
587596 bool checkEval(CSPDirective*) const;
588597 bool checkInline(CSPDirective*) const;
589598 bool checkNonce(const String&) const;
590599 bool checkSource(CSPDirective*, const KURL&) const;
 600 bool checkPluginType(const String& type, const String& typeAttribute) const;
591601
592602 bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
593603 bool checkInlineAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
594604 bool checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
595605 bool checkSourceAndReportViolation(CSPDirective*, const KURL&, const String& type) const;
 606 bool checkPluginTypeAndReportViolation(const String& type, const String& typeAttribute, const String& consoleMessage) const;
596607
597608 bool denyIfEnforcingPolicy() const { return m_reportOnly; }
598609

@@private:
613624 OwnPtr<CSPDirective> m_connectSrc;
614625
615626 Vector<KURL> m_reportURIs;
 627 HashSet<String> m_pluginTypes;
 628 String m_pluginTypesDirective;
616629 String m_scriptNonce;
617630};
618631

@@void CSPDirectiveList::logInvalidNonce(const String& nonce) const
709722 m_scriptExecutionContext->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message);
710723}
711724
 725void CSPDirectiveList::logInvalidPluginTypes(const String& pluginType) const
 726{
 727 String message;
 728 if (pluginType.isNull())
 729 message = "'plugin-types' Content Security Policy directive is empty; all plugins will be blocked.\n";
 730 else
 731 message = makeString("Invalid plugin type in 'plugin-types' Content Security Policy directive: '", pluginType, "'.\n");
 732 m_scriptExecutionContext->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message);
 733}
 734
712735bool CSPDirectiveList::checkEval(CSPDirective* directive) const
713736{
714737 return !directive || directive->allowEval();

@@bool CSPDirectiveList::checkSource(CSPDirective* directive, const KURL& url) con
731754 return !directive || directive->allows(url);
732755}
733756
 757bool CSPDirectiveList::checkPluginType(const String& type, const String& typeAttribute) const
 758{
 759 if (m_pluginTypesDirective.isNull())
 760 return true;
 761 if (typeAttribute.isEmpty() || typeAttribute.stripWhiteSpace() != type)
 762 return false;
 763 return m_pluginTypes.contains(type);
 764}
 765
734766CSPDirective* CSPDirectiveList::operativeDirective(CSPDirective* directive) const
735767{
736768 return directive ? directive : m_defaultSrc.get();

@@bool CSPDirectiveList::checkNonceAndReportViolation(const String& nonce, const S
752784 return denyIfEnforcingPolicy();
753785}
754786
 787bool CSPDirectiveList::checkPluginTypeAndReportViolation(const String& type, const String& typeAttribute, const String& consoleMessage) const
 788{
 789 if (checkPluginType(type, typeAttribute))
 790 return true;
 791
 792 reportViolation(m_pluginTypesDirective, consoleMessage + "'plugin-types " + m_pluginTypesDirective + "'.\n", KURL());
 793 return denyIfEnforcingPolicy();
 794}
 795
755796bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
756797{
757798 if (checkInline(directive))

@@bool CSPDirectiveList::allowScriptNonce(const String& nonce, const String& conte
825866 return checkNonceAndReportViolation(nonce, "Refused to load '" + url.string() + "' because it violates the following Content Security Policy directive: ", contextURL, contextLine);
826867}
827868
 869bool CSPDirectiveList::allowPluginType(const String& type, const String& typeAttribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
 870{
 871 return reportingStatus == ContentSecurityPolicy::SendReport ?
 872 checkPluginTypeAndReportViolation(type, typeAttribute, "Refused to load '" + url.string() + "' (MIME type '" + typeAttribute + "') because it violates the following Content Security Policy Directive: ") :
 873 checkPluginType(type, typeAttribute);
 874}
 875
828876bool CSPDirectiveList::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
829877{
830878 DEFINE_STATIC_LOCAL(String, type, ("script"));

@@void CSPDirectiveList::parseScriptNonce(const String& name, const String& value)
10251073 m_scriptNonce = nonce;
10261074}
10271075
 1076void CSPDirectiveList::parsePluginTypes(const String& name, const String& value)
 1077{
 1078 if (!m_pluginTypesDirective.isNull()) {
 1079 logDuplicateDirective(name);
 1080 return;
 1081 }
 1082
 1083 const UChar* begin = value.characters();
 1084 const UChar* position = begin;
 1085 const UChar* end = begin + value.length();
 1086 m_pluginTypesDirective = value;
 1087
 1088 // 'plugin-types ____;' OR 'plugin-types;'
 1089 if (value.isEmpty()) {
 1090 logInvalidPluginTypes(value);
 1091 m_pluginTypesDirective = "";
 1092 return;
 1093 }
 1094
 1095 while (position < end) {
 1096 // _____ OR _____mime1/mime1
 1097 // ^ ^
 1098 skipWhile<isASCIISpace>(position, end);
 1099 if (position == end)
 1100 return;
 1101
 1102 // mime1/mime1 mime2/mime2
 1103 // ^
 1104 begin = position;
 1105 if (!skipExactly<isMediaTypeCharacter>(position, end)) {
 1106 skipWhile<isNotASCIISpace>(position, end);
 1107 logInvalidPluginTypes(String(begin, position - begin));
 1108 continue;
 1109 }
 1110 skipWhile<isMediaTypeCharacter>(position, end);
 1111
 1112 // mime1/mime1 mime2/mime2
 1113 // ^
 1114 if (!skipExactly(position, end, '/')) {
 1115 skipWhile<isNotASCIISpace>(position, end);
 1116 logInvalidPluginTypes(String(begin, position - begin));
 1117 continue;
 1118 }
 1119
 1120 // mime1/mime1 mime2/mime2
 1121 // ^
 1122 if (!skipExactly<isMediaTypeCharacter>(position, end)) {
 1123 skipWhile<isNotASCIISpace>(position, end);
 1124 logInvalidPluginTypes(String(begin, position - begin));
 1125 continue;
 1126 }
 1127 skipWhile<isMediaTypeCharacter>(position, end);
 1128
 1129 // mime1/mime1 mime2/mime2 OR mime1/mime1 OR mime1/mime1/error
 1130 // ^ ^ ^
 1131 if (position < end && isNotASCIISpace(*position)) {
 1132 skipWhile<isNotASCIISpace>(position, end);
 1133 logInvalidPluginTypes(String(begin, position - begin));
 1134 continue;
 1135 }
 1136 m_pluginTypes.add(String(begin, position - begin));
 1137
 1138 ASSERT(position == end || isASCIISpace(*position));
 1139 }
 1140}
 1141
10281142void CSPDirectiveList::setCSPDirective(const String& name, const String& value, OwnPtr<CSPDirective>& directive)
10291143{
10301144 if (directive) {

@@void CSPDirectiveList::addDirective(const String& name, const String& value)
10481162{
10491163 DEFINE_STATIC_LOCAL(String, defaultSrc, ("default-src"));
10501164 DEFINE_STATIC_LOCAL(String, scriptSrc, ("script-src"));
1051 #if ENABLE(CSP_NEXT)
1052  DEFINE_STATIC_LOCAL(String, scriptNonce, ("script-nonce"));
1053 #endif
10541165 DEFINE_STATIC_LOCAL(String, objectSrc, ("object-src"));
10551166 DEFINE_STATIC_LOCAL(String, frameSrc, ("frame-src"));
10561167 DEFINE_STATIC_LOCAL(String, imgSrc, ("img-src"));

@@void CSPDirectiveList::addDirective(const String& name, const String& value)
10601171 DEFINE_STATIC_LOCAL(String, connectSrc, ("connect-src"));
10611172 DEFINE_STATIC_LOCAL(String, sandbox, ("sandbox"));
10621173 DEFINE_STATIC_LOCAL(String, reportURI, ("report-uri"));
 1174#if ENABLE(CSP_NEXT)
 1175 DEFINE_STATIC_LOCAL(String, scriptNonce, ("script-nonce"));
 1176 DEFINE_STATIC_LOCAL(String, pluginTypes, ("plugin-types"));
 1177#endif
10631178
10641179 ASSERT(!name.isEmpty());
10651180

@@void CSPDirectiveList::addDirective(const String& name, const String& value)
10881203#if ENABLE(CSP_NEXT)
10891204 else if (equalIgnoringCase(name, scriptNonce))
10901205 parseScriptNonce(name, value);
 1206 else if (equalIgnoringCase(name, pluginTypes))
 1207 parsePluginTypes(name, value);
10911208#endif
10921209 else
10931210 logUnrecognizedDirective(name);

@@bool ContentSecurityPolicy::allowScriptNonce(const String& nonce, const String&
12221339 return isAllowedByAllWithNonce<&CSPDirectiveList::allowScriptNonce>(m_policies, nonce, contextURL, contextLine, url);
12231340}
12241341
 1342bool ContentSecurityPolicy::allowPluginType(const String& type, const String& typeAttribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
 1343{
 1344 for (size_t i = 0; i < m_policies.size(); ++i) {
 1345 if (!m_policies[i].get()->allowPluginType(type, typeAttribute, url, reportingStatus))
 1346 return false;
 1347 }
 1348 return true;
 1349}
 1350
12251351bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
12261352{
12271353 return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_policies, url, reportingStatus);

Source/WebCore/page/ContentSecurityPolicy.h

@@public:
7878 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
7979 bool allowEval(PassRefPtr<ScriptCallStack>, ReportingStatus = SendReport) const;
8080 bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& = KURL()) const;
 81 bool allowPluginType(const String& type, const String& typeAttribute, const KURL&, ReportingStatus = SendReport) const;
8182
8283 bool allowScriptFromSource(const KURL&, ReportingStatus = SendReport) const;
8384 bool allowObjectFromSource(const KURL&, ReportingStatus = SendReport) const;

LayoutTests/ChangeLog

 12012-08-07 Mike West <mkwst@chromium.org>
 2
 3 Implement the plugin-types Content Security Policy directive.
 4 https://bugs.webkit.org/show_bug.cgi?id=91919
 5
 6 Reviewed by Adam Barth.
 7
 8 * http/tests/plugins/resources/mock-plugin-unknown-type.pl:
 9 Adding a mock plugin resource that is served with a type that WebKit
 10 doesn't understand. Using it to test a confusion attack in
 11 plugintypes-url-02.
 12 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-invalid-expected.txt: Added.
 13 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-invalid.html: Added.
 14 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-data-expected.txt: Added.
 15 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-data.html: Added.
 16 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-url-expected.txt: Added.
 17 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-url.html: Added.
 18 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-data-expected.txt: Added.
 19 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-data.html: Added.
 20 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-url-expected.txt: Added.
 21 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-url.html: Added.
 22 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-allowed-expected.txt: Added.
 23 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-allowed.html: Added.
 24 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-blocked-expected.txt: Added.
 25 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-blocked.html: Added.
 26 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-01-expected.txt: Added.
 27 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-01.html: Added.
 28 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-02-expected.txt: Added.
 29 * http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-02.html: Added.
 30 * http/tests/security/contentSecurityPolicy/object-src-none-allowed.html:
 31 * http/tests/security/contentSecurityPolicy/object-src-none-blocked.html:
 32 Renaming the `q` parameter to `plugin` in these two tests.
 33 * http/tests/security/contentSecurityPolicy/resources/echo-object-data.pl:
 34 Add output of explicit MIME types to the object data renderer, and
 35 changed the `q` parameter to be slightly less confusingly named.
 36 It's now `plugin`.
 37 * http/tests/security/contentSecurityPolicy/resources/multiple-iframe-plugin-test.js: Added.
 38 Copy `multiple-iframe-test.js`, and add in plugin-specific details,
 39 like `plugin`, `log`, and `type`.
 40 (test):
 41 (finishTesting):
 42
1432012-08-07 W. James MacLean <wjmaclean@chromium.org>
244
345 [chromium] Add support to DumpRenderTree [EventSender] for GestureTapDown events.

LayoutTests/http/tests/plugins/resources/mock-plugin-unknown-type.pl

 1#!/usr/bin/perl -wT
 2use strict;
 3
 4print "Content-Type: application/x-unknown-type\n\n";
 5print "This is a mock plugin of a type that WebKit doesn't natively understand.";

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-invalid-expected.txt

 1CONSOLE MESSAGE: 'plugin-types' Content Security Policy directive is empty; all plugins will be blocked.
 2
 3CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types '.
 4
 5CONSOLE MESSAGE: 'plugin-types' Content Security Policy directive is empty; all plugins will be blocked.
 6
 7CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types '.
 8
 9CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: 'text'.
 10
 11CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text'.
 12
 13CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: 'text/'.
 14
 15CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text/'.
 16
 17CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: '/text'.
 18
 19CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types /text'.
 20
 21CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: 'text//plain'.
 22
 23CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text//plain'.
 24
 25CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: 'text/plainapplication/nospace'.
 26
 27CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text/plainapplication/nospace'.
 28
 29CONSOLE MESSAGE: Invalid plugin type in 'plugin-types' Content Security Policy directive: 'text'.
 30
 31This tests our handling of invalid `plugin-types` CSP directives. Consider this test passing if each of the following frames contains either "PASS" or no text at all.
 32
 33
 34
 35--------
 36Frame: '<!--framePath //<!--frame0-->-->'
 37--------
 38
 39
 40--------
 41Frame: '<!--framePath //<!--frame1-->-->'
 42--------
 43
 44
 45--------
 46Frame: '<!--framePath //<!--frame2-->-->'
 47--------
 48
 49
 50--------
 51Frame: '<!--framePath //<!--frame3-->-->'
 52--------
 53
 54
 55--------
 56Frame: '<!--framePath //<!--frame4-->-->'
 57--------
 58
 59
 60--------
 61Frame: '<!--framePath //<!--frame5-->-->'
 62--------
 63
 64
 65--------
 66Frame: '<!--framePath //<!--frame6-->-->'
 67--------
 68
 69
 70--------
 71Frame: '<!--framePath //<!--frame7-->-->'
 72--------
 73PASS.
 74
 75

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-invalid.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script src='../resources/multiple-iframe-plugin-test.js'></script>
 5<script>
 6var tests = [
 7 [false, 'plugin-types;'],
 8 [false, 'plugin-types ;'],
 9 [false, 'plugin-types text'],
 10 [false, 'plugin-types text/'],
 11 [false, 'plugin-types /text'],
 12 [false, 'plugin-types text//plain'],
 13 [false, 'plugin-types text/plainapplication/nospace'],
 14 [true, 'plugin-types text application/x-webkit-test-netscape'],
 15];
 16</script>
 17</head>
 18<body onload="test()">
 19 <p>
 20 This tests our handling of invalid `plugin-types` CSP directives.
 21 Consider this test passing if each of the following frames contains
 22 either "PASS" or no text at all.
 23 </p>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-data-expected.txt

 1This tests that plugin content that doesn't match the declared type doesn't load, even if the document's CSP would allow it. This test passes if "FAIL!" isn't logged.

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-data.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner) {
 6 testRunner.dumpAsText();
 7 testRunner.dumpChildFramesAsText();
 8}
 9</script>
 10<meta http-equiv="X-WebKit-CSP" content="plugin-types application/x-invalid-type">
 11</head>
 12<body>
 13 This tests that plugin content that doesn't match the declared type doesn't
 14 load, even if the document's CSP would allow it. This test passes if "FAIL!"
 15 isn't logged.
 16 <object type="application/x-invalid-type"
 17 data="data:application/x-webkit-test-netscape,logifloaded"
 18 log="FAIL!"></object>
 19</body>
 20</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-url-expected.txt

 1This tests that plugin content that doesn't match the declared type doesn't load, even if the document's CSP would allow it. This test passes if no iframe is dumped (meaning that no PluginDocument was created).

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-mismatched-url.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner) {
 6 testRunner.dumpAsText();
 7 testRunner.dumpChildFramesAsText();
 8}
 9</script>
 10<script src="/plugins/resources/mock-plugin-logger.js"></script>
 11<meta http-equiv="X-WebKit-CSP" content="plugin-types application/x-invalid-type">
 12</head>
 13<body>
 14 This tests that plugin content that doesn't match the declared type doesn't
 15 load, even if the document's CSP would allow it. This test passes if no
 16 iframe is dumped (meaning that no PluginDocument was created).
 17 <object type="application/x-invalid-type"
 18 data="/plugins/resources/mock-plugin.pl"
 19 log="FAIL!"></object>
 20</body>
 21</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-data-expected.txt

 1CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type '') because it violates the following Content Security Policy Directive: 'plugin-types application/x-invalid-type'.
 2
 3Given a `plugin-types` directive, plugins have to declare a type explicitly. No declared type, no load. This test passes if there's a console message above and "FAIL!" isn't logged.

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-data.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner) {
 6 testRunner.dumpAsText();
 7 testRunner.dumpChildFramesAsText();
 8}
 9</script>
 10<script src="/plugins/resources/mock-plugin-logger.js"></script>
 11<meta http-equiv="X-WebKit-CSP" content="plugin-types application/x-invalid-type">
 12</head>
 13<body>
 14 Given a `plugin-types` directive, plugins have to declare a type explicitly.
 15 No declared type, no load. This test passes if there's a console message
 16 above and "FAIL!" isn't logged.
 17 <object data="data:application/x-webkit-test-netscape,logifloaded"
 18 log="FAIL!"></object>
 19</body>
 20</html>
 21

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-url-expected.txt

 1CONSOLE MESSAGE: Refused to load 'http://127.0.0.1:8000/plugins/resources/mock-plugin.pl' (MIME type '') because it violates the following Content Security Policy Directive: 'plugin-types application/x-invalid-type'.
 2
 3Given a `plugin-types` directive, plugins have to declare a type explicitly. No declared type, no load. This test passes if there's a console message above.
 4
 5--------
 6Frame: '<!--framePath //<!--frame0-->-->'
 7--------
 8

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-notype-url.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner) {
 6 testRunner.dumpAsText();
 7 testRunner.dumpChildFramesAsText();
 8}
 9</script>
 10<meta http-equiv="X-WebKit-CSP" content="plugin-types application/x-invalid-type">
 11</head>
 12<body>
 13 Given a `plugin-types` directive, plugins have to declare a type explicitly.
 14 No declared type, no load. This test passes if there's a console message
 15 above.
 16 <object data="/plugins/resources/mock-plugin.pl"
 17 log="FAIL!"></object>
 18</body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-allowed-expected.txt

 1This test passes if there isn't a console message saying the plugin was blocked.

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-allowed.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner)
 6 testRunner.dumpAsText();
 7</script>
 8<meta http-equiv="X-WebKit-CSP" content="plugin-types application/x-webkit-test-netscape">
 9</head>
 10<body>
 11This test passes if there isn't a console message saying the plugin was blocked.
 12<object type="application/x-webkit-test-netscape"></object>
 13</body>
 14</html>
 15

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-blocked-expected.txt

 1CONSOLE MESSAGE: Refused to load '' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text/plain'.
 2
 3This test passes if there is a console message saying the plugin was blocked.

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-nourl-blocked.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script>
 5if (window.testRunner)
 6 testRunner.dumpAsText();
 7</script>
 8<meta http-equiv="X-WebKit-CSP" content="plugin-types text/plain">
 9</head>
 10<body>
 11This test passes if there is a console message saying the plugin was blocked.
 12<object type="application/x-webkit-test-netscape"></object>
 13</body>
 14</html>
 15

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-01-expected.txt

 1This tests our handling of `data:` URLs, given a `plugin-types` CSP directive. Consider this test passing if each of the following frames contains "PASS" or no text at all, and no console warnings appear above.
 2
 3
 4
 5--------
 6Frame: '<!--framePath //<!--frame0-->-->'
 7--------
 8PASS.
 9
 10
 11
 12--------
 13Frame: '<!--framePath //<!--frame1-->-->'
 14--------
 15PASS.
 16
 17
 18
 19--------
 20Frame: '<!--framePath //<!--frame2-->-->'
 21--------
 22PASS.
 23
 24
 25
 26--------
 27Frame: '<!--framePath //<!--frame3-->-->'
 28--------
 29

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-01.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script src='../resources/multiple-iframe-plugin-test.js'></script>
 5<script>
 6var tests = [
 7 [true, 'plugin-types application/x-webkit-test-netscape'],
 8 [true, 'plugin-types text/plain application/x-webkit-test-netscape'],
 9 [true, 'plugin-types application/x-webkit-test-netscape text/plain'],
 10 [true, 'plugin-types application/x-webkit-test-netscape', '/plugins/resources/mock-plugin.pl', 'application/x-webkit-test-netscape'],
 11];
 12</script>
 13</head>
 14<body onload="test()">
 15 <p>
 16 This tests our handling of `data:` URLs, given a `plugin-types` CSP
 17 directive. Consider this test passing if each of the following frames
 18 contains "PASS" or no text at all, and no console warnings appear above.
 19 </p>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-02-expected.txt

 1CONSOLE MESSAGE: Refused to load 'data:application/x-webkit-test-netscape,logifloaded' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types text/plain'.
 2
 3CONSOLE MESSAGE: Refused to load 'http://127.0.0.1:8000/plugins/resources/mock-plugin.pl?url-doesnt-match-csp' (MIME type 'application/x-webkit-test-netscape') because it violates the following Content Security Policy Directive: 'plugin-types application/x-shockwave-flash'.
 4
 5CONSOLE MESSAGE: Refused to load 'http://127.0.0.1:8000/plugins/resources/mock-plugin.pl?type-attribute-doesnt-match-csp' (MIME type 'application/x-shockwave-flash') because it violates the following Content Security Policy Directive: 'plugin-types application/x-webkit-test-netscape'.
 6
 7This tests our handling of non-`data:` URLs, given a `plugin-types` CSP directive. Consider this test passing if none of the following frames contains "FAIL" and four sets of console logs appear above.
 8
 9
 10
 11--------
 12Frame: '<!--framePath //<!--frame0-->-->'
 13--------
 14
 15
 16--------
 17Frame: '<!--framePath //<!--frame1-->-->'
 18--------
 19
 20
 21--------
 22Frame: '<!--framePath //<!--frame2-->-->'
 23--------
 24

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/plugintypes-url-02.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script src='../resources/multiple-iframe-plugin-test.js'></script>
 5<script>
 6var tests = [
 7 [false, 'plugin-types text/plain'],
 8 [false, 'plugin-types application/x-shockwave-flash', '/plugins/resources/mock-plugin.pl?url-doesnt-match-csp', 'application/x-webkit-test-netscape'],
 9 [false, 'plugin-types application/x-unknown-type', '/plugins/resources/mock-plugin-unknown-type.pl?type-attribute-doesnt-match-csp', 'application/x-webkit-test-netscape'],
 10];
 11</script>
 12</head>
 13<body onload="test()">
 14 <p>
 15 This tests our handling of non-`data:` URLs, given a `plugin-types` CSP
 16 directive. Consider this test passing if none of the following frames
 17 contains "FAIL" and four sets of console logs appear above.
 18 </p>

LayoutTests/http/tests/security/contentSecurityPolicy/object-src-none-allowed.html

@@if (window.testRunner) {
99</script>
1010</head>
1111<body>
12  <iframe src="http://127.0.0.1:8000/security/contentSecurityPolicy/resources/echo-object-data.pl?q=data:application/x-webkit-test-netscape,logifloaded&log=PASS!&csp=img-src%20'none'"></iframe>
 12 <iframe src="http://127.0.0.1:8000/security/contentSecurityPolicy/resources/echo-object-data.pl?plugin=data:application/x-webkit-test-netscape,logifloaded&log=PASS!&csp=img-src%20'none'"></iframe>
1313</body>
1414</html>

LayoutTests/http/tests/security/contentSecurityPolicy/object-src-none-blocked.html

@@if (window.testRunner) {
99</script>
1010</head>
1111<body>
12  <iframe src="http://127.0.0.1:8000/security/contentSecurityPolicy/resources/echo-object-data.pl?q=data:application/x-webkit-test-netscape,logifloaded&log=FAIL&csp=object-src%20'none'"></iframe>
 12 <iframe src="http://127.0.0.1:8000/security/contentSecurityPolicy/resources/echo-object-data.pl?plugin=data:application/x-webkit-test-netscape,logifloaded&log=FAIL&csp=object-src%20'none'"></iframe>
1313</body>
1414</html>

LayoutTests/http/tests/security/contentSecurityPolicy/resources/echo-object-data.pl

@@print "<!DOCTYPE html>\n";
1111print "<html>\n";
1212print "<body>\n";
1313print "<script src=\"/plugins/resources/mock-plugin-logger.js\"></script>\n";
14 print "<object data=\"".$cgi->param('q')."\" log=\"".$cgi->param('log')."\"></object>\n";
 14print "<object data=\"".$cgi->param('plugin')."\"\n";
 15print " log=\"".$cgi->param('log')."\"\n" if $cgi->param('log');
 16print " type=\"".$cgi->param('type')."\"\n" if $cgi->param('type');
 17print "></object>\n";
1518print "</body>\n";
1619print "</html>\n";

LayoutTests/http/tests/security/contentSecurityPolicy/resources/multiple-iframe-plugin-test.js

 1if (window.testRunner) {
 2 testRunner.waitUntilDone();
 3 testRunner.dumpAsText();
 4 testRunner.dumpChildFramesAsText();
 5}
 6
 7function test() {
 8 if (tests.length === 0)
 9 return finishTesting();
 10 var baseURL = "http://127.0.0.1:8000/security/contentSecurityPolicy/";
 11 var current = tests.shift();
 12 var iframe = document.createElement("iframe");
 13 iframe.src = baseURL + "resources/echo-object-data.pl?" +
 14 "&csp=" + escape(current[1]);
 15
 16 if (current[0])
 17 iframe.src += "&log=PASS.";
 18 else
 19 iframe.src += "&log=FAIL.";
 20
 21 if (current[2])
 22 iframe.src += "&plugin=" + escape(current[2]);
 23 else {
 24 iframe.src += "&plugin=data:application/x-webkit-test-netscape,logifloaded";
 25 }
 26
 27 if (current[3] !== undefined)
 28 iframe.src += "&type=" + escape(current[3]);
 29 else
 30 iframe.src += "&type=application/x-webkit-test-netscape";
 31
 32 iframe.onload = test;
 33 document.body.appendChild(iframe);
 34}
 35
 36function finishTesting() {
 37 if (window.testRunner) {
 38 setTimeout("testRunner.notifyDone()", 0);
 39 }
 40 return true;
 41}