Skip to content

fix: make isAuthenticated validate delegation expiry #985

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

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

Conversation

asabates-dfinity
Copy link

@asabates-dfinity asabates-dfinity commented Mar 26, 2025

Description

Currently isAuthenticated does not work if the delegation has expired, as it does not check at any moment further than the chain has being unset, which only happens when actively logout call is triggered. This produces the scenario in which a consumer can call to isAuthenticated, get a true result and yet their agents are rejected because of the expired authorization.

This PR aims to fix this problem by adding a check validating the delegation chain, it also adjusts the signature of the method to non asynchronous as none of the operations done inside are, indeed, asynchronous. This simplifies the usage for the consumer.

How Has This Been Tested?

Updated unit tests to check that it returns false when its expired

Checklist:

  • My changes follow the guidelines in CONTRIBUTING.md.
  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@nathanosdev nathanosdev requested a review from Copilot March 26, 2025 12:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where isAuthenticated did not validate delegation expiry and updates its signature to synchronous, simplifying its usage.

  • Updated isAuthenticated to include a delegation chain expiry check and made it synchronous.
  • Adjusted unit tests to remove unnecessary async handling and add an assertion for delegation expiry.
  • Reformatted export statements in index.ts for consistency.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/auth-client/src/index.ts Made isAuthenticated synchronous with an added delegation expiry check and reformatted exports.
packages/auth-client/src/index.test.ts Updated tests to reflect the synchronous isAuthenticated method and added an assertion for failed delegation validation.

@asabates-dfinity asabates-dfinity force-pushed the asabates/extended-is-authorized branch from 72feeb2 to 37704af Compare March 26, 2025 12:13
@asabates-dfinity asabates-dfinity marked this pull request as ready for review March 26, 2025 12:32
@asabates-dfinity asabates-dfinity requested a review from a team as a code owner March 26, 2025 12:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue with the isAuthenticated method not validating expired delegation chains and updates its signature from asynchronous to synchronous. It also updates the CI workflows to use the latest Ubuntu image and adjusts test usage accordingly.

  • Fix isAuthenticated to validate delegation expiry
  • Update tests to remove unnecessary async/await usage on isAuthenticated
  • Update workflow configurations to use ubuntu-latest

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.github/workflows/mitm.yml Updated OS version from ubuntu-20.04 to ubuntu-latest
packages/auth-client/src/index.test.ts Removed await for isAuthenticated and added additional checks in tests
.github/workflows/unit-tests.yml Updated OS version in CI workflow
.github/workflows/e2e-tests.yml Updated OS version in CI workflow
packages/use-auth-client/src/use-auth-client.ts Simplified then block to match the synchronous isAuthenticated signature
packages/auth-client/src/index.ts Changed isAuthenticated from asynchronous to synchronous with added delegation expiry check
Comments suppressed due to low confidence (3)

.github/workflows/mitm.yml:18

  • Switching from a fixed Ubuntu version to ubuntu-latest can introduce environmental changes; please verify that all tests continue to pass reliably under the updated CI environment.
os: [ubuntu-latest]

packages/auth-client/src/index.test.ts:55

  • Updating the test to remove the await is consistent with the synchronous nature of isAuthenticated; ensure that similar changes are made in all affected tests.
expect(test.isAuthenticated()).toBe(false);

packages/auth-client/src/index.ts:437

  • Changing the signature of isAuthenticated to synchronous impacts its usage—please update the documentation and ensure that consumers remove any awaiting of its result.
public isAuthenticated(): boolean {

@asabates-dfinity asabates-dfinity force-pushed the asabates/extended-is-authorized branch from 47a837a to 8e08e59 Compare March 26, 2025 17:42
@@ -428,8 +434,12 @@ export class AuthClient {
return this._identity;
}

public async isAuthenticated(): Promise<boolean> {
return !this.getIdentity().getPrincipal().isAnonymous() && this._chain !== null;
public 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.

I prefer to leave this asynchronous. If we decide to add support for validating the signatures for all delegations in the chain (currently haven't adopted this yet because we wanted to avoid the secp256k1 dependency), this operation will most likely have async behavior.

Breaking the API is costly, and this is why we tagged it async preemptively, even years in advance

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, reverted here fb339a1

setAuthClient(client);
setIdentity(client.getIdentity());
setIsAuthenticated(await client.isAuthenticated());
Copy link
Contributor

Choose a reason for hiding this comment

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

see here also, I'd like this reverted

Copy link
Author

Choose a reason for hiding this comment

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

Fixed here fb339a1

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a large formatting diff, presumably from autoformatting. Which tool did you use for this?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed here fb339a1, I was just using VSCode with prettier and eslint :)

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.

2 participants