Commit Graph

170 Commits

Author SHA1 Message Date
Maciej Zieniuk
c57d220e04 [PM-31191] Move KDF from Auth to KM constants (#7709)
* Move KDF from Auth to KM constants

* formatting
2026-05-27 12:00:29 -05:00
Rui Tomé
a56946fd13 [PM-37486] Remove IPolicyService and associated dead code (#7672)
* Refactor InitPendingOrganizationValidator to remove IPolicyService dependency and replace with IPolicyRequirementQuery for policy checks. Update related tests to reflect changes in policy validation logic.

* Refactor AccountsController and related validators to replace IPolicyService with IPolicyRequirementQuery for policy checks. Update tests accordingly to reflect changes in policy validation logic.

* Remove IPolicyService and related implementations from the codebase, updating PolicyServiceCollectionExtensions and deleting associated tests. This change streamlines policy management by relying on IPolicyRequirementQuery for policy checks.

* Refactor OrganizationUserRepository to remove GetByUserIdWithPolicyDetailsAsync method and associated tests.

* Remove unused stored procedures: OrganizationUser_ReadByUserIdWithPolicyDetails and PolicyDetails_ReadByUserId, as they are no longer called in the codebase.

* Remove OrganizationUserPolicyDetails class and associated test fixtures, as they are no longer needed in the codebase.

* Refactor BaseRequestValidatorTests to replace IPolicyService with IPolicyRequirementQuery for SSO validation checks. Update related test logic to ensure accurate policy validation outcomes. Clean up unused test fixtures in PolicyFixtures.cs to streamline the codebase.

* Refactor BaseRequestValidator and SsoRequestValidator to improve readability by storing policy requirement results in local variables before returning values. This change enhances code clarity while maintaining existing functionality.

* Refactor AccountsController to improve clarity by storing the result of the policy requirement query in a local variable before returning the enforced options. This change enhances code readability while preserving existing functionality.

* Revert "Remove unused stored procedures: OrganizationUser_ReadByUserIdWithPolicyDetails and PolicyDetails_ReadByUserId, as they are no longer called in the codebase."

This reverts commit 0f4fdca6e7.
2026-05-25 14:27:47 +01:00
renovate[bot]
c27eebbcff [deps]: Update dotnet monorepo to v10 (major) (#6634)
* [deps]: Update dotnet monorepo to v10

* fix up pins causing downgrades

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Derek Nance <dnance@bitwarden.com>
2026-05-21 11:28:32 -05:00
Jared McCannon
acf0c48a00 [PM-37259] - Update Sso Request Validator (#7676)
* Updated SsoRequestValidator to leverage OrgId from req

* Undoing unrelated change

* Updating tests. Removed unused query and tests. Updated SsoRequestValidator to leverage OrgId and retain multiple match hardening.

* updated xml. updated ssoorgids to orgids

* fixing some issues
2026-05-21 08:16:57 -05:00
Stephon Brown
4224933c62 [PM-35357] Update Trial Length Parameter (#7597)
* test(billing): Add unit tests for TrialInitiationCache

* feat(billing): Add trial initiation cache interface and implementation

* feat(billing): Register trial initiation cache services

* feat(core): Add trial properties to OrganizationSignup model

* feat(mail): Update trial verification email model and services for TrialInitiationId

* feat(billing): Enhance TrialSendVerificationEmailRequestModel validation

* test(billing): Add tests for TrialSendVerificationEmailRequestModel validation

* feat(billing): Introduce default trial length constant

* refactor(identity): Use constant for default trial length in AccountsController

* test(identity): Update accounts controller tests for default trial length constant

* feat(billing): Integrate trial initiation into email sending command

* feat(billing): Add TrialLength to SubscriptionSetup model

* feat(billing): Map TrialLength in OrganizationSale creation

* feat(billing): Allow custom trial length in organization billing service

* feat(admin-console): Add TrialLength and TrialInitiationId to organization creation requests

* feat(admin-console): Validate trial length during cloud organization signup

* test(admin-console): Add tests for organization create request trial properties

* test(admin-console): Add tests for CloudOrganizationSignUpCommand trial length validation

* refactor(TrialInitiationCache): change validation method to retrieval

* test(TrialInitiationCache): update tests for GetAndRemoveAsync

* feat(OrganizationSignUp): refactor trial validation to command

* test(OrganizationSignUp): add trial validation scenarios

* test(OrganizationSignUp): nullify TrialLength in unrelated tests

* fix(billing): dotnet format

* refactor: remove `TrialInitiationId` property from data models
refactor: update mail service interfaces and implementations

* refactor: remove `ITrialInitiationCache` infrastructure
test: update `CloudOrganizationSignUpCommandTests` for trial validation

* refactor: update `SendTrialInitiationEmailForRegistrationCommand`

* refactor: update `CloudOrganizationSignUpCommand` trial length validation

* test(organization): fix plan call in tests

* test(billing): fix test settings
2026-05-18 09:32:04 -04:00
Jared Snider
eb9c8c9aa9 Auth/PM-37621 - Fix Device.LastActivityDate surfacing legacy NULL rows as DateTime.UtcNow (#7649)
* PM-37621 - Fix Device.LastActivityDate surfacing legacy NULL rows as DateTime.UtcNow

Dapper's deserializer skips the property setter when a nullable column is
DBNull, leaving the property at its CLR default. The field initializer
`public DateTime? LastActivityDate { get; internal set; } = DateTime.UtcNow`
poisoned that default, so rows whose LastActivityDate column was NULL (e.g.
devices created before the column existed) read back as the current time.

Drop the initializer, relax `internal set` to `set`, and stamp
LastActivityDate explicitly at the two creation call sites
(DeviceValidator.GetDeviceFromRequest and DeviceRequestModel.ToDevice). Adds
an integration regression test that creates a device with an explicit null
LastActivityDate and asserts the read path surfaces null. Augments
DeviceValidatorTests.GetDeviceFromRequest_RawDeviceInfoValid_ReturnsDevice
to lock in the creation-time stamp.

* PM-37621 - DeviceSeeder - creation should set LastActivityDate
2026-05-15 16:34:08 -04:00
Jared Snider
450159a1e2 Auth/PM-37166 - Devices - add client version (#7632)
* PM-37166 - Add ClientVersion to Device entity and repository contract

* PM-37166 - Add ClientVersion SQL schema and refactor bump stored procedures

* PM-37166 - Implement combined bump in repositories and add EF migrations

EF snapshot regeneration also absorbs Collection / CollectionGroup /
CollectionUser namespace moves (Bit.Infrastructure.EntityFramework.Models
-> Bit.Infrastructure.EntityFramework.AdminConsole.Models) that were left
un-regenerated by PR #7523 (PM-35489). Namespace-only, no SQL impact;
flagged with the AC team for awareness.

* PM-37166 - Replace DeviceLastActivityCacheService with DeviceDataCacheService

* PM-37166 - Replace BumpDeviceLastActivityDateCommand with BumpDeviceDataCommand

* PM-37166 - Pass ClientVersion through identity request validators

* PM-37166 - Align migration script with SQL style guide

Refresh Device_ReadBy* sprocs after DeviceView change so their cached
schema picks up ClientVersion, swap retired-sproc drops to
DROP PROCEDURE IF EXISTS, and tighten the ALTER TABLE indent in step 1.

* PM-37166 - Rename BumpData to UpdateLastActivity across device write pathway

The "BumpData" naming was vague — "data" named a category, not the thing
being written. Rename to "UpdateLastActivity" everywhere: SP, repositories,
command, cache, validators, tests. "Last activity" names the event of the
device's most recent appearance; LastActivityDate (when) and ClientVersion
(what was running) are facts we observed about that event. ClientVersion is
treated as a property of the activity event rather than an independent value,
so future last-observed properties (last IP, OS, etc.) slot in without renaming.

The SQL layer uses Update* per architect guidance on bitwarden/server#7302;
the Bump* SPs in this codebase are legacy and not being extended. The
extensibility note lives on IUpdateDeviceLastActivityCommand with short
pointers from the SP, repo, and cache.

Cache key prefix changes from device:data: to device:last-activity: — safe
because the cache is only a write-suppression optimization (SP guards ensure
correctness) and entries TTL out within 24h.

Migration renamed to 2026-05-14 to reflect the rewrite.

* PM-37166 - Add UTF-8 BOM to device last activity cache files

Aligns file encoding with the repo's .editorconfig (charset = utf-8-bom for .cs) so dotnet format --verify-no-changes passes.

* PM-37166 - Compare LastActivityDate at second precision in device creation test

GetManyByUserIdWithDeviceAuth_ReturnsLastActivityDate_ForNewDeviceAsync was
flaking on SqlServer: Dapper binds DateTime params as legacy `datetime`
(~3.33ms granularity), so the entity initializer's UtcNow can be rounded a
few ms earlier than the in-memory `beforeCreation` capture, making a strict
>= comparison occasionally false. Truncate both sides to the second to
absorb that drift while still rejecting stale or defaulted values.

* PM-37166 - Rename Device.ClientVersion EF migration

Renames migration class/files from AddDeviceClientVersionRefactorDeviceDataBump
to AddDeviceClientVersion to drop stale "Bump" terminology and the misleading
"RefactorDeviceData" prefix. The EF migration only adds the ClientVersion
column; the BumpData -> UpdateLastActivity SP refactor lives in MSSQL .sql
files and has no EF representation.

* PM-37166 - Document null-is-no-op semantics for ClientVersion on IUpdateDeviceLastActivityCommand

Tighten the interface-level summary and add a <param> note clarifying that
a null clientVersion is treated as "no opinion" and will not clear an
existing stored value.

* PM-37166 - Regenerate Device.ClientVersion EF migration on post-#7634 baseline

PR #7634 merged AddLastApiKeyRotationDateToUserTable into main while this
branch was open. The prior AddDeviceClientVersion migration's frozen model
snapshot (its .Designer.cs) was generated before that PR landed, so it did
not include User.LastApiKeyRotationDate. Applying migrations incrementally
against that stale snapshot would produce an inconsistent model graph.

Regenerated AddDeviceClientVersion on top of the merged-from-main baseline
so the new .Designer.cs files include both columns. The migration body
itself still only adds Device.ClientVersion; the top-level
DatabaseContextModelSnapshot.cs files were already correct from git's
three-way merge.

New timestamps (20260514192xxx) come after the User migration
(20260514011xxx), preserving migration order.

* PM-37166 - util/Migrator/DbScripts/2026-05-14_00_AddDeviceClientVersionAndUpdateLastActivitySp.sql - fix wrong comment

* PM-37166 - Bump Device.ClientVersion column width from 20 to 43

43 is the upper bound of Version.ToString() for any input parseable by
Version.TryParse — four Int32 components (Int32.MaxValue = 10 digits)
joined by 3 dots. Sizing to the type's mathematical max prevents
SQL Server error 8152 on malformed/hostile Bitwarden-Client-Version
headers without paying the cost of normalization at the call sites.

Real Bitwarden CalVer (YYYY.M.B) remains well within bounds at ~9 chars.

- Device.cs [MaxLength] + entity doc comment
- SSDT table + 4 stored procedures
- Cloud migration ALTER TABLE + SP parameters
- EF migrations regenerated for MySQL / Postgres / SQLite

* PM-37166 - Defer dropping old single-column UpdateLastActivityDate SPs to follow-up

Server and DB deploys are decoupled, so dropping the old SPs in the same migration that
introduces the new combined ones would break server rollback. Per discussion on PR #7632:

- Remove DROP PROCEDURE statements from the migration; replace with a note explaining the deferral.
- Restore the old Device_UpdateLastActivityDate{ById,ByIdentifierUserId}.sql files in src/Sql/dbo
  so the SSDT source-of-truth stays aligned with deployed schema (EDD).

A follow-up ticket will drop the old SPs and delete the .sql files together once we're
confident no deployed server version still calls them.

* PM-37166 - Pass @LastActivityDate into Device_UpdateLastActivity SPs

Bitwarden convention is to compute timestamps in the application layer
and pass them as DATETIME2(7) params, not call GETUTCDATE() inside SPs.
Dapper repo now computes DateTime.UtcNow locally (matching the EF repo
and UserRepository.cs precedent) and passes LastActivityDate through.
2026-05-14 20:22:13 -04:00
Vincent Salucci
9b1d82c1e9 [PM-19790] [PM-19791] Remove policy requirements feature flag references and definition (#7596)
* chore: remove ff false conditional in WebAuthnController, refs PM-19790

* chore: remove policy reqs flag ref, imports, instantiation, refs PM-19790

* chore: clean up unused imports, instantiations, refs PM-19790

* chore: remove policy reqs ff references, refs PM-19790

* remove policy reqs ff refs from SsoRequestValidatorTests, refs PM-19790

* chore: remove unused method in WebAuthnController and update imports, refs PM-19790

* fix: update WebAuthnControllerTests to account for policy reqs ff removal, refs PM-19790

* fix: update SsoRequestValidatorTests to remove IPolicyService checks, refs PM-19790

* chore: remove policy reqs ff definition, refs PM-19790

* chore: remove unused policy service constructor parameter, refs PM-19790

* chore: removed unnecessary comment about feature flag state from SsoRequestValidatorTests, refs PM-19790
2026-05-08 10:07:56 -05:00
renovate[bot]
3227cf4f14 [deps] Tools: Pin dependencies (#6204)
* [deps] Tools: Pin dependencies

* [PM-24840] updated dependencies that are required with Net 10 switch

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Alex Dragovich <adragovich@bitwarden.com>
Co-authored-by: Alex Dragovich <46065570+itsadrago@users.noreply.github.com>
Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
2026-05-07 10:06:10 -07:00
Ike
da5fc0e10b [PM-31631] update password pre-login salt response (#7469)
feat: add salt to password pre-login response

  - Include salt in GetDefaultKdf so clients receive the correct algorithm and salt for password authentication
  - Normalize email when looking up the salt to ensure consistent matching
  - Add startup warning for self-hosted users about the new salt requirement
  - Use CoreHelpers to check for the salt value in the accounts controller
  - Enforce nullable reference types and add explanatory comments in the accounts controller
  - Add unit and integration test coverage for the new salt property
2026-05-05 16:30:39 -04:00
Ike
90f451bc60 [PM-33417] WebAuthn cache (#7500)
feat: Add WebAuthn Cache
  - Add IWebAuthnChallengeCacheProvider with distributed cache implementation for storing WebAuthn Challenges
  - Inject the cache provider into AssertWebAuthnLoginCredentialCommand and WebAuthnGrantValidator so challenges can be stored
  - Use a static token lifetime for WebAuthnLoginAssertionOptionsTokenable and enable nullable reference types on the tokenable
  - Add unit tests for the cache provider, the assertion command, and the WebAuthn controller; add Identity integration and unit tests for WebAuthnGrantValidator with a FakeWebAuthnAuthenticator helper
2026-04-30 09:21:03 -04:00
Bernd Schoolmann
a714278b9a [PM-35306] Fix password change not working when using the unlock and authentication data models (#7505)
* Fix password change not working when using the unlock and authentication data models

* Cleanup test

* Cleanup test

* Clean up test comment

* Address feedback

* Fix tests

* Fix tests

* Update src/Core/KeyManagement/Models/Api/Request/MasterPasswordAuthenticationDataRequestModel.cs

Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com>

---------

Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com>
2026-04-21 12:07:50 -04:00
Eli Grubb
9e1215ae8e [PM-27278] add AccountKeysRequestModel to RegisterFinishRequestModel for account encryption v2 support (#6798)
Deprecating V1 User Asymmetric Key information in favor of new V2 User Asymmetric Account Keys structure.

This PR adds support for the new AccountKeys structure while maintaining support for the legacy UserAsymmetricKey-based flow. Validation is updated to check either AccountKeys or UserAsymmetricKeys are updated. Tests include modeling for both scenarios.
2026-04-21 12:10:56 +09:00
Patrick-Pimentel-Bitwarden
e113dbd263 feat: [PM-32626] standardize unlock and authentication validation
- Standardize validation on `RegisterFinishRequestModel` so Auth and Unlock data are both required and consistently validated
  - Add salt validation to both unlock and authentication data
  - Enforce that Auth and Unlock data contain matching values
  - Keep validation backwards compatible with older clients
  - Add and update unit tests covering the new validation rules and error messages

Co-authored-by: Ike Kottlowski <ikottlowski@bitwarden.com>
2026-04-17 10:47:09 -04:00
cyprain-okeke
279c3bc94a [PM-24927] Add payment optional support to trial initiation flow (#7418)
* Implement the payment option properties

* Fix the lint error

* Remove payment-optional feature flag
2026-04-17 13:16:11 +01:00
Jared Snider
28902acec8 Auth/Innovation/PM-4517 - Device Management - Add Last Activity Date (#7302)
* PM-4517 - Add LastActivityDate to Device entity, interfaces, DTOs, and response models

Adds the LastActivityDate nullable DateTime property to the Device entity,
IDeviceRepository interface (BumpLastActivityDateByIdAsync and
BumpLastActivityDateByIdentifierAsync), DeviceAuthDetails DTO,
DeviceResponseModel, DeviceAuthRequestResponseModel, and the
DevicesLastActivityDate feature flag key in Constants.

* PM-4517 - Add BumpDeviceLastActivityDateCommand with distributed cache guard

Adds IBumpDeviceLastActivityDateCommand and IDeviceLastActivityCacheService
interfaces with their implementations. The cache service uses the persistent
keyed IDistributedCache (Cosmos DB in cloud, SQL Server in self-hosted) with
a 48h TTL to guard against redundant DB writes within the same calendar day.
Moves device DI registration into a consolidated AddDeviceServices() extension.

* PM-4517 - Add LastActivityDate SQL schema, stored procedures, and MSSQL migration

Adds LastActivityDate DATETIME2 column to the Device table. Updates Device_Create
and Device_Update stored procedures. Adds Device_BumpLastActivityDateById and
Device_BumpLastActivityDateByIdentifier stored procedures with a CAST AS DATE
guard as a fallback against redundant writes when the application-layer cache
is unavailable.

* PM-4517 - Implement LastActivityDate repository methods and EF migrations

Implements BumpLastActivityDateByIdAsync and BumpLastActivityDateByIdentifierAsync
in both Dapper (via stored procedures) and EF (via ExecuteUpdateAsync with a
date-level guard). Adds EF migrations for Postgres, SQLite, and MySQL.

* PM-4517 - Bump device LastActivityDate on login and refresh token

Wires IBumpDeviceLastActivityDateCommand into BaseRequestValidator (login path,
keyed on device.Id) and CustomTokenRequestValidator (refresh token path, keyed
on device identifier from subject claims). Both call sites are feature-flagged
behind DevicesLastActivityDate.

* PM-4517 - Move AddDeviceServices() to AddBaseServices alongside IDeviceService

Device services are not user features — co-locating them with IDeviceService
in AddBaseServices is more cohesive than nesting them inside AddUserServices.

* PM-4517 - Swallow transient LastActivityDate bump failures to prevent auth disruption

* PM-4517 - Fix DeviceAuthDetails Dapper constructor parameter order to match LastActivityDate column position

* PM-4517 - Add edge case tests for BumpDeviceLastActivityForRefreshAsync guard conditions

* PM-4517 - Add tests for BumpLastActivityDate flag-disabled, null-device, and happy-path cases

* PM-4517 - Add PM-34091 cleanup TODOs to all DevicesLastActivityDate feature flag sites

* PM-4517 - Refine PM-34091 cleanup TODOs and add missing feature flag disabled test for refresh path

* PM-4517 - Remove redundant LastActivityDate shadow property from DeviceAuthDetails

* PM-4517 - Use CultureInfo.InvariantCulture in date string formatting for CA1305

* PM-4517 - Make _bumpDeviceLastActivityDateCommand protected in base to remove duplicate field in derived class

* PM-4517 - Scope device last activity cache key by userId to prevent cross-user collisions

The Device table's unique constraint is (UserId, Identifier), not Identifier alone,
so two users can share the same device identifier (e.g. account switching in a browser).
Scoping the cache key to device:last-activity:{userId}:{identifier} ensures that a cache
hit for one user never suppresses a DB write for another.

Also adds userId to BumpByIdAsync signature and reorders params to be consistent with
BumpByIdentifierAsync(string identifier, Guid userId).

* PM-4517 - Widen try-catch in TryBumpDeviceLastActivityForRefreshAsync and add happy-path test

Renames BumpDeviceLastActivityForRefreshAsync to TryBumpDeviceLastActivityForRefreshAsync
to signal the swallow-on-error intent. Moves the try-catch to wrap the entire method body,
including GetSubjectId() which can throw InvalidOperationException, so no exception can
escape and disrupt token refresh. Also moves the XML doc comment to RecordActivityForInstallation
where it belongs, and adds a happy-path test verifying BumpByIdentifierAsync is called
with the correct identifier and userId.

* PM-4517 - Capture DateTime.UtcNow once in EF bump methods to ensure consistent timestamp

Avoids a minor inconsistency where the WHERE filter and SET clause could evaluate
DateTime.UtcNow at slightly different moments, aligning behavior with the SQL stored
procedures which use a single @RevisionDate parameter.

* PM-4517 - Preserve LastActivityDate on Device_Update when null to prevent regressions

Device_Update previously overwrote LastActivityDate unconditionally, meaning any unrelated
device update (push token rotation, trust changes, deactivation) could silently regress a
recently-bumped value. COALESCE preserves the existing DB value when NULL is passed, while
still allowing callers to set it in the same write by passing a non-NULL value. The EF
ReplaceAsync override applies the same semantics via IsModified = false. Integration test
added to cover the preserve-on-null behaviour across all DB providers.

* PM-4517 - Add docs

* PM-4517 - Adjust docs

* PM-4517 - Add test coverage for BumpLastActivityDateByIdentifierAsync

* PM-4517 - Per PR feedback, add docs on IDeviceLastActivityCacheService

* PM-4517 - Per PR feedback, adjust IBumpDeviceLastActivityDateCommand.BumpById to be bump by device instead b/c it has all what we need.

* PM-4517 - Per PR feedback, add tech debt ticket.

* PM-4517 - Rename BumpByIdentifierAsync to BumpByIdentifierAndUserIdAsync across the board.

* PM-4517 - Per PR feedback, adjust stored proc names to meet SQL style requirements

* PM-4517 - Replace COALESCE with CASE in Device_Update to prevent stale non-null LastActivityDate overwrites

* PM-4517 - Add EF repository feature parity for replace logic + test to ensure we don't run into this again.

* PM-4517 - Fix DB migration order after main merge.

* PM-4517 - Regenerate EF DB migrations

* PM-4517 - actually regenerate EF DB migrations

* PM-4517 - Add LastActivityDate to Device_ReadActiveWithPendingAuthRequestsByUserId and integration tests
2026-04-16 11:45:26 -04:00
Patrick-Pimentel-Bitwarden
fc0ce255af Revert "fix(change-email): [PM-34742] Change Email Sets Salt (#7413)" (#7421)
This reverts commit 13eecfd605.
2026-04-08 11:05:57 -04:00
Patrick-Pimentel-Bitwarden
13eecfd605 fix(change-email): [PM-34742] Change Email Sets Salt (#7413)
* fix(change-email): [PM-34742] Change Email Sets Salt - Fixed prelogin to respond back with salt data coming from database.

* fix(change-email): [PM-34742] Change Email Sets Salt - Fixed change email.

* test(change-email): [PM-34742] Change Email Sets Salt - Updated and added more tests
2026-04-07 18:47:19 -04:00
Jimmy Vo
deff00b881 [PM-33043] Refactor PolicyService, CipherService, and TwoFactorAuthenticationValidator (#7214) 2026-03-26 12:10:21 -04:00
Ike
ffebc0d792 [PM- 30370] [PM-28827] Add Salt to Auth and KM DTOs (#7239)
feat: add `MasterPasswordSalt` to unlock and authentication flow

- Add optional `MasterPasswordSalt`:
    - `MasterPasswordUnlockAndAuthenticationData`
    - `RegisterFinishRequestModel`
    - `UserDecryptionOptionsBuilder`
- Add test coverage for explicit checks where appropriate in the above model updates
2026-03-25 16:02:33 -04:00
Todd Martin
063ae435cb chore(flags): [PM-33972] Remove pm-26140-marketing-initiated-premium-flow feature flag 2026-03-24 08:19:40 -04:00
Thomas Avery
53907c2f14 [PM-33162] Refactor user key rotation (#7201)
* Refactor user key rotation to use base data composition

* Update tests
2026-03-20 10:31:25 -05:00
Thomas Rittson
99454f5fe7 [PM-33216] Finalize RequireSsoPolicyRequirement (#7173)
* Add more efficient sproc to retrieve PolicyDetails
  for a single user. This closely matches the existing sproc
  used by PolicyService and should be performant enough
  to be used in the login flow

* Maintain feature flag for this critical path
2026-03-17 08:30:51 +10:00
John Harrington
c118f23e78 [PM-32885] Fix incorrect behavior for expired sends (#7203)
* fix unexpected/randomized error response for expired Sends
2026-03-16 13:19:35 -07:00
Todd Martin
f4956349b6 chore(flags): Remove pm-19394-send-access-control feature flag
* Remove feature flag.

* Fixed import statements.

* Fixed constructor.
2026-03-10 11:40:01 -04:00
Ike
df09fb6916 [PM-32424] Send Access Enumeration protection (#7166)
feat: add enumeration protection to email protected sends

- Implement enumeration protection for email-based protected sends
- Update SendAccess validator with new protection logic
- Change OTP generation failure logging from warning to error level
- Remove unused constants and update validator tests
2026-03-09 12:46:48 -04:00
Rui Tomé
ef4f4e352f [PM-21179] Add interface to check if user is enrolled in account recovery (#6993)
* Add validation for reset password key and account recovery enrollment in OrganizationUser

* Update admin approval logic to check account recovery enrollment and add tests for reset password key validation

* Enhance UserService validation to include account recovery enrollment and add unit test for empty or whitespace reset password key handling

* Refactor OrganizationUserUserDetailsQuery to validate reset password keys and add unit tests for filtering out invalid keys

* Update AdminRecoverAccountCommand to validate account recovery enrollment and adjust tests for whitespace reset password keys

* Enhance OrganizationUserRotationValidator to validate reset password keys, including filtering out whitespace-only keys, and add corresponding unit tests for validation logic.

* Refactor OrganizationUserUserDetailsQueryTests to remove unnecessary whitespace-only test cases for account recovery key validation.

* Refactor MemberResponseModel to use OrganizationUser's validation method for ResetPasswordEnrolled status and update corresponding unit test for clarity.

* Refactor OrganizationUsersController and response models to utilize OrganizationUser's validation method for ResetPasswordKey, ensuring consistent validation across the application. Add unit tests for OrganizationUser to verify key validation logic.

* Update OrganizationUserRotationValidator to handle null reset password keys and adjust tests for client-side bug. Add comments for future migration after resolving PM-31001.

* Fix whitespace issue in UserServiceTests.cs by removing BOM character from the file header.
2026-02-24 14:16:54 +00:00
Patrick-Pimentel-Bitwarden
3dbd17f61d feat(auth-validator): [Auth/PM-22975] Client Version Validator (#6588)
* feat(auth-validator): [PM-22975] Client Version Validator - Implementation.

* test(auth-validator): [PM-22975] Client Version Validator - Added tests.
2026-02-23 15:00:10 +00:00
Alex Dragovich
6d43cc43e3 [PM-31684] Remove email hashing for send access (#6945)
* [PM-31684] Remove email hashing for send access

* [PM-31684] switching the order of migration files

* [PM-31684] adding more migrations

* [PM-31684] Removing anon access emails field  and reusing emails field

* [PM-31684] cleanup before adding migrations back

* [PM-31684] restore original snapshots

* [PM-31684] restore original postgres snapshots

* [PM-31684] adding migrations

* [PM-31684] removing encryption attributes from emails request model

* [PM-31684] adding missing stored proc alters

* [PM-31684] Improved formatting for stored proc defs

* [PM-31684] adding necessary comment back

* [PM-31684] adding case-insensitive check on the server for send auth
2026-02-09 12:58:57 -08:00
Patrick-Pimentel-Bitwarden
c52f2e0d09 feat(register): [PM-27084] Account Register Uses New Data Types - Repush (#6855)
* feat(register): [PM-27084] Account Register Uses New Data Types - Changes.

* test(register): [PM-27084] Account Register Uses New Data Types - Added tests.

* fix(register): [PM-27084] Account Register Uses New Data Types - Added constant for feature flag.
2026-02-04 10:03:55 -05:00
Ike
5afdfa6fd1 [PM-30563] Change error response on Send Access token request (#6911)
* feat: remove invalid email response and instead return email and OTP required to protect against enumeration attacks.

* fix: fixing tests and dotnet format
2026-02-04 09:42:32 -05:00
Todd Martin
a27eda7df6 chore(flags): [PM-30613] Remove unused mjml-based-email-templates feature flag
* Removed old method.

* Removed IFeatureService.

* Fixed test.

* Renamed the v2 endpoint.

* Removed old Handlebars templates.

* Renamed v2 templates to remove v2 suffix.
2026-02-02 11:36:39 -05:00
Alex Dragovich
0544ec41d5 [PM-31394] use email address hash for send access email verification (#6921)
* [PM-31394] use email address hash for send access email verification

* [PM-31394] fixing identity server tests for send access

* [PM-31394] fixing more identity server tests for send access
2026-01-29 11:48:12 -08:00
Anders Åberg
40e293117d PM-2035: PRF Unlock (#6401)
* Initial refactor

* Add WebauthnPRFOptions to syncResponse

* MAYBE: Use KM owned ResponseModel?

* REVERT ^- Keep using PrfUnlockOptions for simplicity

This reverts commit 5a34e7dfa8.

* UserDecryptionOptions: Only send one credential

* format

* Update UserDecryptionOptions.cs

* format

* Added feature flag (#6600)
2026-01-26 07:18:42 -08:00
Todd Martin
c37412bacb chore(flags): Remove pm-1632-redirect-on-sso-required feature flag
* Remove feature flag.

* Update test title.

* Fixed some test failures.

* Fixed tests

* Removed method that's no longer used.

* Removed unneeded directive.
2026-01-20 10:03:33 -05:00
Patrick-Pimentel-Bitwarden
029a5f6a2d Revert "feat(register): [PM-27084] Account Register Uses New Data Types (#6715)" (#6854)
This reverts commit 8cb8030534.
2026-01-15 21:19:16 +00:00
Patrick-Pimentel-Bitwarden
8cb8030534 feat(register): [PM-27084] Account Register Uses New Data Types (#6715)
* feat(register): [PM-27084] Account Register Uses New Data Types - Implementation

* test(register): [PM-27084] Account Register Uses New Data Types - Added tests
2026-01-15 15:55:27 -05:00
Justin Baur
d559b1da11 Make CA1304 & CA1305 warnings (#6813) 2026-01-13 04:02:56 -05:00
Todd Martin
94cd6fbff6 chore(flags): [PM-28337] Remove account recovery permission feature flag
* Removed pm-24425-send-2fa-failed-email

* Remove feature flag

* Linting

* Removed tests and cleaned up comment.
2026-01-11 12:04:10 -05:00
Dave
4fdc4b1b49 refactor(base-request-validator) [PM-28621] Unwind pm-21153 Feature Flag (#6730)
* refactor(base-request-validator) [PM-28621]: Remove feature flagged logic and constant.

* refactor(base-request-validator) [PM-28621]: Update tests to reflect unwound feature flag.
2025-12-12 15:38:21 -05:00
Todd Martin
bd75c71d10 chore(feature-flag): [PM-28331] Remove pm-24425-send-2fa-failed-email feature flag
* Removed pm-24425-send-2fa-failed-email

* Removed flagged logic.
2025-12-08 13:42:54 -05:00
Ike
8a67aafbe5 [PM-1632] Redirect on SsoRequired - return SsoOrganizationIdentifier (#6597)
feat: add SSO request validation and organization identifier lookup

- Implement SsoRequestValidator to validate SSO requirements
- Add UserSsoOrganizationIdentifierQuery to fetch organization identifiers
- Create SsoOrganizationIdentifier custom response for SSO redirects
- Add feature flag (RedirectOnSsoRequired) for gradual rollout
- Register validators and queries in dependency injection
- Create RequestValidationConstants to reduce magic strings
- Add comprehensive test coverage for validation logic
- Update BaseRequestValidator to consume SsoRequestValidator
2025-11-30 16:55:47 -05:00
rr-bw
5fb69e42b0 feat(marketing-initiated-premium): (Auth) [PM-27541] Add optional marketing param to email verification link (#6604)
Adds an optional `&fromMarketing=premium` query parameter to the verification email link.

Feature flag: `"pm-26140-marketing-initiated-premium-flow"`
2025-11-24 15:06:16 -08:00
Patrick-Pimentel-Bitwarden
59b6cd0cdb feat(prelogin): [Auth/PM-27062] Prelogin New Response (#6583)
* feat(prelogin): [PM-27062] Prelogin New Response - Initial changes to support new data coming back from prelogin.

* test(prelogin): [PM-27062] Prelogin New Response - Added tests.
2025-11-20 15:43:01 -05:00
Patrick-Pimentel-Bitwarden
7eaca9bb7d Revert "feat(prelogin): [Auth/PM-27062] Prelogin New Response (#6577)" (#6582)
This reverts commit 92e511284b.

Merged without feature flag code and before QA could get their review done.
2025-11-14 21:42:14 +00:00
Patrick-Pimentel-Bitwarden
92e511284b feat(prelogin): [Auth/PM-27062] Prelogin New Response (#6577)
* feat(prelogin): [PM-27062] Prelogin New Response - Initial changes to support new data coming back from prelogin.

* test(prelogin): [PM-27062] Prelogin New Response - Added tests.
2025-11-14 19:33:31 +00:00
Dave
bda2bd8ac1 fix(base-request-validator) [PM-21153] Recovery Code Not Functioning for SSO-required Users (#6481)
* chore(feature-flag-keys) [PM-21153]: Add feature flag key for BaseRequestValidator changes.

* fix(base-request-validator) [PM-21153]: Add validation state model for composable validation scenarios.

* fix(base-request-validator) [PM-21153]: Update BaseRequestValidator to allow validation scenarios to be composable.

* fix(base-request-validator) [PM-21153]: Remove validation state object in favor of validator context, per team discussion.

* feat(base-request-validator) [PM-21153]: Update tests to use issue feature flag, both execution paths.

* fix(base-request-validator) [PM-21153]: Fix a null dictionary check.

* chore(base-request-validator) [PM-21153]: Add unit tests around behavior addressed in this feature.

* chore(base-request-validator) [PM-21153]: Update comments for clarity.

* chore(base-request-validator-tests) [PM-21153]: Update verbiage for tests.

* fix(base-request-validator) [PM-21153]: Update validators to no longer need completed scheme management, use 2FA flag for recovery scenarios.

* fix(base-request-validator-tests) [PM-21153]: Customize CustomValidatorRequestContext fixture to allow for setting of request-specific flags as part of the request validation (not eagerly truthy).
2025-11-03 12:24:00 -05:00
Ike
9ce1ecba49 [PM-25240] Send Access OTP email in MJML format (#6411)
feat: Add MJML email templates for Send Email OTP
feat: Implement MJML-based email templates for Send OTP functionality
feat: Add feature flag support for Send Email OTP v2 emails
feat: Update email view models and call sites for Send Email OTP

fix: Modify the directory structure for MJML templates to have Auth directory for better team ownership
fix: Rename `hero.js` to `mj-bw-hero.js`

---
Co-authored-by: Todd Martin <106564991+trmartin4@users.noreply.github.com>
2025-10-22 15:13:31 -04:00
Maciej Zieniuk
6324f692b8 [PM-23249] Prevent log-out when changing KDF settings (#6349)
* Prevent log-out when changing KDF settings with feature flag.

* validate salt unchanged for user to throw bad request (400), not internal server error (500)

* change kdf integration tests

* failing tests

* iuncorrect tests wording

* conditional logout

* log out reason as enum

* explicit naming
2025-10-21 19:03:25 +02:00
Dave
629672c4b0 Add tests for ProfileService (#6466)
* feat(profile-service) [PM-24621]: Add ProfileService test fixtures.

* feat(profile-service) [PM-24621]: Add ProfileService test suite.

* feat(profile-servie) [PM-24621]: Re-spell to more consistently use constants across tests.
2025-10-20 11:45:11 -04:00