CSP: Apply img-src directive to favicon loads
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 20:45:37 +0000 (20:45 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 20:45:37 +0000 (20:45 +0000)
commitf74ed4eebc5dc6fca8c041af2e858846e2b25ddb
treefe64af1dc869ae0e9180d35356209300acbccb1e
parent9d809f3a837e37133cad2c970d2e41d67882508e
CSP: Apply img-src directive to favicon loads
https://bugs.webkit.org/show_bug.cgi?id=172733
<rdar://problem/32082654>

Reviewed by Brady Eidson.

Source/WebCore:

Differentiate favicon requests from raw resources requests so that we can apply the Content
Security Policy to favicon requests.

Tests: http/tests/security/contentSecurityPolicy/allow-favicon.html
       http/tests/security/contentSecurityPolicy/block-favicon.html

* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::cachedResourceContent): Keep our current behavior and treat a
favicon resource analogous to a raw resource.
(WebCore::InspectorPageAgent::cachedResourceType): Ditto.
* loader/LinkLoader.cpp:
(WebCore::createLinkPreloadResourceClient): Now that we differentiate between a favicon
and a raw resource we add favicons to the list of unsupported <link as="..."> types. This
makes the list of handled request destination types more closely match the list of valid types
documented in <https://fetch.spec.whatwg.org/#concept-request-destination> (24 May 2017).
* loader/ResourceLoadInfo.cpp:
(WebCore::toResourceType): Keep our current behavior and treat a favicon resource analogous
to a raw resource.
* loader/SubresourceLoader.cpp:
(WebCore::logResourceLoaded): Ditto.
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::CachedRawResource): Update for renaming.
* loader/cache/CachedRawResource.h:
(isType): Ditto.
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::defaultPriorityForResourceType): Keep our current behavior and treat
a favicon resource analogous to a raw resource.
* loader/cache/CachedResource.h:
(WebCore::CachedResource::isMainOrMediaOrFaviconOrRawResource): Renamed; formerly named isMainOrMediaOrRawResource.
Also return true if the this resource is a favicon.
(WebCore::CachedResource::ignoreForRequestCount): Keep our current behavior and treat a
favicon resource analogous to a raw resource.
(WebCore::CachedResource::isMainOrMediaOrRawResource): Deleted; renamed to isMainOrMediaOrFaviconOrRawResource.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::createResource): Keep our current behavior and treat a favicon resource analogous
to a raw resource.
(WebCore::CachedResourceLoader::requestFavicon): Added.
(WebCore::contentTypeFromResourceType): Keep our current behavior and treat a favicon
resource analogous to a raw resource.
(WebCore::CachedResourceLoader::checkInsecureContent): Ditto.
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy): Check if the favicon is
allowed by the CSP of the page.
(WebCore::CachedResourceLoader::determineRevalidationPolicy): Update for renaming.
* loader/cache/CachedResourceLoader.h:
* loader/icon/IconLoader.cpp:
(WebCore::IconLoader::startLoading): Substitute call CachedResourceLoader::requestFavicon() for CachedResourceLoader::requestRawResource()
and remove comment about ContentSecurityPolicyImposition::DoPolicyCheck being a placeholder. This is no longer the
case. This resource request option is now meaningful as we want to apply the CSP of the page with respect to the
request for the favicon.

Source/WebKit2:

Return 0 seconds for the maximum buffering time for favicons (no change in behavior).

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::maximumBufferingTime):

LayoutTests:

Adds tests to ensure the CSP policy is applied to favicon loads.

* http/tests/security/contentSecurityPolicy/allow-favicon-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/allow-favicon.html: Added.
* http/tests/security/contentSecurityPolicy/block-favicon-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/block-favicon.html: Added.
* platform/wk2/TestExpectations: Skip the tests until we fix <https://bugs.webkit.org/show_bug.cgi?id=115809>.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218015 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/security/contentSecurityPolicy/allow-favicon-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/allow-favicon.html [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/block-favicon-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/block-favicon.html [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/ResourceLoadInfo.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedRawResource.cpp
Source/WebCore/loader/cache/CachedRawResource.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/loader/icon/IconLoader.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp