Bug 146868 - unless-domain and if-domain in Content Blocker don't appear to work
Summary: unless-domain and if-domain in Content Blocker don't appear to work
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 525.x (Safari 3.2)
Hardware: iPhone / iPad Other
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-07-10 19:29 PDT by Michael
Modified: 2015-07-14 10:38 PDT (History)
8 users (show)

See Also:


Attachments
Patch (6.12 KB, patch)
2015-07-13 13:39 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (9.35 KB, patch)
2015-07-13 14:12 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-mavericks-wk2 (818.23 KB, application/zip)
2015-07-13 14:31 PDT, Build Bot
no flags Details
Patch (10.96 KB, patch)
2015-07-13 14:59 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (12.60 KB, patch)
2015-07-13 15:58 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (14.66 KB, patch)
2015-07-14 10:05 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2015-07-10 19:29:46 PDT
I am playing with the new Content Blocker extensions on iOS 9 beta 2/3 using Xcode 7.0 beta 2/3 and an iPhone 6. 

I was trying to block all webpages except those of white-listed domains. I thought this should do it:

[
    {
        "action": {
            "type": "block"
        },
        "trigger": {
            "url-filter": ".*",
            "unless-domain": ["apple.com"]
        }
    }
]

I would expect this to block all domains except Apple from loading, but instead all domains are blocked.

If I change it to:

[
    {
        "action": {
            "type": "block"
        },
        "trigger": {
            "url-filter": ".*",
            "if-domain": ["apple.com"]
        }
    }
]

I would expect only Apple to be blocked while all other domains load correctly, but instead all domains including Apple load. 

My apologies if I'm missing something obvious; I'm brand new to programming.
Comment 1 Michael 2015-07-10 19:35:33 PDT
I should add that the reason I was using unless-domain rather than doing something like 

[
    {
        "action": {
            "type": "block"
        },
        "trigger": {
            "url-filter": "apple.com"
        }
    }
]

Was in order to create an array of either black-listed or white-listed domains using unless/if-domain.
Comment 2 Benjamin Poulain 2015-07-11 11:41:51 PDT
I can reproduce locally. Even with "unless-domain": ["*apple.com"], apple.com is blocked in minibrowser.
Comment 3 Radar WebKit Bug Importer 2015-07-11 11:42:09 PDT
<rdar://problem/21782350>
Comment 4 Alex Christensen 2015-07-13 13:39:43 PDT
Created attachment 256718 [details]
Patch
Comment 5 Alex Christensen 2015-07-13 14:12:30 PDT
Created attachment 256722 [details]
Patch
Comment 6 Build Bot 2015-07-13 14:31:48 PDT
Comment on attachment 256722 [details]
Patch

Attachment 256722 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6175807298863104

New failing tests:
http/tests/contentextensions/sync-xhr-blocked.html
http/tests/contentextensions/domain-rules.html
http/tests/contentextensions/basic-filter.html
http/tests/contentextensions/filters-with-quantifiers-combined.html
http/tests/contentextensions/block-everything-unless-domain.html
Comment 7 Build Bot 2015-07-13 14:31:50 PDT
Created attachment 256728 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 8 Alex Christensen 2015-07-13 14:59:38 PDT
Created attachment 256731 [details]
Patch
Comment 9 Alex Christensen 2015-07-13 15:58:14 PDT
Created attachment 256738 [details]
Patch
Comment 10 Benjamin Poulain 2015-07-13 18:26:47 PDT
Comment on attachment 256738 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=256738&action=review

Thanks for fixing this!

> Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:176
> +            mainDocumentURL = request.url();

What happen when the main request is a redirect? Will the next branch take over and give the right URL (the final one)?

Can you add test coverage for that too?
Comment 11 Alex Christensen 2015-07-14 10:05:19 PDT
Created attachment 256773 [details]
Patch
Comment 12 Alex Christensen 2015-07-14 10:06:45 PDT
Comment on attachment 256773 [details]
Patch

Added block-everything-unless-domain-redirect.php
Comment 13 WebKit Commit Bot 2015-07-14 10:38:06 PDT
Comment on attachment 256773 [details]
Patch

Clearing flags on attachment: 256773

Committed r186807: <http://trac.webkit.org/changeset/186807>
Comment 14 WebKit Commit Bot 2015-07-14 10:38:10 PDT
All reviewed patches have been landed.  Closing bug.