Scriptlets
Scriptlets copied to clipboard
Fix `prevent-setTimeout`/`prevent-setInterval` - if `matchCallback` contains `(` then scriptlet doesn't work correctly
Steps to reproduce:
- Add this rule:
example.org#%#//scriptlet('prevent-setTimeout', 'alert(')
- Go to - https://example.org/
- 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.