Skip to content

Commit

Permalink
Fix SAML timeout issues when keepalive is true
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Feb 8, 2024
1 parent 4d7e5f3 commit 183b502
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/auth/types/authentication_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export abstract class AuthenticationType implements IAuthenticationType {
cookie = undefined;
}

console.log(cookie)

Check failure on line 146 in server/auth/types/authentication_type.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 146 in server/auth/types/authentication_type.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

if (!cookie || !(await this.isValidCookie(cookie, request))) {
// clear cookie
this.sessionStorageFactory.asScoped(request).clear();
Expand All @@ -160,7 +162,7 @@ export abstract class AuthenticationType implements IAuthenticationType {

// extend session expiration time
if (this.config.session.keepalive) {
cookie!.expiryTime = Date.now() + this.config.session.ttl;
cookie!.expiryTime = Math.max(Date.now() + this.config.session.ttl, cookie.expiryTime || 0);
this.sessionStorageFactory.asScoped(request).set(cookie!);
}
// cookie is valid
Expand Down
6 changes: 6 additions & 0 deletions server/auth/types/saml/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class SamlAuthRoutes {
redirectHash: request.query.redirectHash === 'true',
},
};
console.log('saml login cookie' + JSON.stringify(cookie))

Check failure on line 87 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 87 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`
this.sessionStorageFactory.asScoped(request).set(cookie);
return response.redirected({
headers: {
Expand Down Expand Up @@ -113,6 +114,7 @@ export class SamlAuthRoutes {
let redirectHash: boolean = false;
try {
const cookie = await this.sessionStorageFactory.asScoped(request).get();
console.log('acs' + JSON.stringify(cookie))

Check failure on line 117 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 117 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`
if (cookie) {
requestId = cookie.saml?.requestId || '';
nextUrl =
Expand Down Expand Up @@ -142,16 +144,20 @@ export class SamlAuthRoutes {
credentials.authorization
);

console.log('creds' + JSON.stringify(credentials), 'user' + JSON.stringify(user))

Check failure on line 147 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 147 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

let expiryTime = Date.now() + this.config.session.ttl;
const [headerEncoded, payloadEncoded, signature] = credentials.authorization.split('.');
if (!payloadEncoded) {
context.security_plugin.logger.error('JWT token payload not found');
}
const tokenPayload = JSON.parse(Buffer.from(payloadEncoded, 'base64').toString());
console.log(tokenPayload)

Check failure on line 155 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 155 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

if (tokenPayload.exp) {
expiryTime = parseInt(tokenPayload.exp, 10) * 1000;
}
console.log(expiryTime)

Check failure on line 160 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `;`

Check failure on line 160 in server/auth/types/saml/routes.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `;`

const cookie: SecuritySessionCookie = {
username: user.username,
Expand Down

0 comments on commit 183b502

Please sign in to comment.