mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Configurable session expiration
This commit is contained in:
@@ -95,3 +95,8 @@ deepl:
|
|||||||
formality: default
|
formality: default
|
||||||
# -- SERVER PLUGIN CONFIGURATION --
|
# -- SERVER PLUGIN CONFIGURATION --
|
||||||
enableServerPlugins: false
|
enableServerPlugins: false
|
||||||
|
# User session timeout *in seconds* (defaults to 24 hours).
|
||||||
|
## Set to a positive number to expire session after a certain time of inactivity
|
||||||
|
## Set to 0 to expire session when the browser is closed
|
||||||
|
## Set to a negative number to disable session expiration
|
||||||
|
sessionTimeout: 86400
|
||||||
|
21
server.js
21
server.js
@@ -200,11 +200,30 @@ if (enableCorsProxy) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSessionCookieAge() {
|
||||||
|
// Defaults to 24 hours in seconds if not set
|
||||||
|
const configValue = getConfigValue('sessionTimeout', 24 * 60 * 60);
|
||||||
|
|
||||||
|
// Convert to milliseconds
|
||||||
|
if (configValue > 0) {
|
||||||
|
return configValue * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "No expiration" is just 400 days as per RFC 6265
|
||||||
|
if (configValue < 0) {
|
||||||
|
return 400 * 24 * 60 * 60 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 means session cookie is deleted when the browser session ends
|
||||||
|
// (depends on the implementation of the browser)
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
app.use(cookieSession({
|
app.use(cookieSession({
|
||||||
name: userModule.getCookieSessionName(),
|
name: userModule.getCookieSessionName(),
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
maxAge: getSessionCookieAge(),
|
||||||
secret: userModule.getCookieSecret(),
|
secret: userModule.getCookieSecret(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user