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 download of public annotation, include access ctx in user cache key #7025

Merged
merged 3 commits into from
Apr 27, 2023

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Apr 26, 2023

Fetching the user object to write the NML failed for logged-out users, since it was missing the GlobalAccessContext modifier. However, the user cache was independent of the access context, making this work sometimes nonetheless (except if the cache was expired). Instead, the user cache should take the access context as cache key, avoiding leaking user info in unexpected contexts.

Steps to test:

  • Set annotation and its dataset to public
  • Download route should work even when logged out and no other requests have been sent in the past 3 minutes (use wget directly on /api/annotations/:id/download

Issues:


@fm3 fm3 self-assigned this Apr 26, 2023
@fm3 fm3 requested a review from philippotto April 26, 2023 11:40
@fm3 fm3 marked this pull request as ready for review April 26, 2023 11:40
result
}

def retrieve(loginInfo: LoginInfo): Future[Option[User]] =
userDAO.findOne(ObjectId(loginInfo.providerKey))(GlobalAccessContext).futureBox.map(_.toOption)
findOneCached(ObjectId(loginInfo.providerKey))(GlobalAccessContext).futureBox.map(_.toOption)
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 noticed that this didn’t use the cache. I think it is safe for it to do so now. This method is used by silhouette when authenticating requests. This change may save us quite a few database queries

@fm3
Copy link
Member Author

fm3 commented Apr 27, 2023

  • note to self: change cache key from whole access context to its toStringAnonymous representation to avoid cache invalidation when the requesting user is mutated

@@ -411,7 +411,7 @@ Expects:
skeletonAnnotationLayer =>
tracingStoreClient.getSkeletonTracing(skeletonAnnotationLayer, skeletonVersion)
} ?~> "annotation.download.fetchSkeletonLayer.failed"
user <- userService.findOneCached(annotation._user) ?~> "annotation.download.findUser.failed"
user <- userService.findOneCached(annotation._user)(GlobalAccessContext) ?~> "annotation.download.findUser.failed"
Copy link
Member

Choose a reason for hiding this comment

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

So, this failed before (ignoring the caching issue) because the requesting user didn't have access to the owning user?
Does this mean that an annotation owned by user A can be downloaded by user B (if B has access to it) even though user B might not be allowed to "read" user A? Because user A needs to be serialized into the annotation?
I'm wondering whether this circumvents the permission system a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that’s true. However, not all info about user A is serialized into the annotation. I believe we had a discussion about this some time ago and decided that it would be fair to say that a user publishing an annotation publishes their name with it. I’m open to having that discussion again, though. Also it might be worth double-checking what info is really needed for wk to show an annotation. The download only includes the name, but i think the annotation info request (which already works in the same way before this PR) also includes the email address.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, fair enough 👍

Also it might be worth double-checking what info is really needed for wk to show an annotation.

Yes, this is a good idea. One could also put in a dummy email value à la anonymous.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Works great 👍

@fm3 fm3 merged commit 918bfe6 into master Apr 27, 2023
2 checks passed
@fm3 fm3 deleted the fix-public-annotation-download branch April 27, 2023 09:20
hotzenklotz added a commit that referenced this pull request Apr 28, 2023
…ove_wkconnect

* 'master' of github.com:scalableminds/webknossos:
  Update docker compose commands + dev install readme (#7002)
  Add segment groups (#6966)
  Add screenshot nightly test for wkorg (#7030)
  Workaround for WebGL crash for datasets with many segmentation layers (#6995)
  Fix download of public annotation, include access ctx in user cache key (#7025)
  Fix that changing a segment color could lead to a crash (#7000)
  Add more error chaining to annotation download (#7023)
  Guard against NaNs in shader (#7018)
  Store editable mappings in multiple fossildb columns+keys (#6903)
  Context action to move tree to group (#7005)
  Release 23.05.0 (#7014)
  Remove vault cache when reloading dataset (#7007)
  Fix viewing of public datasets (#7010)
  Update screenshots scalebar positioning (#7003)
  Update team members (#6999)
hotzenklotz added a commit that referenced this pull request May 17, 2023
…ty-list-drawings

* 'master' of github.com:scalableminds/webknossos: (25 commits)
  Fix issues with styling in dark mode on login page (#7052)
  Fix nightly by setting missing token (#7048)
  Release 23.05.1 (#7042)
  DRY types in update_actions.ts (#7036)
  Remove some spammy logging from backend (#7039)
  Use zarr string fill values (#7017)
  Fix voxel offset for Neuroglancer Precomputed datasets (#7019)
  Log when user is activated (#7027)
  Fix exception in applying UpdateTreeGroupVisibility skeleton action (#7037)
  Fix organization storage layouting (#7034)
  Update docker compose commands + dev install readme (#7002)
  Add segment groups (#6966)
  Add screenshot nightly test for wkorg (#7030)
  Workaround for WebGL crash for datasets with many segmentation layers (#6995)
  Fix download of public annotation, include access ctx in user cache key (#7025)
  Fix that changing a segment color could lead to a crash (#7000)
  Add more error chaining to annotation download (#7023)
  Guard against NaNs in shader (#7018)
  Store editable mappings in multiple fossildb columns+keys (#6903)
  Context action to move tree to group (#7005)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sometimes, api/annotation/download, called by libs, returns 404
2 participants