Dannyboy
Dannyboy

Reputation: 2052

Is it possible to detect malicious ads that redirect users?

So I'm getting complaints sometimes that users are being taken to phishing and or virus-spreading sites without clicking on anything.
I think this is caused by some malicious google ads triggering window.location and redirecting people. Is it possible to detect such action so I could log ad source?

P.S> srry just to clarify -> is it possible to also detect the url where is user being taken so we could discern malicios rediredcts from non-malicious?

Upvotes: 0

Views: 239

Answers (2)

Lukas Liesis
Lukas Liesis

Reputation: 26413

To stop redirection you can try using onbeforeunload event

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

window.onbeforeunload = function(e) {
  var dialogText = 'Dialog text here';
  e.returnValue = dialogText;
  return dialogText;
};

Upvotes: 0

floribon
floribon

Reputation: 19193

You could quickly send some info about the page being redirected using onbeforeunload. You can either decide to block the redirection with a message asling a confirmation from the user, or just send to a backend some data about what happened.

window.onbeforeunload = function(event) {
  // Send sync ajax call with event data
  // Return a message to ask confirmation
  return 'You are being redirected, please call the police'
}; 

Upvotes: 2

Related Questions