Configurable session expiration

02e65ff1765181682be301334616a5a8caff2523

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +25 -1Showing whitespace changes
default/config.yaml+5 -0
@@ -95,3 +95,8 @@ deepl:
9595 formality: default
9696# -- SERVER PLUGIN CONFIGURATION --
9797enableServerPlugins: false
98+# User session timeout *in seconds* (defaults to 24 hours).
99+## Set to a positive number to expire session after a certain time of inactivity
100+## Set to 0 to expire session when the browser is closed
101+## Set to a negative number to disable session expiration
102+sessionTimeout: 86400
server.js+20 -1
@@ -200,11 +200,30 @@ if (enableCorsProxy) {
200200 });
201201}
202202
203+function getSessionCookieAge() {
204+ // Defaults to 24 hours in seconds if not set
205+ const configValue = getConfigValue('sessionTimeout', 24 * 60 * 60);
206+
207+ // Convert to milliseconds
208+ if (configValue > 0) {
209+ return configValue * 1000;
210+ }
211+
212+ // "No expiration" is just 400 days as per RFC 6265
213+ if (configValue < 0) {
214+ return 400 * 24 * 60 * 60 * 1000;
215+ }
216+
217+ // 0 means session cookie is deleted when the browser session ends
218+ // (depends on the implementation of the browser)
219+ return undefined;
220+}
221+
203222app.use(cookieSession({
204223 name: userModule.getCookieSessionName(),
205224 sameSite: 'strict',
206225 httpOnly: true,
207- maxAge: 24 * 60 * 60 * 1000, // 24 hours
226+ maxAge: getSessionCookieAge(),
208227 secret: userModule.getCookieSecret(),
209228}));
210229