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