Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support removeparam #15943

Merged
merged 5 commits into from
Dec 1, 2022
Merged

Support removeparam #15943

merged 5 commits into from
Dec 1, 2022

Conversation

antonok-edm
Copy link
Collaborator

Resolves brave/brave-browser#23927

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Save the following document as index.html and serve it using your preferred method (e.g. python -m http.server).

<html>
    <head></head>
    <body>
        <div id="qstring"></div>
        <a href="/?test2=false">/?test2=false</a>
        <a href="/?test=true">/?test=true</a>
        <a href="/?test=true&test2=false">/?test=true&test2=false</a>
        <script>
            const e = document.getElementById('qstring');
            e.innerText = document.location.search;
        </script>
    </body>
</html>

Add a custom rule to brave://settings/shields/filters corresponding to the location the HTML document is served from. For example, localhost:8000^$document,removeparam=test (modify localhost:8000 as necessary based on your hosting endpoint). Save the custom rules.

Open the page you served in a new tab of the browser. There are 3 links on the page. Click on each one in order and observe the following query string in the URL bar, as well as on the first line of the page:

  1. ?test2=false
  2. (empty)
  3. ?test2=false

@antonok-edm antonok-edm requested a review from fmarier November 15, 2022 01:03
@antonok-edm antonok-edm requested review from iefremov and a team as code owners November 15, 2022 01:03
@antonok-edm antonok-edm self-assigned this Nov 15, 2022
@github-actions github-actions bot added CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/run-network-audit Run network-audit labels Nov 15, 2022
@fmarier
Copy link
Member

fmarier commented Nov 15, 2022

Is this meant to replace the existing query filter? If so, we should make sure it passes the existing browser tests: https://github.com/brave/brave-core/blob/c7a229c7eb8a0c2ad4d2d799c3a7eac2a19da541/browser/net/brave_site_hacks_network_delegate_helper_browsertest.cc

@fmarier
Copy link
Member

fmarier commented Nov 15, 2022

@antonok-edm Can you point to the PR implementing the URL rewriting on the Rust side?

@antonok-edm
Copy link
Collaborator Author

antonok-edm commented Nov 15, 2022

@fmarier it's currently in brave/adblock-rust#235

(I will merge that and set the Cargo.toml entry to the official release before merging this PR)

@antonok-edm antonok-edm requested a review from a team as a code owner November 15, 2022 09:32
@antonok-edm antonok-edm force-pushed the removeparam branch 3 times, most recently from 961843f to 04b2956 Compare November 16, 2022 22:45
@fmarier
Copy link
Member

fmarier commented Nov 17, 2022

Is this meant to replace the existing query filter?

Just noting that the answer for this PR is no. This is adding support for custom lists and rules in order to get parity with uBlock Origin.

Using this support to migrate the existing query string filter to a list will be done in a separate PR.

@@ -110,7 +110,8 @@ class AdBlockService {
bool* did_match_rule,
bool* did_match_exception,
bool* did_match_important,
std::string* mock_data_url);
std::string* mock_data_url,
std::string* rewritten_url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should stop adding new params to this method and introduce a structure instead. Otherwise, it goes out of control - there is no single line of comment describing what is for what, and every new change touches a dozen of irrelevant files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we just need brave/brave-browser#5461, which I'm hoping to get to soon:tm:

or definitely at least before adding any further arguments to these methods

CancelDeferredNavigation(content::NavigationThrottle::ThrottleCheckResult(
content::NavigationThrottle::CANCEL));

const GURL new_url(new_url_spec);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if the url is valid

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


if (ctx->method == "GET" || ctx->method == "HEAD" ||
ctx->method == "OPTIONS") {
ctx->new_url_spec = rewritten_url;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check validity of the url?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also be worth checking that the scheme is HTTP/HTTPS?

Copy link
Collaborator Author

@antonok-edm antonok-edm Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@fmarier I think we want it to be able to apply to WS/WSS as well. But anyways, unsupported schemes are already not even passed to the adblock engine so it should be alright here.

// technically this is a new navigation
params.redirect_chain.clear();

base::SequencedTaskRunnerHandle::Get()->PostTask(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this approach to filtering is potentially suboptimal, but we can keep it as is as long the filter list consists of really small set of entries

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iefremov What did you have in mind in term of a "really small set of entries"?

Here's an example list a user could add: https://github.com/AdguardTeam/FiltersRegistry/blob/master/filters/filter_17_TrackParam/filter.txt

@antonok-edm antonok-edm enabled auto-merge December 1, 2022 02:56
@antonok-edm antonok-edm merged commit 523f4fd into master Dec 1, 2022
@antonok-edm antonok-edm deleted the removeparam branch December 1, 2022 04:37
@github-actions github-actions bot added this to the 1.48.x - Nightly milestone Dec 1, 2022
brave-builds pushed a commit that referenced this pull request Dec 6, 2022
@kjozwiak
Copy link
Member

kjozwiak commented Dec 9, 2022

Verification PASSED on Win 11 x64 using the following build(s):

Brave | 1.48.40 Chromium: 108.0.5359.99 (Official Build) nightly (64-bit)
-- | --
Revision | 410951fc34bb4b2cbf182231f9f779efaafaf682-refs/branch-heads/5359_71@{#9}
OS | Windows 11 Version 22H2 (Build 22621.900)

Using the STR/Cases outlined via #15943 (comment), went through the following:

Setup http://localhost:8000 & added custom filter

Example Example
serverRunning filterlist

Clicking on links via http://localhost:8000/index.html

Link #1 (?test2=false) Link #2 (Blank) Link #3 (?test2=false)
link1 link2 link3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/run-network-audit Run network-audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for $removeparam filter syntax
6 participants