Say someone (evil) has set us a timer with setInterval
, but we don't know its ID (we don't have the reference to the object, that setInterval is returning, nor its value)
(function(){
setInterval(function(){console.log('pwned')},
10000)
})();
Is there a way, how to clear it? Is it possible to acces the timer some other way? Or at least in particular browser/javascript engine?
David Flanagan touches similar topic his big JSTDG.
setInterval() method, use in malicious code
key in the index points to
... Some browsers detect repeated dialog boxes and long-running scripts and give the user the option to stop them. But malicious code can use methods such as setInterval() to load the CPU and can also attack your system by allocating lots of memory. There is no general way that web browsers can prevent this kind of ham-handed attack. In practice, this is not a common problem on the Web since no one returns to a site that engages in this kind of scripting abuse!