Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and analyze background script reload events #720

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

everdimension
Copy link
Member

No description provided.

@everdimension everdimension changed the title eeeeDetect and analyze background script reload events Detect and analyze background script reload events Feb 24, 2025
Copy link

github-actions bot commented Feb 24, 2025

📦 build.zip [updated at Feb 27, 5:09:25 PM UTC]

@@ -46,27 +61,29 @@ export class Account extends EventEmitter<AccountEvents> {
isPendingNewUser: boolean;

private static async writeCurrentUser(user: User) {
await browserStorage.set(currentUserKey, user);
await BrowserStorage.set(currentUserKey, user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User data contains salt:

export interface User {
  id: string;
  salt: string;
}

I'm not sure how risky it is to store the salt in browser storage or if we can keep user data in session storage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encrypted storage cannot be unlocked without it, this is part of necessary data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make the salt a hash of the password instead of using crypto.getRandomValues(new Uint8Array(32)), so that we wouldn’t need to store it in browser storage (it could be stored in the session store).
But I’m still not sure if this is a good idea

@@ -10,7 +10,7 @@ export function registerPersistentRoute(value: string) {
}

export async function resetPersistedRoutes() {
return browserStorage.remove('routeRestoration');
return BrowserStorage.remove('routeRestoration');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt about moving this one to the session storage? May be there is no point of restoring the route after browser was reopened?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

}

private static async removeCredentials() {
return await browserStorage.remove(credentialsKey);
await SessionStorage.remove(credentialsKey);
await LoginActivity.recordLogout();
}

static async readCurrentUser() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these 2 functions to the top to place it near the writeCurrentUser?

@@ -152,6 +169,16 @@ export class Account extends EventEmitter<AccountEvents> {
await this.setUser(user, { password }, { isNewUser: false });
}

isAuthenticated(): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this function below the getUser?

? installedEvent.reason
: isIntentionalBrowserRestart
? 'browser restart'
: 're-enabled by user';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we consider background script reload by itself as an unlikely reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect such reloads to be caught by onInstalled listener and come with installedEvent.reason

return;
}
const hasExistingUser = await account.hasExistingUser();
const didNotOnboardYet = !hasExistingUser;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasNotOnboardedYet? :)

}

const sessionExpiry = await estimateSessionExpiry();
const { previousVersion } = packageVersionStore;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use getState here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants