Changeset 216553 in webkit


Ignore:
Timestamp:
May 9, 2017 3:53:13 PM (7 years ago)
Author:
weinig@apple.com
Message:

LayoutTests/imported/w3c:
Implement Subresource Integrity (SRI)
https://bugs.webkit.org/show_bug.cgi?id=148363
<rdar://problem/18945879>

Reviewed by Youenn Fablet.

  • web-platform-tests/fetch/api/basic/integrity-expected.txt:
  • web-platform-tests/fetch/api/basic/integrity-worker-expected.txt:

Update results now that integrity is implemented.

Source/WebCore:
Implement Subresource Integrity (SRI) [Part 2 - Fetch]
https://bugs.webkit.org/show_bug.cgi?id=148363
<rdar://problem/18945879>

Reviewed by Youenn Fablet.

Tests: http/tests/subresource-integrity/sri-fetch-worker.html

http/tests/subresource-integrity/sri-fetch.html

  • loader/FetchOptions.h:
  • loader/ThreadableLoader.cpp:

(WebCore::ThreadableLoaderOptions::isolatedCopy):

  • loader/ThreadableLoader.h:
  • loader/WorkerThreadableLoader.cpp:

(WebCore::LoaderTaskOptions::LoaderTaskOptions):
Add integrity metadata to the fetch options, and fix the implementation of
ThreadableLoaderOptions::isolatedCopy to work correctly (it was missing isolated
copy derivedCachedDataTypesToRetrieve).

  • Modules/fetch/FetchRequest.cpp:

(WebCore::buildOptions):
(WebCore::FetchRequest::initializeOptions):

  • Modules/fetch/FetchRequest.h:

Switch to using the integrity metadata on the fetchOptions, removing the need to
store them directly on the internal request.

  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
(WebCore::DocumentThreadableLoader::didReceiveResponse):
(WebCore::DocumentThreadableLoader::didReceiveData):
(WebCore::DocumentThreadableLoader::didFinishLoading):
(WebCore::DocumentThreadableLoader::loadRequest):
(WebCore::DocumentThreadableLoader::reportIntegrityMetadataError):

  • loader/DocumentThreadableLoader.h:

Add a new flag, m_delayCallbacksForIntegrityCheck, which is used when integrity metadata
is present, so we can implement the 'wait' concept from the fetch spec, and delay informing
the clients until we have validated the integrity metadata.

LayoutTests:
Implement Subresource Integrity (SRI)
https://bugs.webkit.org/show_bug.cgi?id=148363
<rdar://problem/18945879>

Reviewed by Youenn Fablet.

Add tests for Subresource Integrity for Fetch based off the ones from Web
Platform Tests. Additional tests for more CORS combinations have been added.

  • http/tests/subresource-integrity/resources/crossorigin-anon-resource.txt: Added.
  • http/tests/subresource-integrity/resources/crossorigin-creds-resource.txt: Added.
  • http/tests/subresource-integrity/resources/crossorigin-ineligible-resource.txt: Added.
  • http/tests/subresource-integrity/resources/resource.txt: Added.
  • http/tests/subresource-integrity/sri-fetch-expected.txt: Added.
  • http/tests/subresource-integrity/sri-fetch-worker-expected.txt: Added.
  • http/tests/subresource-integrity/sri-fetch-worker.html: Added.
  • http/tests/subresource-integrity/sri-fetch.html: Added.
  • http/tests/subresource-integrity/sri-fetch.js: Added.
Location:
trunk
Files:
9 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r216552 r216553  
     12017-05-09  Sam Weinig  <sam@webkit.org>
     2
     3        Implement Subresource Integrity (SRI)
     4        https://bugs.webkit.org/show_bug.cgi?id=148363
     5        <rdar://problem/18945879>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Add tests for Subresource Integrity for Fetch based off the ones from Web
     10        Platform Tests. Additional tests for more CORS combinations have been added.
     11
     12        * http/tests/subresource-integrity/resources/crossorigin-anon-resource.txt: Added.
     13        * http/tests/subresource-integrity/resources/crossorigin-creds-resource.txt: Added.
     14        * http/tests/subresource-integrity/resources/crossorigin-ineligible-resource.txt: Added.
     15        * http/tests/subresource-integrity/resources/resource.txt: Added.
     16        * http/tests/subresource-integrity/sri-fetch-expected.txt: Added.
     17        * http/tests/subresource-integrity/sri-fetch-worker-expected.txt: Added.
     18        * http/tests/subresource-integrity/sri-fetch-worker.html: Added.
     19        * http/tests/subresource-integrity/sri-fetch.html: Added.
     20        * http/tests/subresource-integrity/sri-fetch.js: Added.
     21
    1222017-05-09  Matt Lewis  <jlewis3@apple.com>
    223
  • trunk/LayoutTests/http/tests/subresource-integrity/sri-script.html

    r216347 r216553  
    163163
    164164// WebKit additions to the web-platform-tests test cases.
     165// FIXME: Upstream these additional tests to the official web-platform-tests repository.
    165166
    166167new SRIScriptTest(
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r216537 r216553  
     12017-05-09  Sam Weinig  <sam@webkit.org>
     2
     3        Implement Subresource Integrity (SRI)
     4        https://bugs.webkit.org/show_bug.cgi?id=148363
     5        <rdar://problem/18945879>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * web-platform-tests/fetch/api/basic/integrity-expected.txt:
     10        * web-platform-tests/fetch/api/basic/integrity-worker-expected.txt:
     11        Update results now that integrity is implemented.
     12
    1132017-05-09  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/integrity-expected.txt

    r211930 r216553  
     1CONSOLE MESSAGE: Fetch API cannot load http://localhost:8800/fetch/api/resources/top.txt. Failed integrity metadata check.
     2CONSOLE MESSAGE: Fetch API cannot load http://localhost:8800/fetch/api/resources/top.txt. Failed integrity metadata check.
     3CONSOLE MESSAGE: Fetch API cannot load http://localhost:8800/fetch/api/resources/top.txt. Failed integrity metadata check.
     4CONSOLE MESSAGE: Fetch API cannot load http://localhost:8801/fetch/api/resources/top.txt?pipe=header(Access-Control-Allow-Origin,*). Failed integrity metadata check.
    15
    26PASS Empty string integrity
     
    48PASS SHA-384 integrity
    59PASS SHA-512 integrity
    6 FAIL Invalid integrity assert_unreached: Should have rejected: undefined Reached unreachable code
     10PASS Invalid integrity
    711PASS Multiple integrities: valid stronger than invalid
    8 FAIL Multiple integrities: invalid stronger than valid assert_unreached: Should have rejected: undefined Reached unreachable code
     12PASS Multiple integrities: invalid stronger than valid
    913PASS Multiple integrities: invalid as strong as valid
    1014PASS Multiple integrities: both are valid
    11 FAIL Multiple integrities: both are invalid assert_unreached: Should have rejected: undefined Reached unreachable code
     15PASS Multiple integrities: both are invalid
    1216PASS CORS empty integrity
    1317PASS CORS SHA-512 integrity
    14 FAIL CORS invalid integrity assert_unreached: Should have rejected: undefined Reached unreachable code
     18PASS CORS invalid integrity
    1519
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/integrity-worker-expected.txt

    r211930 r216553  
    44PASS SHA-384 integrity
    55PASS SHA-512 integrity
    6 FAIL Invalid integrity assert_unreached: Should have rejected: undefined Reached unreachable code
     6PASS Invalid integrity
    77PASS Multiple integrities: valid stronger than invalid
    8 FAIL Multiple integrities: invalid stronger than valid assert_unreached: Should have rejected: undefined Reached unreachable code
     8PASS Multiple integrities: invalid stronger than valid
    99PASS Multiple integrities: invalid as strong as valid
    1010PASS Multiple integrities: both are valid
    11 FAIL Multiple integrities: both are invalid assert_unreached: Should have rejected: undefined Reached unreachable code
     11PASS Multiple integrities: both are invalid
    1212PASS CORS empty integrity
    1313PASS CORS SHA-512 integrity
    14 FAIL CORS invalid integrity assert_unreached: Should have rejected: undefined Reached unreachable code
     14PASS CORS invalid integrity
    1515
  • trunk/Source/WebCore/ChangeLog

    r216550 r216553  
     12017-05-09  Sam Weinig  <sam@webkit.org>
     2
     3        Implement Subresource Integrity (SRI) [Part 2 - Fetch]
     4        https://bugs.webkit.org/show_bug.cgi?id=148363
     5        <rdar://problem/18945879>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Tests: http/tests/subresource-integrity/sri-fetch-worker.html
     10               http/tests/subresource-integrity/sri-fetch.html
     11
     12        * loader/FetchOptions.h:
     13        * loader/ThreadableLoader.cpp:
     14        (WebCore::ThreadableLoaderOptions::isolatedCopy):
     15        * loader/ThreadableLoader.h:
     16        * loader/WorkerThreadableLoader.cpp:
     17        (WebCore::LoaderTaskOptions::LoaderTaskOptions):
     18        Add integrity metadata to the fetch options, and fix the implementation of
     19        ThreadableLoaderOptions::isolatedCopy to work correctly (it was missing isolated
     20        copy derivedCachedDataTypesToRetrieve).
     21
     22        * Modules/fetch/FetchRequest.cpp:
     23        (WebCore::buildOptions):
     24        (WebCore::FetchRequest::initializeOptions):
     25        * Modules/fetch/FetchRequest.h:
     26        Switch to using the integrity metadata on the fetchOptions, removing the need to
     27        store them directly on the internal request.
     28
     29        * loader/DocumentThreadableLoader.cpp:
     30        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
     31        (WebCore::DocumentThreadableLoader::didReceiveResponse):
     32        (WebCore::DocumentThreadableLoader::didReceiveData):
     33        (WebCore::DocumentThreadableLoader::didFinishLoading):
     34        (WebCore::DocumentThreadableLoader::loadRequest):
     35        (WebCore::DocumentThreadableLoader::reportIntegrityMetadataError):
     36        * loader/DocumentThreadableLoader.h:
     37        Add a new flag, m_delayCallbacksForIntegrityCheck, which is used when integrity metadata
     38        is present, so we can implement the 'wait' concept from the fetch spec, and delay informing
     39        the clients until we have validated the integrity metadata.
     40
    1412017-05-09  Commit Queue  <commit-queue@webkit.org>
    242
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r209629 r216553  
    106106
    107107    if (!init.integrity.isNull())
    108         request.integrity = init.integrity;
     108        request.options.integrity = init.integrity;
    109109
    110110    if (!init.method.isNull()) {
     
    133133        if (method != "GET" && method != "POST" && method != "HEAD")
    134134            return Exception { TypeError, ASCIILiteral("Method must be GET, POST or HEAD in no-cors mode.") };
    135         if (!m_internalRequest.integrity.isEmpty())
     135        if (!m_internalRequest.options.integrity.isEmpty())
    136136            return Exception { TypeError, ASCIILiteral("There cannot be an integrity in no-cors mode.") };
    137137        m_headers->setGuard(FetchHeaders::Guard::RequestNoCors);
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.h

    r210860 r216553  
    8484    Redirect redirect() const;
    8585
    86     const String& integrity() const { return m_internalRequest.integrity; }
     86    const String& integrity() const { return m_internalRequest.options.integrity; }
    8787
    8888    ExceptionOr<Ref<FetchRequest>> clone(ScriptExecutionContext&);
     
    9292        FetchOptions options;
    9393        String referrer;
    94         String integrity;
    9594    };
    9695
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r216051 r216553  
    5353#include "SchemeRegistry.h"
    5454#include "SecurityOrigin.h"
     55#include "SubresourceIntegrity.h"
    5556#include "SubresourceLoader.h"
    5657#include "ThreadableLoaderClient.h"
     
    9697    , m_simpleRequest(true)
    9798    , m_async(blockingBehavior == LoadAsynchronously)
     99    , m_delayCallbacksForIntegrityCheck(!m_options.integrity.isEmpty())
    98100    , m_contentSecurityPolicy(WTFMove(contentSecurityPolicy))
    99101    , m_shouldLogError(shouldLogError)
     
    297299    InspectorInstrumentation::didReceiveThreadableLoaderResponse(*this, identifier);
    298300
     301    if (m_delayCallbacksForIntegrityCheck)
     302        return;
     303
    299304    if (options().filteringPolicy == ResponseFilteringPolicy::Disable) {
    300305        m_client->didReceiveResponse(identifier, response);
     
    325330    ASSERT(m_client);
    326331
     332    if (m_delayCallbacksForIntegrityCheck)
     333        return;
     334
    327335    m_client->didReceiveData(data, dataLength);
    328336}
     
    362370{
    363371    ASSERT(m_client);
     372
     373    if (m_delayCallbacksForIntegrityCheck) {
     374        if (!matchIntegrityMetadata(*m_resource, m_options.integrity)) {
     375            reportIntegrityMetadataError(m_resource->url());
     376            return;
     377        }
     378
     379        auto response = m_resource->response();
     380
     381        if (options().filteringPolicy == ResponseFilteringPolicy::Disable) {
     382            m_client->didReceiveResponse(identifier, response);
     383            m_client->didReceiveData(m_resource->resourceBuffer()->data(), m_resource->resourceBuffer()->size());
     384        } else {
     385            ASSERT(response.type() == ResourceResponse::Type::Default);
     386           
     387            auto tainting = m_resource->responseTainting();
     388            m_client->didReceiveResponse(identifier, ResourceResponse::filterResponse(response, tainting));
     389            m_client->didReceiveData(m_resource->resourceBuffer()->data(), m_resource->resourceBuffer()->size());
     390        }
     391    }
     392
    364393    m_client->didFinishLoading(identifier);
    365394}
     
    408437        options.clientCredentialPolicy = m_sameOriginRequest ? ClientCredentialPolicy::MayAskClientForCredentials : ClientCredentialPolicy::CannotAskClientForCredentials;
    409438        options.contentSecurityPolicyImposition = ContentSecurityPolicyImposition::SkipPolicyCheck;
     439       
     440        // If there is integrity metadata to validate, we must buffer.
     441        if (!m_options.integrity.isEmpty())
     442            options.dataBufferingPolicy = BufferData;
    410443
    411444        request.setAllowCookies(m_options.allowCredentials == AllowStoredCredentials);
     
    575608}
    576609
     610void DocumentThreadableLoader::reportIntegrityMetadataError(const URL& url)
     611{
     612    logErrorAndFail(ResourceError(errorDomainWebKitInternal, 0, url, "Failed integrity metadata check.", ResourceError::Type::General));
     613}
     614
    577615void DocumentThreadableLoader::logErrorAndFail(const ResourceError& error)
    578616{
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.h

    r212993 r216553  
    119119        void reportContentSecurityPolicyError(const URL&);
    120120        void reportCrossOriginResourceSharingError(const URL&);
     121        void reportIntegrityMetadataError(const URL&);
    121122        void logErrorAndFail(const ResourceError&);
    122123
     
    130131        bool m_simpleRequest;
    131132        bool m_async;
     133        bool m_delayCallbacksForIntegrityCheck;
    132134        std::unique_ptr<ContentSecurityPolicy> m_contentSecurityPolicy;
    133135        std::optional<CrossOriginPreflightChecker> m_preflightChecker;
  • trunk/Source/WebCore/loader/FetchOptions.h

    r207086 r216553  
    2929#pragma once
    3030
     31#include <wtf/text/WTFString.h>
     32
    3133namespace WebCore {
    3234
     
    5254    enum class ReferrerPolicy { EmptyString, NoReferrer, NoReferrerWhenDowngrade, Origin, OriginWhenCrossOrigin, UnsafeUrl };
    5355    ReferrerPolicy referrerPolicy { ReferrerPolicy::EmptyString };
     56
     57    String integrity;
    5458};
    5559
  • trunk/Source/WebCore/loader/ThreadableLoader.cpp

    r210828 r216553  
    6161}
    6262
     63ThreadableLoaderOptions ThreadableLoaderOptions::isolatedCopy() const
     64{
     65    ThreadableLoaderOptions copy;
     66
     67    // FetchOptions
     68    copy.type = this->type;
     69    copy.destination = this->destination;
     70    copy.mode = this->mode;
     71    copy.credentials = this->credentials;
     72    copy.cache = this->cache;
     73    copy.redirect = this->redirect;
     74    copy.referrerPolicy = this->referrerPolicy;
     75    copy.integrity = this->integrity.isolatedCopy();
     76
     77    // ResourceLoaderOptions
     78    copy.sendLoadCallbacks = this->sendLoadCallbacks;
     79    copy.sniffContent = this->sniffContent;
     80    copy.dataBufferingPolicy = this->dataBufferingPolicy;
     81    copy.allowCredentials = this->allowCredentials;
     82    copy.securityCheck = this->securityCheck;
     83    copy.certificateInfoPolicy = this->certificateInfoPolicy;
     84    copy.contentSecurityPolicyImposition = this->contentSecurityPolicyImposition;
     85    copy.defersLoadingPolicy = this->defersLoadingPolicy;
     86    copy.cachingPolicy = this->cachingPolicy;
     87    copy.sameOriginDataURLFlag = this->sameOriginDataURLFlag;
     88    copy.initiatorContext = this->initiatorContext;
     89    copy.clientCredentialPolicy = this->clientCredentialPolicy;
     90    copy.maxRedirectCount = this->maxRedirectCount;
     91    copy.derivedCachedDataTypesToRetrieve.reserveInitialCapacity(this->derivedCachedDataTypesToRetrieve.size());
     92    for (auto& derivedCachedDataType : this->derivedCachedDataTypesToRetrieve)
     93        copy.derivedCachedDataTypesToRetrieve.uncheckedAppend(derivedCachedDataType.isolatedCopy());
     94
     95    // ThreadableLoaderOptions
     96    copy.preflightPolicy = this->preflightPolicy;
     97    copy.contentSecurityPolicyEnforcement = this->contentSecurityPolicyEnforcement;
     98    copy.initiator = this->initiator.isolatedCopy();
     99    copy.filteringPolicy = this->filteringPolicy;
     100
     101    return copy;
     102}
     103
     104
    63105RefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext& context, ThreadableLoaderClient& client, ResourceRequest&& request, const ThreadableLoaderOptions& options, String&& referrer)
    64106{
  • trunk/Source/WebCore/loader/ThreadableLoader.h

    r210828 r216553  
    6767        ~ThreadableLoaderOptions();
    6868
     69        ThreadableLoaderOptions isolatedCopy() const;
     70
    6971        PreflightPolicy preflightPolicy { ConsiderPreflight };
    7072        ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement { ContentSecurityPolicyEnforcement::EnforceConnectSrcDirective };
  • trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp

    r212993 r216553  
    9595
    9696LoaderTaskOptions::LoaderTaskOptions(const ThreadableLoaderOptions& options, const String& referrer, Ref<SecurityOrigin>&& origin)
    97     : options(options, options.preflightPolicy, options.contentSecurityPolicyEnforcement, options.initiator.isolatedCopy(), options.filteringPolicy)
     97    : options(options.isolatedCopy())
    9898    , referrer(referrer.isolatedCopy())
    9999    , origin(WTFMove(origin))
Note: See TracChangeset for help on using the changeset viewer.