fix(striker-ui-api): make cookie original max age configable

main
Tsu-ba-me 1 year ago
parent 5a1ad20d7f
commit a7709df2a6
  1. 8
      striker-ui-api/src/lib/consts/ENV.ts
  2. 10
      striker-ui-api/src/middlewares/session.ts

@ -7,6 +7,14 @@ import { resolveGid, resolveUid } from '../shell';
*/ */
export const COOKIE_PREFIX = process.env.COOKIE_PREFIX ?? 'suiapi'; export const COOKIE_PREFIX = process.env.COOKIE_PREFIX ?? 'suiapi';
/**
* The max lifespan of a session cookie in milliseconds.
*
* @default 28800000
*/
export const COOKIE_ORIGINAL_MAX_AGE =
Number(process.env.COOKIE_ORIGINAL_MAX_AGE) || 28800000;
/** /**
* The fallback job progress value when queuing jobs. * The fallback job progress value when queuing jobs.
* *

@ -4,15 +4,13 @@ import expressSession, {
Store as BaseSessionStore, Store as BaseSessionStore,
} from 'express-session'; } from 'express-session';
import { DELETED } from '../lib/consts'; import { COOKIE_ORIGINAL_MAX_AGE, DELETED } from '../lib/consts';
import { getLocalHostUUID, query, timestamp, write } from '../lib/accessModule'; import { getLocalHostUUID, query, timestamp, write } from '../lib/accessModule';
import { cname } from '../lib/cname'; import { cname } from '../lib/cname';
import { getSessionSecret } from '../lib/getSessionSecret'; import { getSessionSecret } from '../lib/getSessionSecret';
import { stderr, stdout, stdoutVar, uuid } from '../lib/shell'; import { stderr, stdout, stdoutVar, uuid } from '../lib/shell';
const DEFAULT_COOKIE_ORIGINAL_MAX_AGE = 28800000; // 8 hours
export class SessionStore extends BaseSessionStore { export class SessionStore extends BaseSessionStore {
constructor(options = {}) { constructor(options = {}) {
super(options); super(options);
@ -85,7 +83,7 @@ export class SessionStore extends BaseSessionStore {
const data: SessionData = { const data: SessionData = {
cookie: { cookie: {
maxAge: cookieMaxAge, maxAge: cookieMaxAge,
originalMaxAge: DEFAULT_COOKIE_ORIGINAL_MAX_AGE, originalMaxAge: COOKIE_ORIGINAL_MAX_AGE,
}, },
passport: { user: userUuid }, passport: { user: userUuid },
}; };
@ -169,7 +167,7 @@ export class SessionStore extends BaseSessionStore {
public static calculateCookieMaxAge( public static calculateCookieMaxAge(
sessionModifiedDate: string, sessionModifiedDate: string,
cookieOriginalMaxAge: number = DEFAULT_COOKIE_ORIGINAL_MAX_AGE, cookieOriginalMaxAge: number = COOKIE_ORIGINAL_MAX_AGE,
) { ) {
const sessionModifiedEpoch = Date.parse(sessionModifiedDate); const sessionModifiedEpoch = Date.parse(sessionModifiedDate);
const sessionDeadlineEpoch = sessionModifiedEpoch + cookieOriginalMaxAge; const sessionDeadlineEpoch = sessionModifiedEpoch + cookieOriginalMaxAge;
@ -185,7 +183,7 @@ export default (async () =>
expressSession({ expressSession({
cookie: { cookie: {
httpOnly: true, httpOnly: true,
maxAge: DEFAULT_COOKIE_ORIGINAL_MAX_AGE, maxAge: COOKIE_ORIGINAL_MAX_AGE,
secure: false, secure: false,
}, },
genid: ({ originalUrl }) => { genid: ({ originalUrl }) => {

Loading…
Cancel
Save