use trusted redirect

pull/223/head
Fabian Jakobs 2015-10-26 15:38:37 +00:00
rodzic ef5af704cd
commit 80a98cf92d
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -1,11 +1,23 @@
"use strict";
var url = require("url");
module.exports = function(options, imports, register) {
var trustedHosts = options.trustedHosts || {};
imports.connect.addResponseMethod("redirect", function(location) {
this.writeHead(302, {Location: location});
this.end("");
});
imports.connect.addResponseMethod("secureRedirect", function(location) {
var parsedLocation = url.parse(location);
if (!(location.host in trustedHosts))
location = parsedLocation.path;
this.writeHead(302, {Location: location});
this.end("");
});
imports.connect.addResponseMethod("returnTo", function(req, defaultReturn) {
var url = defaultReturn || "/";
if (req.session && req.session.returnTo) {