Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How safe is redirect via javascript?

I have developed a Rails app and now I'm trying to improve its security. There are some ajax on it and as I don't have much experience with jQuery and on one of the ajax requests, I have to redirect the user via javascript, is it a good practice? I would like to know if it's safe the implementation below and what is the risk that my app could be suffering too:

success: function(callback) {
  if (callback.status == true) {
    if (event.target.id == 'radar_occurrences')
      window.location.href = '/radar/all'
    else
      window.location.href = '/radar/list'
    }
  else {
    $("body").before("<p class='error'>Failure message.</p>");
    flashError();
  }
}

Thanks!

like image 572
hugalves Avatar asked Aug 26 '26 19:08

hugalves


1 Answers

A common security issue with redirects are "open redirects" where basically an attacker can take advantage of a flaw in your page to get a user redirected to some other site of his/her choice. In your specific case it seems that you don't use any user supplied parameter to define the target URL of the redirect, so you should be safe from this attack.

like image 116
Frank Avatar answered Aug 28 '26 12:08

Frank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!