Skip to content

Commit 9ea95fc

Browse files
authored
fix: Add dashboard option cookieSessionMaxAge to keep user logged in across browser sessions (#2366)
1 parent 7fa5a7f commit 9ea95fc

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

Parse-Dashboard/Authentication.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ function initialize(app, options) {
5454
});
5555

5656
var cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
57+
const cookieSessionMaxAge = options.cookieSessionMaxAge;
5758
app.use(require('connect-flash')());
5859
app.use(require('body-parser').urlencoded({ extended: true }));
5960
app.use(require('cookie-session')({
6061
key : 'parse_dash',
6162
secret : cookieSessionSecret,
62-
cookie : {
63-
maxAge: (2 * 7 * 24 * 60 * 60 * 1000) // 2 weeks
64-
}
63+
maxAge : cookieSessionMaxAge
6564
}));
6665
app.use(passport.initialize());
6766
app.use(passport.session());

Parse-Dashboard/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = function(config, options) {
6868
const users = config.users;
6969
const useEncryptedPasswords = config.useEncryptedPasswords ? true : false;
7070
const authInstance = new Authentication(users, useEncryptedPasswords, mountPath);
71-
authInstance.initialize(app, { cookieSessionSecret: options.cookieSessionSecret });
71+
authInstance.initialize(app, { cookieSessionSecret: options.cookieSessionSecret, cookieSessionMaxAge: options.cookieSessionMaxAge });
7272

7373
// CSRF error handler
7474
app.use(function (err, req, res, next) {

Parse-Dashboard/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ program.option('--trustProxy [trustProxy]', 'set this flag when you are behind a
2828
program.option('--cookieSessionSecret [cookieSessionSecret]', 'set the cookie session secret, defaults to a random string. You should set that value if you want sessions to work across multiple server, or across restarts');
2929
program.option('--createUser', 'helper tool to allow you to generate secure user passwords and secrets. Use this on trusted devices only.');
3030
program.option('--createMFA', 'helper tool to allow you to generate multi-factor authentication secrets.');
31+
program.option('--cookieSessionMaxAge [cookieSessionMaxAge]', '(Optional) Sets the time in seconds for when the session cookie will be deleted and the dashboard user has to re-login; if no value is set then the cookie will be deleted when the browser session ends.');
32+
3133
program.action(async (options) => {
3234
for (const key in options) {
3335
const func = CLIHelper[key];

Parse-Dashboard/server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = (options) => {
1919
const allowInsecureHTTP = options.allowInsecureHTTP || process.env.PARSE_DASHBOARD_ALLOW_INSECURE_HTTP;
2020
const cookieSessionSecret = options.cookieSessionSecret || process.env.PARSE_DASHBOARD_COOKIE_SESSION_SECRET;
2121
const trustProxy = options.trustProxy || process.env.PARSE_DASHBOARD_TRUST_PROXY;
22+
const cookieSessionMaxAge = options.cookieSessionMaxAge || process.env.PARSE_DASHBOARD_COOKIE_SESSION_MAX_AGE;
2223
const dev = options.dev;
2324

2425
if (trustProxy && allowInsecureHTTP) {
@@ -145,7 +146,7 @@ module.exports = (options) => {
145146
if (allowInsecureHTTP || trustProxy || dev) app.enable('trust proxy');
146147

147148
config.data.trustProxy = trustProxy;
148-
let dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev };
149+
let dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev, cookieSessionMaxAge };
149150
app.use(mountPath, parseDashboard(config.data, dashboardOptions));
150151
let server;
151152
if(!configSSLKey || !configSSLCert){

0 commit comments

Comments
 (0)