Opened 2 months ago

Closed 2 months ago

Last modified 3 weeks 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 (14)

comment:1 Changed 2 months ago by abpbot

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

comment:2 Changed 2 months ago by mjethani

  • Owner set to agiammarchi

comment:3 Changed 2 months ago by mjethani

  • Review URL(s) modified (diff)

comment:4 Changed 2 months ago by mjethani

  • Description modified (diff)

comment:5 Changed 2 months ago by mjethani

  • Review URL(s) modified (diff)

comment:6 Changed 2 months ago by mjethani

  • Status changed from new to reviewing

comment:7 Changed 2 months ago by abpbot

comment:8 Changed 2 months ago by mjethani

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

comment:10 Changed 4 weeks 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 4 weeks 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 4 weeks ago by sebastian

  • Cc sebastian added

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

comment:13 Changed 4 weeks ago by agiammarchi

I think Manish found the issue with the URL searchParams

comment:14 Changed 3 weeks ago by mjethani

  • Sensitive unset
Note: See TracTickets for help on using tickets.