Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Fix `prevent-setTimeout`/`prevent-setInterval` - if `matchCallback` contains `(` then scriptlet doesn't work correctly

Open AdamWr opened this issue 3 years ago • 0 comments

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('prevent-setTimeout', 'alert(')
  1. Go to - https://example.org/
  2. Run in console:
setTimeout(()=>{ alert("test") }, 100);

Alert should be blocked, but it isn't.

As far as I understand, problem is in isValidStrPattern function which is used by isValidMatchStr, which is used by isPreventionNeeded.

https://github.com/AdguardTeam/Scriptlets/blob/d49fe8b63f072395f8461544e9fec51f8dac4bc6/src/helpers/string-utils.js#L51-L66

The input is alert(, in this case new RegExp(str); throws error and function returns false, so setTimeout is not prevented, if I understand correctly. I guess that similar issue may be with other scriptlets which use the same function.

AdamWr avatar Sep 01 '22 06:09 AdamWr