| 200 | }); | 200 | }); |
| 201 | } | 201 | } |
| 202 | | 202 | |
| | 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 | |
| 203 | app.use(cookieSession({ | 222 | app.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 hours | 226 | maxAge: getSessionCookieAge(), |
| 208 | secret: userModule.getCookieSecret(), | 227 | secret: userModule.getCookieSecret(), |
| 209 | })); | 228 | })); |
| 210 | | 229 | |