Opened 9 months ago

Closed 9 months ago

Last modified 4 months ago

#7294 closed change (fixed)

Implement strip-fetch-query-parameter snippet

Reported by: mjethani Assignee: agiammarchi
Priority: P2 Milestone:
Module: Core Keywords: circumvention
Cc: sebastian Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

https://gitlab.com/eyeo/adblockplus/adblockpluscore/merge_requests/23
https://codereview.adblockplus.org/30013555/

Description (last modified by mjethani)

Background

In some cases we need to strip parameters from the query string of a URL while letting the request through. This is not always possible using the $rewrite option, especially with preflight OPTIONS requests, because doing so invalidates the request (307 Temporary Redirect). A snippet that wraps fetch() to strip out the given query string parameter would be handy.

What to change

Implement a snippet called strip-fetch-query-parameter with the following signature:

function stripFetchQueryParameter(name, urlPattern = null)

name should be the unencoded name of the parameter. For example, in the query string ?first%20name=John, the parameter name is first name (space).

The optional urlPattern can be a literal string or a pattern (regular expression surrounded by /) that the URL must match. If null, the snippet should work for any URL.

Hints for testers

Try the following document:

<!DOCTYPE html>
<html>
  <body>
    <script>
      setTimeout(() =>
      {
        fetch("https://example.com/?foo=1&bar=2");
      },
      500);
    </script>
  </body>
</html>

The filter #$#strip-fetch-query-parameter foo example should cause the request to go to https://example.com/?bar=2 (foo is dropped). The filter #$#strip-fetch-query-parameter foo too should do the same.

The filter #$#strip-fetch-query-parameter bar other should cause the request to go to https://example.com/?foo=1&bar=2 (bar is not dropped).

Change History (15)

comment:1 Changed 9 months ago by abpbot

A commit referencing this issue has landed:
Issue 7294 - Implement strip-fetch-query-parameter snippet

comment:2 Changed 9 months ago by mjethani

  • Owner set to agiammarchi

comment:3 Changed 9 months ago by mjethani

  • Review URL(s) modified (diff)

comment:4 Changed 9 months ago by mjethani

  • Description modified (diff)

comment:5 Changed 9 months ago by mjethani

  • Review URL(s) modified (diff)

comment:6 Changed 9 months ago by mjethani

  • Status changed from new to reviewing

comment:7 Changed 9 months ago by abpbot

comment:8 Changed 9 months ago by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:10 Changed 8 months ago by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Implemented and working in the browsers listed below. However it does not appear to work in Chrome 49 (#7407), Edge (#7409) or Firefox Mobile (#7410).

ABP 2.5.0.2282
Chrome 73.0.3683.86 / Windows 10
Firefox 65.0.1 / Windows 10
Firefox 51.0 / Windows 10
Opera 58.0.3135.118 / Windows 10

comment:11 Changed 8 months ago by agiammarchi

Most likely 'cause they don't have fetch to start with, so that the page would throw errors regardless ?

comment:12 Changed 8 months ago by sebastian

  • Cc sebastian added

According to MDN, all these browsers support the fetch() API.

comment:13 Changed 8 months ago by agiammarchi

I think Manish found the issue with the URL searchParams

comment:14 Changed 7 months ago by mjethani

  • Sensitive unset

comment:15 Changed 4 months ago by Ross

Done. Working as described. Now works in Chrome 49/Edge/Firefox Mobile.

ABP 0.9.15.2340
Microsoft Edge 44.17763.1.0 / Windows 10 1809

ABP 3.5.2.2340
Chrome 49.0.2623.75 / Windows 10 1809
Chrome 75.0.3770.142 / Windows 10 1809
Opera 36.0.2130.65 / Windows 10 1809
Opera 62.0.3331.72 / Windows 10 1809
Firefox 51.0 / Windows 10 1809
Firefox 68.0 / Windows 10 1809
Firefox Mobile 68.0 / Android 7.2.2

Note: See TracTickets for help on using tickets.