Closed Bug 1631587 Opened 6 years ago Closed 6 years ago

webRequest.filterResponseData does not seem to work with 302-redirected scripts

Categories

(WebExtensions :: Request Handling, defect, P3)

66 Branch
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1595197

People

(Reporter: twisniewski, Unassigned)

Details

Attachments

(1 file, 1 obsolete file)

I set up a minimal server which 302-redirects the script test.js to test.1234.js, and loads it in a minimal HTML page like this:

<script src="http://localhost/test.js"></script>

Then I made a minimal webExtension which filter-rewrites test.js and test.1234.js, but it does not end up working:

"use strict";
  
function block(request) {
  const { frameId, tabId, url, requestId } = request;
  console.log("SHIMMING", url, requestId, "on", tabId, "(", frameId, ")");
  const filter = browser.webRequest.filterResponseData(requestId);
  filter.onerror = function() {
    console.log("ERROR", arguments);
  };
  filter.onstart = async event => {
    const script = `console.log("OVERRULED!");`
    filter.write(new Uint8Array(new TextEncoder("utf-8").encode(script)));
    filter.close();
    console.log("FILTERED", script);
  };
  return {};
}   

chrome.webRequest.onBeforeRequest.addListener(
  block,
  {urls: ["http://localhost/test.js",
          "http://localhost/test.1234.js"]},
  ["blocking"]
);

In the network panel I see the test.js request being redirected to test.1234.js. In my add-ons background page, I see both requests are being intercepted, and apparently the filter applies to test.1234.js, but I see this in the console when I visit the minimal HTML page above:

Loading failed for the <script> with source “http://localhost/test.js”.

It doesn't appear to be my server config; I get the same results when I try to filter https://www.instagram.com/embed.js on a page like this one, which currently 302-redirects to https://www.instagram.com/static/bundles/es6/EmbedSDK.js/bf4a12bd69f3.js.

I'll see if I can write an in-tree-ready testcase to reproduce this ASAP, but for now I figured I'd file the bug so it's not forgotten.

Extension + Node.js server to reproduce.

The bug occurs when StreamFilter is attached to the 302 request; it is not needed to have a listener for the redirect target.

STR:

  1. node server.js to start the server at localhost:8080.
  2. Load the extension. The extension will open localhost:8080.
  3. Open the console.

At step 2, the server will respond with HTML that loads http://localhost/test.js. The extension attaches a StreamFilter. The server responds with 302, and the extension receives filter.onerror with filter.error = "Channel redirected".

At step 3, the following error appears in the console:

Loading failed for the <script> with source “http://localhost/test.js”.

Reproduced with Firefox 77.0a1 build ID 20200419091145. I can even reproduce it on older versions such as Firefox 74.0.

The test isn't entirely right as it isn't checking for the changed content, but I've verified that the loading does not fail when the patch in Bug 1595197 is applied.

Depends on: 1595197

Yes, with that patch applied my own tests seem to work fine, so this would appear to be a dupe of that issue.

Attachment #9141883 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 6 years ago
No longer depends on: 1595197
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: