einaregilsson / Redirector

Browser extension (Firefox, Chrome, Opera, Edge) to redirect urls based on regex patterns, like a client side mod_rewrite.
http://einaregilsson.com/redirector/
MIT License
1.54k stars 159 forks source link

[bug] Redirector hangs whole browser after visiting some web-sites #297

Open AlexCzar opened 2 years ago

AlexCzar commented 2 years ago

After I visit Gmail, Amazon or some other heavy sites, Redirector will hang the whole UI, some resources will stop loading. Browser: Firefox 96.0.3 (64-bit) OS: Linux DE: KDE Plasma Maybe relevant extensions:

Configured redirects ```json { "createdBy": "Redirector v3.5.3", "createdAt": "2022-02-07T07:43:08.630Z", "redirects": [ { "description": "Medium -> Scribe", "exampleUrl": "https://medium.com/@user/post-123456abcdef", "exampleResult": "https://scribe.rip//@user/post-123456abcdef", "error": null, "includePattern": "^https?://(?:.*\\.)*(? Libreddit", "exampleUrl": "https://www.reddit.com/r/subreddit", "exampleResult": "https://r.nf//r/subreddit", "error": null, "includePattern": "^https?://(?:.*\\.)*reddit\\.com(/.*)?$", "excludePattern": "", "patternDesc": "", "redirectUrl": "https://r.nf/$1", "patternType": "R", "processMatches": "noProcessing", "disabled": false, "grouped": false, "appliesTo": [ "main_frame" ] } ] } ```
Crackz commented 2 years ago

I have the same issue with amazon. when I add stuff to the cart then clicking on the checkout button the extension consumes 100% CPU

{
    "createdBy": "Redirector v3.5.3",
    "createdAt": "2022-03-01T12:38:45.394Z",
    "redirects": [
        {
            "description": "Medium -> Scribe",
            "exampleUrl": "https://medium.com/@user/post-123456abcdef",
            "exampleResult": "https://scribe.rip//@user/post-123456abcdef",
            "error": null,
            "includePattern": "^https?://(?:.*\\.)*(?<!(link\\.|cdn\\-images\\-\\d+\\.))medium\\.com(/.*)?$",
            "excludePattern": "",
            "patternDesc": "",
            "redirectUrl": "https://scribe.rip/$2",
            "patternType": "R",
            "processMatches": "noProcessing",
            "disabled": false,
            "grouped": false,
            "appliesTo": [
                "main_frame"
            ]
        }
    ]
}
Brawl345 commented 2 years ago

I have the same problem but only since a few days ago... Using Chrome 99. The whole browser doesn't load any other webpage until I kill the addon. It's so bad that I had to disable it :/

laurent22 commented 2 years ago

Same problem on Edge. It would use 100% CPU all the time and prevent all pages to load, so also had to remove the extension.

I was also using the same Medium configuration as above and no Medium page was actually being displayed so the extension shouldn't have been doing anything.

Gitoffthelawn commented 2 years ago

@laurent22 In Redirector, did you only have the single redirect rule mentioned by "Crackz" (and originally posted by "AlexCzar") in this thread?

Also, had you visited any Medium pages within the prior 10 minutes before you experienced 100% CPU use?

Finally, so we have good records, on which version of Edge did you encounter this issue? Also, what other extensions, if any, did you have installed?

decoherencer commented 2 years ago

I have other redirect rules added, but I tried disabling the above medium rule and the issue still pops up occasionally. I have a chromium-based browser v102.0.5005.125 I have multiple extensions, but I will try to disable some extensions at a time and observe again for the next few days. Is there a way to collect the log from the extension in a file?

Ok, so the errors file indicates this:

Error handling response: TypeError: Could not add listener
Context
_generated_background_page.html
Stack Trace
js/background.js:215 (anonymous function)

line 215: chrome.webNavigation.onHistoryStateUpdated.addListener(checkHistoryStateRedirects, filter);
jtraub commented 2 years ago

I too observe the problem.

Sometimes Redirector hangs browser and the only way to continue using it is either full restart or killing the extension

jtraub commented 2 years ago

Ok, I did some testing and narrowed down the problem.

The extension hangs when you visit a page with a very long URL with many dots in it (say, 500+ characters and 15+ dots).

UPD: Yeah, I noticed that I also have scribe.rip rule to redirect medium articles. I should have read the other comments more carefully instead of going blind and trying to locate the problem. I guess its regex is the reason.

jtraub commented 2 years ago

Scribe.rip rule is the culprit indeed.

It uses the following regex

^https?://(?:.*\.)*(?<!(link\.|cdn\-images\-\d+\.))medium\.com(/.*)?$

The regex has catastrophic backtracking.

This can be verified by opening browser console and putting

const regexp = new RegExp('^https?://(?:.*\.)*(?<!(link\.|cdn\-images\-\d+\.))medium\.com(/.*)?$');
regexp.exec('...put here a really long url or even just a string with 1500 chars and 20-40 dots ...')

there. You can now watch how the browser hangs.

Another way to verify is visiting this url with Redirector containing only mentioned scribe.rip rule. You can use this url in the console test too.

Switching to something like this should help

^https?://(?:[^\.]+\.){0,1}(?<!(link\.|cdn\-images\-\d+\.))medium\.com(/.*)?$

I guess I should report the issue to scribe.rip author.

Gitoffthelawn commented 2 years ago

@jtraub Thanks for your posts. Very helpful. On which web browser (and version) did you experience this issue?

jtraub commented 2 years ago

@Gitoffthelawn

Chromium version 105.0.5195.125 (Official Build) Arch Linux (64-bit)

However, this problem will be observed on all browsers and all platforms as the number of steps during regex matching grows exponentially with the length of URL.

I am not sure Redirector can do anything here as the catastrophic backtracking can have so many forms and detecting it by searching patterns in regex is hard.

Gitoffthelawn commented 2 years ago

@jtraub

I agree. The best solution may be to hope that someday web browsers will have JavaScript engines that can detect regex catastrophic backtracking and handle it gracefully. I'm not sure if any browsers do this already, but it sounds like we can probably rule out all Chromium-based browsers.