Skip to content

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Jul 1, 2025

Quoting from Silhouette’s BearerTokenAuthenticator docstring for update:

   * Updates the authenticator with the new last used date in the backing store.
   *
   * We needn't embed the token in the response here because the token itself will not be changed.
   * Only the authenticator in the backing store will be changed.

Our implementation of update did something else. It fetched any authenticator of the same user and changed not only the last used date time but also the value. So if update was called by silhouette on a datastore token, it could happen that an Authentication token was changed.

This bug has been in place ever since #2149 but to trigger it, a request has to be sent to /api/ with a valid datastore token. We don’t usually do that, but the libs tests seem to do so now. That is also a libs bug.

This also caused the webknossos-libs tests to get 401 responses when using X-Auth-Tokens that were lost in this way.

Steps to test:

  • Requests with X-Auth-Token should work, token should stay fixed.
  • Normal datastore/tracingstore operation should also still work

  • Added changelog entry (create a $PR_NUMBER.md file in unreleased_changes or use ./tools/create-changelog-entry.py)
  • Considered common edge cases

Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

📝 Walkthrough

Walkthrough

The update process for bearer token authenticators was simplified by revising the update logic to only refresh the last used timestamp, removing unnecessary database context dependencies and redundant field updates. The token data access object was refactored to support this streamlined update, and a bug causing premature token expiration was fixed.

Changes

Files/Paths Change Summary
app/security/BearerTokenAuthenticatorRepository.scala Simplified the update method to refresh only the last used timestamp; removed unused imports.
app/security/Token.scala Removed updateValues method; added updateLastUsedDateTime for updating only the last used time.
unreleased_changes/8738.md Added a bugfix note about correcting premature token expiration.

Possibly related PRs

Suggested reviewers

  • frcroth

Poem

In the warren of code, a token hops anew,
No longer expiring before it is due.
With timestamps refreshed and clutter swept clean,
Our authenticator runs swift and keen.
🐇✨
Bugs are but shadows—now out of view!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c9bb64 and e095ed2.

📒 Files selected for processing (3)
  • app/security/BearerTokenAuthenticatorRepository.scala (1 hunks)
  • app/security/Token.scala (1 hunks)
  • unreleased_changes/8738.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
app/security/Token.scala (1)
Learnt from: frcroth
PR: scalableminds/webknossos#8236
File: webknossos-datastore/app/com/scalableminds/webknossos/datastore/services/mesh/NeuroglancerPrecomputedMeshFileService.scala:161-166
Timestamp: 2025-04-28T14:18:04.368Z
Learning: In Scala for-comprehensions with the Fox error handling monad, `Fox.fromBool()` expressions should use the `<-` binding operator instead of the `=` assignment operator to properly propagate error conditions. Using `=` will cause validation failures to be silently ignored.
🧬 Code Graph Analysis (1)
app/security/Token.scala (1)
app/utils/sql/SqlInterpolation.scala (2)
  • q (19-38)
  • asUpdate (73-73)
🪛 LanguageTool
unreleased_changes/8738.md

[duplication] ~1-~1: Possible typo: you repeated a word.
Context: ### Fixed - Fixed a bug where authentication tokens would...

(ENGLISH_WORD_REPEAT_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push
🔇 Additional comments (3)
unreleased_changes/8738.md (1)

1-2: Changelog entry looks good.

The markdown formatting is correct - the first "Fixed" is the section header and the second "Fixed" begins the bullet point. The static analysis tool's duplication warning is a false positive for standard changelog formatting.

app/security/Token.scala (1)

118-123: Excellent implementation of the token update fix.

This new method correctly addresses the core issue by only updating the lastUsedDateTime field without touching the token value. The simplified implementation removes unnecessary database context dependencies and properly identifies tokens by their value string rather than internal ID.

app/security/BearerTokenAuthenticatorRepository.scala (1)

21-29: Well-implemented fix for the token overwriting issue.

The simplified update method now correctly addresses the problem described in the PR objectives. By directly calling tokenDAO.updateLastUsedDateTime, it ensures only the last used timestamp is updated without changing the token value. The error handling and return behavior remain consistent with the original API contract.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fm3 fm3 self-assigned this Jul 1, 2025
@fm3 fm3 marked this pull request as ready for review July 1, 2025 15:17
@fm3 fm3 requested a review from MichaelBuessemeyer July 1, 2025 15:17
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this. I did some basic testing like normal annotation and viewing an annotation via a shared public link incl. token. All seemed to work.

I skipped explicit testing via self written requests using X-Auth-Token. If I should still do this please just ping me.

@fm3 fm3 merged commit 026cde4 into master Jul 2, 2025
5 checks passed
@fm3 fm3 deleted the silhouette-tokens-update-lastused branch July 2, 2025 09:22
@coderabbitai coderabbitai bot mentioned this pull request Aug 28, 2025
9 tasks
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.

2 participants