|
|
@@ -1,8 +1,13 @@
|
|
|
+/**
|
|
|
+ * Redirect with prevention from Open Redirect
|
|
|
+ *
|
|
|
+ * Usage: app.use(require('middleware/safe-redirect')(['example.com', 'some.example.com:8080']))
|
|
|
+ */
|
|
|
+
|
|
|
const loggerFactory = require('@alias/logger');
|
|
|
|
|
|
const logger = loggerFactory('growi:middleware:safe-redirect');
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Check whether the redirect url host is in specified whitelist
|
|
|
* @param {Array<string>} whitelistOfHosts
|
|
|
@@ -17,11 +22,7 @@ function isInWhitelist(whitelistOfHosts, redirectToFqdn) {
|
|
|
return whitelistOfHosts.includes(redirectUrl.hostname) || whitelistOfHosts.includes(redirectUrl.host);
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Redirect with prevention from Open Redirect
|
|
|
- *
|
|
|
- * Usage: app.use(require('middleware/safe-redirect'))
|
|
|
- */
|
|
|
+
|
|
|
module.exports = (whitelistOfHosts) => {
|
|
|
|
|
|
return function(req, res, next) {
|