Changeset 286041 in webkit


Ignore:
Timestamp:
Nov 18, 2021 5:35:35 PM (2 years ago)
Author:
achristensen@apple.com
Message:

Allow all redirect schemes when compiling a content rule list
https://bugs.webkit.org/show_bug.cgi?id=233338

Reviewed by Tim Hatcher.

Source/WebCore:

What was I thinking? I made an SPI that gives you a set of allowed redirect schemes
from the same source as the JSON which contains those redirect schemes. This allows
all redirect schemes. If you want to prevent redirecting to a certain scheme, then
don't compile JSON that redirects to that scheme. We may want a helper function that
uses the same parser to get the set of schemes being redirected to, but right now that
is not necessary because the JSON is being assembled by a program that has the ability
to check the schemes.

  • contentextensions/ContentExtensionActions.cpp:

(WebCore::ContentExtensions::RedirectAction::parse):
(WebCore::ContentExtensions::RedirectAction::URLTransformAction::parse):

  • contentextensions/ContentExtensionActions.h:
  • contentextensions/ContentExtensionCompiler.cpp:

(WebCore::ContentExtensions::compileRuleList):

  • contentextensions/ContentExtensionError.cpp:

(WebCore::ContentExtensions::contentExtensionErrorCategory):

  • contentextensions/ContentExtensionError.h:
  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::loadAction):
(WebCore::ContentExtensions::loadRule):
(WebCore::ContentExtensions::loadEncodedRules):
(WebCore::ContentExtensions::parseRuleList):

  • contentextensions/ContentExtensionParser.h:

Source/WebKit:

  • UIProcess/API/APIContentRuleListStore.cpp:

(API::ContentRuleListStore::lookupContentRuleList):
(API::ContentRuleListStore::compileContentRuleList):

  • UIProcess/API/APIContentRuleListStore.h:
  • UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:

(WKUserContentExtensionStoreCompile):

  • UIProcess/API/Cocoa/WKContentRuleListStore.mm:

(-[WKContentRuleListStore compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler:]):
(-[WKContentRuleListStore _compileContentRuleListForIdentifier:encodedContentRuleList:allowedRedirectSchemes:completionHandler:]): Deleted.

  • UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h:
  • UIProcess/API/glib/WebKitUserContentFilterStore.cpp:

(webkitUserContentFilterStoreSaveBytes):

Tools:

  • TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:

(TestWebKitAPI::InMemoryCompiledContentExtension::create):
(TestWebKitAPI::checkCompilerError):
(TestWebKitAPI::TEST_F):

  • TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:

(compileContentRuleList):

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286039 r286041  
     12021-11-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow all redirect schemes when compiling a content rule list
     4        https://bugs.webkit.org/show_bug.cgi?id=233338
     5
     6        Reviewed by Tim Hatcher.
     7
     8        What was I thinking?  I made an SPI that gives you a set of allowed redirect schemes
     9        from the same source as the JSON which contains those redirect schemes.  This allows
     10        all redirect schemes.  If you want to prevent redirecting to a certain scheme, then
     11        don't compile JSON that redirects to that scheme.  We may want a helper function that
     12        uses the same parser to get the set of schemes being redirected to, but right now that
     13        is not necessary because the JSON is being assembled by a program that has the ability
     14        to check the schemes.
     15
     16        * contentextensions/ContentExtensionActions.cpp:
     17        (WebCore::ContentExtensions::RedirectAction::parse):
     18        (WebCore::ContentExtensions::RedirectAction::URLTransformAction::parse):
     19        * contentextensions/ContentExtensionActions.h:
     20        * contentextensions/ContentExtensionCompiler.cpp:
     21        (WebCore::ContentExtensions::compileRuleList):
     22        * contentextensions/ContentExtensionError.cpp:
     23        (WebCore::ContentExtensions::contentExtensionErrorCategory):
     24        * contentextensions/ContentExtensionError.h:
     25        * contentextensions/ContentExtensionParser.cpp:
     26        (WebCore::ContentExtensions::loadAction):
     27        (WebCore::ContentExtensions::loadRule):
     28        (WebCore::ContentExtensions::loadEncodedRules):
     29        (WebCore::ContentExtensions::parseRuleList):
     30        * contentextensions/ContentExtensionParser.h:
     31
    1322021-11-18  Chris Dumez  <cdumez@apple.com>
    233
  • trunk/Source/WebCore/contentextensions/ContentExtensionActions.cpp

    r285980 r286041  
    280280}
    281281
    282 Expected<RedirectAction, std::error_code> RedirectAction::parse(const JSON::Object& redirectObject, const std::optional<HashSet<String>>& allowedRedirectURLSchemes)
     282Expected<RedirectAction, std::error_code> RedirectAction::parse(const JSON::Object& redirectObject)
    283283{
    284284    auto redirect = redirectObject.getObject("redirect");
     
    296296
    297297    if (auto transform = redirect->getObject("transform")) {
    298         auto parsedTransform = URLTransformAction::parse(*transform, allowedRedirectURLSchemes);
     298        auto parsedTransform = URLTransformAction::parse(*transform);
    299299        if (!parsedTransform)
    300300            return makeUnexpected(parsedTransform.error());
     
    306306        if (!url.isValid())
    307307            return makeUnexpected(ContentExtensionError::JSONRedirectURLInvalid);
    308         if (allowedRedirectURLSchemes && !allowedRedirectURLSchemes->contains(url.protocol().toStringWithoutCopying()))
    309             return makeUnexpected(ContentExtensionError::JSONRedirectURLSchemeNotAllowed);
     308        if (url.protocolIsJavaScript())
     309            return makeUnexpected(ContentExtensionError::JSONRedirectToJavaScriptURL);
    310310        return RedirectAction { URLAction { WTFMove(urlString) } };
    311311    }
     
    384384}
    385385
    386 auto RedirectAction::URLTransformAction::parse(const JSON::Object& transform, const std::optional<HashSet<String>>& allowedRedirectURLSchemes) -> Expected<URLTransformAction, std::error_code>
     386auto RedirectAction::URLTransformAction::parse(const JSON::Object& transform) -> Expected<URLTransformAction, std::error_code>
    387387{
    388388    URLTransformAction action;
     
    411411        if (!scheme)
    412412            return makeUnexpected(ContentExtensionError::JSONRedirectURLSchemeInvalid);
    413         if (allowedRedirectURLSchemes && !allowedRedirectURLSchemes->contains(*scheme))
    414             return makeUnexpected(ContentExtensionError::JSONRedirectURLSchemeNotAllowed);
     413        if (scheme == "javascript")
     414            return makeUnexpected(ContentExtensionError::JSONRedirectToJavaScriptURL);
    415415        action.scheme = WTFMove(*scheme);
    416416    }
  • trunk/Source/WebCore/contentextensions/ContentExtensionActions.h

    r285980 r286041  
    208208
    209209        uint32_t hash() const { return computeHash(fragment.hash(), host.hash(), password.hash(), path.hash(), port, VariantHasher::hash(queryTransform), scheme.hash(), username.hash()); }
    210         static Expected<URLTransformAction, std::error_code> parse(const JSON::Object&, const std::optional<HashSet<String>>&);
     210        static Expected<URLTransformAction, std::error_code> parse(const JSON::Object&);
    211211        URLTransformAction isolatedCopy() const;
    212212        bool operator==(const URLTransformAction&) const;
     
    239239    uint32_t hash() const { return VariantHasher::hash(action); }
    240240
    241     static Expected<RedirectAction, std::error_code> parse(const JSON::Object&, const std::optional<HashSet<String>>&);
     241    static Expected<RedirectAction, std::error_code> parse(const JSON::Object&);
    242242    RedirectAction isolatedCopy() const;
    243243    bool operator==(const RedirectAction&) const;
  • trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp

    r285980 r286041  
    276276#if ASSERT_ENABLED
    277277    callOnMainThread([ruleJSON = ruleJSON.isolatedCopy(), parsedRuleList = parsedRuleList.isolatedCopy()] {
    278         ASSERT(parseRuleList(ruleJSON, std::nullopt).value() == parsedRuleList);
     278        ASSERT(parseRuleList(ruleJSON).value() == parsedRuleList);
    279279    });
    280280#endif
  • trunk/Source/WebCore/contentextensions/ContentExtensionError.cpp

    r285980 r286041  
    102102            case ContentExtensionError::JSONRedirectExtensionPathDoesNotStartWithSlash:
    103103                return "A redirect extension path must start with a slash";
    104             case ContentExtensionError::JSONRedirectURLSchemeNotAllowed:
    105                 return "A redirect url scheme must be in the set of allowed schemes";
    106104            case ContentExtensionError::JSONRedirectURLSchemeInvalid:
    107105                return "A redirect url scheme must be a valid scheme";
    108             case ContentExtensionError::JSONRedirectURLSchemesShouldNotIncludeJavascript:
    109                 return "The set of allowed redirect schemes shouldn't include javascript";
     106            case ContentExtensionError::JSONRedirectToJavaScriptURL:
     107                return "A redirect url can't have a scheme of javascript";
    110108            case ContentExtensionError::JSONRedirectURLInvalid:
    111109                return "A redirect url must be valid";
  • trunk/Source/WebCore/contentextensions/ContentExtensionError.h

    r285980 r286041  
    6262    JSONRedirectExtensionPathDoesNotStartWithSlash,
    6363    JSONRedirectURLSchemeInvalid,
    64     JSONRedirectURLSchemeNotAllowed,
    65     JSONRedirectURLSchemesShouldNotIncludeJavascript,
     64    JSONRedirectToJavaScriptURL,
    6665    JSONRedirectURLInvalid,
    6766    JSONRedirectInvalidType,
  • trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp

    r285980 r286041  
    180180}
    181181
    182 static std::optional<Expected<Action, std::error_code>> loadAction(const JSON::Object& ruleObject, const std::optional<HashSet<String>>& allowedRedirectURLSchemes)
     182static std::optional<Expected<Action, std::error_code>> loadAction(const JSON::Object& ruleObject)
    183183{
    184184    auto actionObject = ruleObject.getObject("action");
     
    211211    }
    212212    if (actionType == "redirect") {
    213         auto action = RedirectAction::parse(*actionObject, allowedRedirectURLSchemes);
     213        auto action = RedirectAction::parse(*actionObject);
    214214        if (!action)
    215215            return makeUnexpected(action.error());
     
    225225}
    226226
    227 static std::optional<Expected<ContentExtensionRule, std::error_code>> loadRule(const JSON::Object& ruleObject, const std::optional<HashSet<String>>& allowedRedirectURLSchemes)
     227static std::optional<Expected<ContentExtensionRule, std::error_code>> loadRule(const JSON::Object& ruleObject)
    228228{
    229229    auto trigger = loadTrigger(ruleObject);
     
    231231        return makeUnexpected(trigger.error());
    232232
    233     auto action = loadAction(ruleObject, allowedRedirectURLSchemes);
     233    auto action = loadAction(ruleObject);
    234234    if (!action)
    235235        return std::nullopt;
     
    240240}
    241241
    242 static Expected<Vector<ContentExtensionRule>, std::error_code> loadEncodedRules(const String& ruleJSON, const std::optional<HashSet<String>>& allowedRedirectURLSchemes)
    243 {
    244     if (allowedRedirectURLSchemes && allowedRedirectURLSchemes->contains("javascript"))
    245         return makeUnexpected(ContentExtensionError::JSONRedirectURLSchemesShouldNotIncludeJavascript);
    246 
     242static Expected<Vector<ContentExtensionRule>, std::error_code> loadEncodedRules(const String& ruleJSON)
     243{
    247244    auto decodedRules = JSON::Value::parseJSON(ruleJSON);
    248245
     
    265262            return makeUnexpected(ContentExtensionError::JSONInvalidRule);
    266263
    267         auto rule = loadRule(*ruleObject, allowedRedirectURLSchemes);
     264        auto rule = loadRule(*ruleObject);
    268265        if (!rule)
    269266            continue;
     
    276273}
    277274
    278 Expected<Vector<ContentExtensionRule>, std::error_code> parseRuleList(const String& ruleJSON, const std::optional<HashSet<String>>& allowedRedirectURLSchemes)
     275Expected<Vector<ContentExtensionRule>, std::error_code> parseRuleList(const String& ruleJSON)
    279276{
    280277#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
     
    282279#endif
    283280
    284     auto ruleList = loadEncodedRules(ruleJSON, allowedRedirectURLSchemes);
     281    auto ruleList = loadEncodedRules(ruleJSON);
    285282
    286283    if (!ruleList.has_value())
  • trunk/Source/WebCore/contentextensions/ContentExtensionParser.h

    r285980 r286041  
    3939class ContentExtensionRule;
    4040
    41 // An allowedRedirectURLSchemes of std::nullopt indicates that all URL schemes are allowed.
    42 // This is used when recompiling source from older versions of WKContentRuleLists on disk,
    43 // where we don't have the list of allowed URL schemes but assume that if it compiled
    44 // successfully the first time then all the schemes used must have been allowed.
    45 // An allowedRedirectURLSchemes of an empty HashSet indicates that no active actions are allowed.
    46 WEBCORE_EXPORT Expected<Vector<ContentExtensionRule>, std::error_code> parseRuleList(const String&, const std::optional<HashSet<String>>& allowedRedirectURLSchemes);
     41WEBCORE_EXPORT Expected<Vector<ContentExtensionRule>, std::error_code> parseRuleList(const String&);
    4742WEBCORE_EXPORT bool isValidCSSSelector(const String&);
    4843
  • trunk/Source/WebKit/ChangeLog

    r286037 r286041  
     12021-11-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow all redirect schemes when compiling a content rule list
     4        https://bugs.webkit.org/show_bug.cgi?id=233338
     5
     6        Reviewed by Tim Hatcher.
     7
     8        * UIProcess/API/APIContentRuleListStore.cpp:
     9        (API::ContentRuleListStore::lookupContentRuleList):
     10        (API::ContentRuleListStore::compileContentRuleList):
     11        * UIProcess/API/APIContentRuleListStore.h:
     12        * UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:
     13        (WKUserContentExtensionStoreCompile):
     14        * UIProcess/API/Cocoa/WKContentRuleListStore.mm:
     15        (-[WKContentRuleListStore compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler:]):
     16        (-[WKContentRuleListStore _compileContentRuleListForIdentifier:encodedContentRuleList:allowedRedirectSchemes:completionHandler:]): Deleted.
     17        * UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h:
     18        * UIProcess/API/glib/WebKitUserContentFilterStore.cpp:
     19        (webkitUserContentFilterStoreSaveBytes):
     20
    1212021-11-18  Per Arne Vollan <pvollan@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

    r285980 r286041  
    492492            if (auto sourceFromOldVersion = getContentRuleListSourceFromMappedFile(*contentRuleList); !sourceFromOldVersion.isEmpty()) {
    493493                RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), sourceFromOldVersion = sourceFromOldVersion.isolatedCopy(), identifier = identifier.isolatedCopy(), completionHandler = WTFMove(completionHandler)] () mutable {
    494                     protectedThis->compileContentRuleList(identifier, WTFMove(sourceFromOldVersion), std::nullopt, WTFMove(completionHandler));
     494                    protectedThis->compileContentRuleList(identifier, WTFMove(sourceFromOldVersion), WTFMove(completionHandler));
    495495                });
    496496                return;
     
    531531}
    532532
    533 void ContentRuleListStore::compileContentRuleList(const WTF::String& identifier, WTF::String&& json, std::optional<HashSet<WTF::String>>&& allowedRedirectSchemes, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)> completionHandler)
     533void ContentRuleListStore::compileContentRuleList(const WTF::String& identifier, WTF::String&& json, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)> completionHandler)
    534534{
    535535    ASSERT(RunLoop::isMain());
     
    537537    WebCore::QualifiedName::init();
    538538   
    539     auto parsedRules = WebCore::ContentExtensions::parseRuleList(json, WTFMove(allowedRedirectSchemes));
     539    auto parsedRules = WebCore::ContentExtensions::parseRuleList(json);
    540540    if (!parsedRules.has_value())
    541541        return completionHandler(nullptr, parsedRules.error());
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h

    r285980 r286041  
    6767    virtual ~ContentRuleListStore();
    6868
    69     void compileContentRuleList(const WTF::String& identifier, WTF::String&& json, std::optional<HashSet<WTF::String>>&& allowedRedirectSchemes, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)>);
     69    void compileContentRuleList(const WTF::String& identifier, WTF::String&& json, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)>);
    7070    void lookupContentRuleList(const WTF::String& identifier, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)>);
    7171    void removeContentRuleList(const WTF::String& identifier, CompletionHandler<void(std::error_code)>);
  • trunk/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp

    r285980 r286041  
    7777{
    7878#if ENABLE(CONTENT_EXTENSIONS)
    79     toImpl(store)->compileContentRuleList(toWTFString(identifier), toWTFString(jsonSource), { HashSet<String>() }, [context, callback](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
     79    toImpl(store)->compileContentRuleList(toWTFString(identifier), toWTFString(jsonSource), [context, callback](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
    8080        callback(error ? nullptr : toAPI(contentRuleList.leakRef()), toResult(error), context);
    8181    });
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStore.mm

    r285980 r286041  
    8888- (void)compileContentRuleListForIdentifier:(NSString *)identifier encodedContentRuleList:(NSString *)encodedContentRuleList completionHandler:(void (^)(WKContentRuleList *, NSError *))completionHandler
    8989{
    90     [self _compileContentRuleListForIdentifier:identifier encodedContentRuleList:encodedContentRuleList allowedRedirectSchemes:nil completionHandler:completionHandler];
     90#if ENABLE(CONTENT_EXTENSIONS)
     91    _contentRuleListStore->compileContentRuleList(identifier, encodedContentRuleList, [completionHandler = makeBlockPtr(completionHandler)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
     92        if (error) {
     93            auto userInfo = @{ NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Rule list compilation failed: %s", error.message().c_str()] };
     94
     95            // error.value() could have a specific compiler error that is not equal to WKErrorContentRuleListStoreCompileFailed.
     96            // We want to use error.message, but here we want to only pass on CompileFailed with userInfo from the std::error_code.
     97            return completionHandler(nil, [NSError errorWithDomain:WKErrorDomain code:WKErrorContentRuleListStoreCompileFailed userInfo:userInfo]);
     98        }
     99        completionHandler(wrapper(*contentRuleList), nil);
     100    });
     101#endif
    91102}
    92103
     
    172183}
    173184
    174 - (void)_compileContentRuleListForIdentifier:(NSString *)identifier encodedContentRuleList:(NSString *)encodedContentRuleList allowedRedirectSchemes:(NSSet<NSString *> *)schemes completionHandler:(void (^)(WKContentRuleList *, NSError *))completionHandler
    175 {
    176 #if ENABLE(CONTENT_EXTENSIONS)
    177     HashSet<String> allowedRedirectSchemes;
    178     for (NSString *scheme in schemes)
    179         allowedRedirectSchemes.add(scheme);
    180     _contentRuleListStore->compileContentRuleList(identifier, encodedContentRuleList, WTFMove(allowedRedirectSchemes), [completionHandler = makeBlockPtr(completionHandler)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
    181         if (error) {
    182             auto userInfo = @{NSHelpAnchorErrorKey: [NSString stringWithFormat:@"Rule list compilation failed: %s", error.message().c_str()]};
    183 
    184             // error.value() could have a specific compiler error that is not equal to WKErrorContentRuleListStoreCompileFailed.
    185             // We want to use error.message, but here we want to only pass on CompileFailed with userInfo from the std::error_code.
    186             return completionHandler(nil, [NSError errorWithDomain:WKErrorDomain code:WKErrorContentRuleListStoreCompileFailed userInfo:userInfo]);
    187         }
    188         completionHandler(wrapper(*contentRuleList), nil);
    189     });
    190 #endif
    191 }
    192 
    193185+ (instancetype)defaultStoreWithLegacyFilename
    194186{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h

    r285980 r286041  
    3333- (void)_getContentRuleListSourceForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSString *))completionHandler;
    3434
    35 - (void)_compileContentRuleListForIdentifier:(NSString *)identifier encodedContentRuleList:(NSString *)encodedContentRuleList allowedRedirectSchemes:(NSSet<NSString *> *)schemes completionHandler:(void (^)(WKContentRuleList *, NSError *))completionHandler;
    36 
    3735// FIXME: Remove _WKUserContentExtensionStore.
    3836+ (instancetype)defaultStoreWithLegacyFilename;
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitUserContentFilterStore.cpp

    r285980 r286041  
    188188
    189189    auto* store = WEBKIT_USER_CONTENT_FILTER_STORE(g_task_get_source_object(task.get()));
    190     store->priv->store->compileContentRuleList(identifier, String::fromUTF8(sourceData, sourceSize), { HashSet<String>() }, [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
     190    store->priv->store->compileContentRuleList(identifier, String::fromUTF8(sourceData, sourceSize), [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
    191191        if (g_task_return_error_if_cancelled(task.get()))
    192192            return;
  • trunk/Tools/ChangeLog

    r286040 r286041  
     12021-11-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Allow all redirect schemes when compiling a content rule list
     4        https://bugs.webkit.org/show_bug.cgi?id=233338
     5
     6        Reviewed by Tim Hatcher.
     7
     8        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
     9        (TestWebKitAPI::InMemoryCompiledContentExtension::create):
     10        (TestWebKitAPI::checkCompilerError):
     11        (TestWebKitAPI::TEST_F):
     12        * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:
     13        (compileContentRuleList):
     14
    1152021-11-18  Robert Jenner  <Jenner@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

    r285980 r286041  
    132132        CompiledContentExtensionData extensionData;
    133133        InMemoryContentExtensionCompilationClient client(extensionData);
    134         auto parsedRules = ContentExtensions::parseRuleList(filter, std::nullopt);
     134        auto parsedRules = ContentExtensions::parseRuleList(filter);
    135135        auto compilerError = ContentExtensions::compileRuleList(client, WTFMove(filter), WTFMove(parsedRules.value()));
    136136
     
    13631363}
    13641364
    1365 void checkCompilerError(const char* json, std::error_code expectedError, const std::optional<HashSet<String>>& allowedRedirectURLSchemes = std::nullopt)
     1365void checkCompilerError(const char* json, std::error_code expectedError)
    13661366{
    13671367    CompiledContentExtensionData extensionData;
    13681368    InMemoryContentExtensionCompilationClient client(extensionData);
    1369     auto parsedRules = ContentExtensions::parseRuleList(json, allowedRedirectURLSchemes);
     1369    auto parsedRules = ContentExtensions::parseRuleList(json);
    13701370    std::error_code compilerError;
    13711371    if (parsedRules.has_value())
     
    15331533    checkCompilerError("[{\"action\":{\"type\":\"css-display-none\"},\"trigger\":{\"url-filter\":\"webkit.org\"}}]",
    15341534        ContentExtensionError::JSONInvalidCSSDisplayNoneActionType);
    1535     checkCompilerError("", ContentExtensionError::JSONRedirectURLSchemesShouldNotIncludeJavascript, { { "javascript" } });
    15361535
    15371536    checkCompilerError("[{\"action\":{\"type\":\"ignore-previous-rules\"},\"trigger\":{\"url-filter\":\"webkit.org\"}},"
     
    15621561    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"query-transform\":{\"add-or-replace-parameters\":[{\"key\":5}]}}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONAddOrReplaceParametersKeyValueMissingKeyString);
    15631562    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"query-transform\":{\"add-or-replace-parameters\":[{\"key\":\"k\",\"value\":5}]}}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONAddOrReplaceParametersKeyValueMissingValueString);
    1564     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"about:blank\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectURLSchemeNotAllowed, { { "not-about" } });
    1565     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"about:blank\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { }, { { "about" } });
    1566     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"https://127..1/\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectURLInvalid, { { "https" } });
    1567     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"about:blank\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { }, { { "about" } });
     1563    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"https://127..1/\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectURLInvalid);
     1564    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"url\":\"JaVaScRiPt:dostuff\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectToJavaScriptURL);
    15681565    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"port\":\"not a number\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectInvalidPort);
    15691566    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"port\":\"65536\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectInvalidPort);
     
    15731570    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"port\":\"\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { });
    15741571    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"extension-path\":\"/does/start/with/slash/\"}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { });
    1575     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"scheme\":\"about\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectURLSchemeNotAllowed, { { "not-about" } });
    15761572    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"scheme\":\"!@#$%\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectURLSchemeInvalid);
    1577     checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"scheme\":\"About\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { }, { { "about" } });
     1573    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"scheme\":\"JaVaScRiPt\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONRedirectToJavaScriptURL);
     1574    checkCompilerError("[{\"action\":{\"type\":\"redirect\",\"redirect\":{\"transform\":{\"scheme\":\"About\"}}},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", { });
    15781575    checkCompilerError("[{\"action\":{\"type\":\"modify-headers\",\"request-headers\":5},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONModifyHeadersNotArray);
    15791576    checkCompilerError("[{\"action\":{\"type\":\"modify-headers\",\"request-headers\":[5]},\"trigger\":{\"url-filter\":\"webkit.org\"}}]", ContentExtensionError::JSONModifyHeadersInfoNotADictionary);
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm

    r285980 r286041  
    485485
    486486    __block RetainPtr<WKContentRuleList> list;
    487     [[WKContentRuleListStore defaultStore] _compileContentRuleListForIdentifier:@"testidentifier" encodedContentRuleList:[NSString stringWithFormat:@"%s", json] allowedRedirectSchemes:[NSSet setWithObjects:@"testscheme", @"othertestscheme", nil] completionHandler:^(WKContentRuleList *filter, NSError *error) {
     487    [[WKContentRuleListStore defaultStore] compileContentRuleListForIdentifier:@"testidentifier" encodedContentRuleList:[NSString stringWithFormat:@"%s", json] completionHandler:^(WKContentRuleList *filter, NSError *error) {
    488488        EXPECT_NULL(error);
    489489        list = filter;
Note: See TracChangeset for help on using the changeset viewer.