Configurable session expiration

02e65ff1765181682be301334616a5a8caff2523

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

2 files changed, +25 -1Ignore whitespace
default/config.yaml+5 -0
@@ -95,3 +95,8 @@ deepl:
95 formality: default95 formality: default
96# -- SERVER PLUGIN CONFIGURATION --96# -- SERVER PLUGIN CONFIGURATION --
97enableServerPlugins: false97enableServerPlugins: 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
102sessionTimeout: 86400
server.js+20 -1
@@ -200,11 +200,30 @@ if (enableCorsProxy) {
200 });200 });
201}201}
202202
203function 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
203app.use(cookieSession({222app.use(cookieSession({
204 name: userModule.getCookieSessionName(),223 name: userModule.getCookieSessionName(),
205 sameSite: 'strict',224 sameSite: 'strict',
206 httpOnly: true,225 httpOnly: true,
207 maxAge: 24 * 60 * 60 * 1000, // 24 hours226 maxAge: getSessionCookieAge(),
208 secret: userModule.getCookieSecret(),227 secret: userModule.getCookieSecret(),
209}));228}));
210229