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

fix: handling invalid session state #4139

Merged
merged 4 commits into from
Jan 17, 2024
Merged

fix: handling invalid session state #4139

merged 4 commits into from
Jan 17, 2024

Conversation

ganchoradkov
Copy link
Member

Description

Implemented several improvements in regards to handling invalid state such as having sessions without their corresponding keychain.

  • new cleanup step on load to confirm all sessions have their keychains
  • additional checks during requests that the session has all required data
  • additional emits of session_delete to notify dapp that session got deleted

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Draft PR (breaking/non-breaking change which needs more work for having a proper functionality [Mark this PR as ready to review only when completely ready])
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

tests
dogfooding

Checklist

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Gancho Radkov added 2 commits January 17, 2024 11:38
…ming keychain exists and removes session if deemed invalid
@ganchoradkov ganchoradkov requested a review from bkrem January 17, 2024 12:24
@arein arein added the accepted label Jan 17, 2024
Copy link
Member

@bkrem bkrem left a comment

Choose a reason for hiding this comment

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

Nice 💪

packages/sign-client/src/controllers/engine.ts Outdated Show resolved Hide resolved
await this.deleteSession(topic);
} else {
await this.deleteSession({ topic, emitEvent: false });
} else if (this.client.core.pairing.pairings.keys.includes(topic)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice improvement 👍

In retrospect I don't recall why we didn't combine pairing and session handling into this top level disconnect/why it was session-only and pairings had to be handled explicitly via core.pairing.disconnect()

@@ -446,7 +451,6 @@ export class Engine extends IEngine {
};

public getPendingSessionRequests: IEngine["getPendingSessionRequests"] = () => {
this.isInitialized();
Copy link
Member

Choose a reason for hiding this comment

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

Por que no? Isn't pendingRequest a store that needs to be initialised during init?

Copy link
Member Author

@ganchoradkov ganchoradkov Jan 17, 2024

Choose a reason for hiding this comment

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

this isInitialized refers to engine's initialization and the cleanup is ran before initialized is set to true

packages/sign-client/src/controllers/engine.ts Outdated Show resolved Hide resolved
packages/sign-client/test/sdk/client.spec.ts Outdated Show resolved Hide resolved
});
this.client.proposal.getAll().forEach((proposal) => {
if (isExpired(proposal.expiry)) proposalIds.push(proposal.id);
});
await Promise.all([
...sessionTopics.map((topic) => this.deleteSession(topic)),
...sessionTopics.map((topic) => this.deleteSession({ topic })),
Copy link
Member

Choose a reason for hiding this comment

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

Do we want emitEvent to be true here? May be very noisy if the client cleans up a lot of sessions but not sure if suppressing emit would effectively be a breaking change to current behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it makes sense to emit, as expirer can delete sessions while the client is active, and the implementing party might not be subscribed to expirer events thus missing the delete

@ganchoradkov ganchoradkov merged commit 0715a49 into v2.0 Jan 17, 2024
9 checks passed
@ganchoradkov ganchoradkov deleted the fix/session-state branch January 17, 2024 14:51
@ganchoradkov ganchoradkov mentioned this pull request Feb 6, 2024
20 tasks
compojoom added a commit to safe-global/safe-wallet-monorepo that referenced this pull request Feb 22, 2024
This seems to be fixed with this PR:
WalletConnect/walletconnect-monorepo#4139
so that is why I force a newer WC version since web3-onboard doesn’t have a release that uses it.
compojoom added a commit to safe-global/safe-wallet-monorepo that referenced this pull request Feb 23, 2024
* fix: wc no matching key: keychain

This seems to be fixed with this PR:
WalletConnect/walletconnect-monorepo#4139
so that is why I force a newer WC version since web3-onboard doesn’t have a release that uses it.

* fix: wc no matching key. session

This is an attempt to fix this WC error, but it doesn’t always work. Even more this error is reproducible only with 1inch.

Steps to reproduce the error:
1. Open your safe and login into an account
2. Open 1inch and select connect with walletconnect
3. On your safe, paste the link in the wc pairing field, but don’t approve
4. Refresh the page
5. Get a new pairing link from 1inch and try to pair again
6. You get the error

With the fix in this commit, we clean up on page unload this way the localstorage of walletconnect is left with an empty propsal and the next time the user tries to approve it should work. This is only a workaround. I think that this is a bug in walletconnect and they should better take care of their localstorage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants