Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect whitelist support #236

Closed
linghuaj opened this issue Apr 16, 2015 · 2 comments
Closed

redirect whitelist support #236

linghuaj opened this issue Apr 16, 2015 · 2 comments

Comments

@linghuaj
Copy link

Does LAZO support blocking off-site redirects via config or only allow redirect from a whitelist via a config?

Or that is something outside of framework scope?

@jstrimpel
Copy link
Contributor

That would something that you put in a filter so that when LAZO.app.navigate is called you can redirect to another page.

@linghuaj
Copy link
Author

here is the solution. you can do something like to only allow redirect within current site

LAZO.app.addRequestFilter('.*', function (path, params, ctx, options) {
          var hostname = ctx.location.hostname;
          var port = ctx.location.port;
          var sslPort = LAZO.config.get('sslPort') || 8443;
          var sslProtocol = LAZO.config.get('sslProtocol') || 'https';
          var hostMatchPattern;
          var redirectHost;
          var redirectUrl;
          hostMatchPattern = port ? hostname + ':' + port : hostname;
          redirectHost = getHostName(ctx.params.redirect);
            if (!(redirectHost === hostMatchPattern)) {
                //redirect to main host page
                return options.success(sslProtocol + '://' + hostname + (sslPort ? ':' + sslPort : ''));
            }
});

  function getHostName(url) {
        var regex = /^(?:https?:\/\/)?(?:www\.)?([^\/]+)/i;
        var redirectHostMatch = url.match(regex);
        var redirectHost;
        if (redirectHostMatch) {
            redirectHost = redirectHostMatch[1];
        }
        return redirectHost;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants