parse-dashboard-analytics 7.4.0 → 7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -55,13 +55,28 @@ function initialize(app, options) {
|
|
|
55
55
|
|
|
56
56
|
const cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
|
|
57
57
|
const cookieSessionMaxAge = options.cookieSessionMaxAge;
|
|
58
|
-
|
|
58
|
+
const cookieSessionStore = options.cookieSessionStore;
|
|
59
|
+
|
|
59
60
|
app.use(require('body-parser').urlencoded({ extended: true }));
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
secret
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
const sessionConfig = {
|
|
62
|
+
name: 'parse_dash',
|
|
63
|
+
secret: cookieSessionSecret,
|
|
64
|
+
resave: false,
|
|
65
|
+
saveUninitialized: false,
|
|
66
|
+
cookie: {
|
|
67
|
+
maxAge: cookieSessionMaxAge,
|
|
68
|
+
httpOnly: true,
|
|
69
|
+
sameSite: 'lax',
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Add custom session store if provided
|
|
74
|
+
if (cookieSessionStore) {
|
|
75
|
+
sessionConfig.store = cookieSessionStore;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
app.use(require('express-session')(sessionConfig));
|
|
79
|
+
app.use(require('connect-flash')());
|
|
65
80
|
app.use(passport.initialize());
|
|
66
81
|
app.use(passport.session());
|
|
67
82
|
|
|
@@ -69,20 +84,32 @@ function initialize(app, options) {
|
|
|
69
84
|
csrf(),
|
|
70
85
|
(req,res,next) => {
|
|
71
86
|
let redirect = 'apps';
|
|
87
|
+
let originalRedirect = null;
|
|
72
88
|
if (req.body.redirect) {
|
|
73
|
-
|
|
89
|
+
originalRedirect = req.body.redirect;
|
|
90
|
+
// Validate redirect to prevent open redirect vulnerability
|
|
91
|
+
if (originalRedirect.includes('://') || originalRedirect.startsWith('//')) {
|
|
92
|
+
// Reject absolute URLs and protocol-relative URLs
|
|
93
|
+
redirect = 'apps';
|
|
94
|
+
originalRedirect = null;
|
|
95
|
+
} else {
|
|
96
|
+
// Strip leading slash from redirect to prevent double slashes
|
|
97
|
+
redirect = originalRedirect.charAt(0) === '/' ? originalRedirect.substring(1) : originalRedirect;
|
|
98
|
+
}
|
|
74
99
|
}
|
|
75
100
|
return passport.authenticate('local', {
|
|
76
101
|
successRedirect: `${self.mountPath}${redirect}`,
|
|
77
|
-
failureRedirect: `${self.mountPath}login${
|
|
102
|
+
failureRedirect: `${self.mountPath}login${originalRedirect ? `?redirect=${originalRedirect}` : ''}`,
|
|
78
103
|
failureFlash : true
|
|
79
104
|
})(req, res, next)
|
|
80
105
|
},
|
|
81
106
|
);
|
|
82
107
|
|
|
83
|
-
app.get('/logout', function(req, res){
|
|
84
|
-
req.logout()
|
|
85
|
-
|
|
108
|
+
app.get('/logout', function (req, res, next) {
|
|
109
|
+
req.logout(function (err) {
|
|
110
|
+
if (err) { return next(err); }
|
|
111
|
+
res.redirect(`${self.mountPath}login`);
|
|
112
|
+
});
|
|
86
113
|
});
|
|
87
114
|
}
|
|
88
115
|
|
package/Parse-Dashboard/app.js
CHANGED
|
@@ -82,7 +82,11 @@ module.exports = function(config, options) {
|
|
|
82
82
|
const users = config.users;
|
|
83
83
|
const useEncryptedPasswords = config.useEncryptedPasswords ? true : false;
|
|
84
84
|
const authInstance = new Authentication(users, useEncryptedPasswords, mountPath);
|
|
85
|
-
authInstance.initialize(app, {
|
|
85
|
+
authInstance.initialize(app, {
|
|
86
|
+
cookieSessionSecret: options.cookieSessionSecret,
|
|
87
|
+
cookieSessionMaxAge: options.cookieSessionMaxAge,
|
|
88
|
+
cookieSessionStore: options.cookieSessionStore
|
|
89
|
+
});
|
|
86
90
|
|
|
87
91
|
// CSRF error handler
|
|
88
92
|
app.use(function (err, req, res, next) {
|
|
@@ -1062,8 +1066,26 @@ You have direct access to the Parse database through function calls, so you can
|
|
|
1062
1066
|
}
|
|
1063
1067
|
|
|
1064
1068
|
app.get('/login', csrf(), function(req, res) {
|
|
1065
|
-
|
|
1069
|
+
let redirectURL = null;
|
|
1070
|
+
try {
|
|
1071
|
+
const url = new URL(req.url, 'http://localhost');
|
|
1072
|
+
redirectURL = url.searchParams.get('redirect');
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
console.warn('Invalid URL in login redirect:', error.message);
|
|
1075
|
+
}
|
|
1066
1076
|
if (!users || (req.user && req.user.isAuthenticated)) {
|
|
1077
|
+
// Validate and sanitize redirect URL to prevent open redirect vulnerability
|
|
1078
|
+
if (redirectURL) {
|
|
1079
|
+
// Reject absolute URLs and protocol-relative URLs
|
|
1080
|
+
if (redirectURL.includes('://') || redirectURL.startsWith('//')) {
|
|
1081
|
+
redirectURL = null;
|
|
1082
|
+
} else {
|
|
1083
|
+
// Strip leading slash to prevent double slashes
|
|
1084
|
+
if (redirectURL.charAt(0) === '/') {
|
|
1085
|
+
redirectURL = redirectURL.substring(1);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1067
1089
|
return res.redirect(`${mountPath}${redirectURL || 'apps'}`);
|
|
1068
1090
|
}
|
|
1069
1091
|
|