L
L
likejavascript2016-06-12 19:41:42
Computer networks
likejavascript, 2016-06-12 19:41:42

How to properly check open redirect for security?

I want to prevent Open redirect attack in my nodejs application.
Now May implementation is as follows:

var = require('url');

// http://example.com/login?redirect=http://example.com/dashboard
app.route('/login', function (req, res, next) {
   var redirect = req.query.redirect,
        paths = url.parse(redirect); 

   if (paths.host !== req.headers.host) {
      return next(new Error('Open redirect attack detected'));
   }

   return res.redirect(redirect);
});

You need to safely redirect to the main domain and subdomains:
For example:
example.com/dashboard
dashboard.example.com
Tell me how secure is my implementation and what needs to be improved?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question