Skip to content

Commit

Permalink
ENG-0000 - Update AlSession to enforce non-zero account Id
Browse files Browse the repository at this point in the history
This updates `AlSession`'s constructor to enforce both timestamps and account IDs for session
information found in localStorage.
  • Loading branch information
mcnielsen committed Feb 6, 2025
1 parent f122a94 commit 3ee7c98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@al/core",
"version": "1.3.1",
"version": "1.3.2",
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
"main": "./dist/index.cjs.js",
"types": "./dist/index.d.ts",
Expand Down
7 changes: 5 additions & 2 deletions src/session/al-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ export class AlSessionInstance
* API requests from being fired before whatever application has imported us has had a chance to bootstrap.
*/
const persistedSession = this.storage.get("session") as AIMSSessionDescriptor;
if ( persistedSession && persistedSession.hasOwnProperty( "authentication" ) && persistedSession.authentication.token_expiration >= this.getCurrentTimestamp() ) {
if ( ( persistedSession?.authentication?.token_expiration ?? 0 ) >= this.getCurrentTimestamp()
&&
persistedSession?.authentication?.account?.id ) {
this.restoreSession( persistedSession );
} else {
console.warn("TOTALLY IGNORING STORED SESSSION!" );
this.storage.destroy();
}

Expand Down Expand Up @@ -776,7 +779,7 @@ export class AlSessionInstance

return this.resolvedAccount;
} catch( e ) {
console.error( e );
console.error( "FAILED to resolve acting account!", e );
throw e;
}
}
Expand Down

0 comments on commit 3ee7c98

Please sign in to comment.