Skip to content

Commit

Permalink
Merge pull request #339 from bolus/cross-domain-redirect-exception
Browse files Browse the repository at this point in the history
Cross domain redirect exception
  • Loading branch information
arunoda committed Oct 1, 2015
2 parents 8476b8f + 10a0b6a commit cc99fbc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Router = function () {

// redirect function used inside triggers
this._redirectFn = function(pathDef, fields, queryParams) {
if (/^http(s)?:\/\//.test(pathDef)) {
var message = "Redirects to URLs outside of the app are not supported in this version of Flow Router. Use 'window.location = yourUrl' instead";
throw new Error(message);
}
self.withReplaceState(function() {
var path = FlowRouter.path(pathDef, fields, queryParams);
self._page.redirect(path);
Expand Down
40 changes: 40 additions & 0 deletions test/client/trigger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,46 @@ Tinytest.addAsync('Client - Triggers - redirect from exit', function(test, next)
}, 100);
});

Tinytest.addAsync('Client - Triggers - redirect to external URL fails', function(test, next) {
var rand = Random.id(), rand2 = Random.id();
var log = [];

// testing "http://" URLs
FlowRouter.route('/' + rand, {
triggersEnter: [function(context, redirect) {
test.throws(function() {
redirect("http://example.com/")
}, "Redirects to URLs outside of the app are not supported")
}],
action: function(_params) {
log.push(1);
},
name: rand
});

// testing "https://" URLs
FlowRouter.route('/' + rand2, {
triggersEnter: [function(context, redirect) {
test.throws(function() {
redirect("https://example.com/")
})
}],
action: function(_params) {
log.push(2);
},
name: rand2
});

FlowRouter.go('/');
FlowRouter.go('/' + rand);
FlowRouter.go('/' + rand2);

setTimeout(function() {
test.equal(log, []);
next();
}, 300);
});

Tinytest.addAsync('Client - Triggers - stop callback from enter', function(test, next) {
var rand = Random.id();
var log = [];
Expand Down

0 comments on commit cc99fbc

Please sign in to comment.