Skip to content

[PM-30993] Better Error Message for Expired Invitation Tokens#6971

Merged
sven-bitwarden merged 17 commits intomainfrom
ac/pm-30993/update-expired-token-exception-message
Mar 20, 2026
Merged

[PM-30993] Better Error Message for Expired Invitation Tokens#6971
sven-bitwarden merged 17 commits intomainfrom
ac/pm-30993/update-expired-token-exception-message

Conversation

@sven-bitwarden
Copy link
Copy Markdown
Contributor

@sven-bitwarden sven-bitwarden commented Feb 10, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-30993

📔 Objective

The server currently sends a nondescript Invalid token. error message when accepting an invalid token. While technically true, we want to be kinder to users accepting expired tokens, giving them a better error message.

Other Considerations

I thought about enhancing the Tokenable API to be return a TokenableValidationResult, which could mirror the existing inheritance hierarchy to return objects that indicate what went wrong. For example, Tokenable returns TokenableValidationResult, ExpiringTokenable returns ExpiringTokenableValidationResult.. each tacking on new metadata.

I opted not to do this, as this is so far the only Tokenable area that is interested in knowing what validation failed, and I didn't want to force the creation of N result classes (one for each Tokenable derivative).

📸 Screenshots

Screenshot 2026-02-10 at 7 51 20 AM

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 10, 2026

Logo
Checkmarx One – Scan Summary & Details2b8b9d9c-0545-48ce-87f9-c1f39172e676


New Issues (2) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1592
detailsMethod at line 1592 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
2 MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 1419
detailsMethod at line 1419 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector

Fixed Issues (1) Great job! The following issues were fixed in this Pull Request
Severity Issue Source File / Package
MEDIUM CSRF /src/Api/Vault/Controllers/CiphersController.cs: 293

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.64%. Comparing base (d977ba4) to head (e3499a4).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...ls/Business/Tokenables/TokenableValidationError.cs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6971   +/-   ##
=======================================
  Coverage   57.64%   57.64%           
=======================================
  Files        2033     2034    +1     
  Lines       89622    89626    +4     
  Branches     7977     7977           
=======================================
+ Hits        51660    51668    +8     
+ Misses      36106    36104    -2     
+ Partials     1856     1854    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sven-bitwarden sven-bitwarden marked this pull request as ready for review February 10, 2026 14:01
@sven-bitwarden sven-bitwarden requested review from a team as code owners February 10, 2026 14:01
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 10, 2026

Claude finished @sven-bitwarden's task in 2m 14s —— View job


Code Review: APPROVE

This PR introduces a TokenableValidationError record to distinguish between expired and invalid organization invite tokens, allowing callers to surface more specific error messages to clients. The new ValidateOrgUserInvite method consolidates validation logic into a single switch expression while preserving backward compatibility through existing ValidateOrgUserInviteStringToken overloads. The IsExpired property extracted on ExpiringTokenable cleanly separates expiration checking from the composite Valid property. Test coverage is thorough, including parameterized tests across all validation branches.

  • Gather context and read changed files
  • Analyze changes for issues
  • Post review findings

No issues found. Clean, well-structured PR with good test coverage.

JaredScar
JaredScar previously approved these changes Feb 10, 2026
Copy link
Copy Markdown
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment

Choose a reason for hiding this comment

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

Nice work!

JaredScar
JaredScar previously approved these changes Feb 11, 2026
…essage

# Conflicts:
#	src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/AcceptOrgUserCommand.cs
@sven-bitwarden
Copy link
Copy Markdown
Contributor Author

@JaredScar @JaredSnider-Bitwarden sorry y'all, my prior PR #6972 had a conflict here 🙏

JaredScar
JaredScar previously approved these changes Mar 9, 2026
@sven-bitwarden
Copy link
Copy Markdown
Contributor Author

@JaredScar @JaredSnider-Bitwarden 🙏 Through QA (which is difficult to QA expired tokens) we found an additional area that needs to benefit from the expired token message. This lead me to consolidate the error message creation logic.

@JaredSnider-Bitwarden I wasn't sure of your preference - we could have all of the methods inside of the static class point to the new method and check if it's null or not to determine the presence of an error. I left it as-is otherwise

Comment thread src/Core/Auth/Models/Business/Tokenables/OrgUserInviteTokenable.cs Outdated
Copy link
Copy Markdown
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment

Choose a reason for hiding this comment

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

Excellent work! Please be sure that the standard org invite and org invite registration flows are re-tested by QA. The tests give great confidence that those will be successful though!

@sonarqubecloud
Copy link
Copy Markdown

@sven-bitwarden sven-bitwarden merged commit 081bbe6 into main Mar 20, 2026
41 of 43 checks passed
@sven-bitwarden sven-bitwarden deleted the ac/pm-30993/update-expired-token-exception-message branch March 20, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants