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

always return KdfMemory and KdfParallelism #3398

Merged

Conversation

stefan0xC
Copy link
Contributor

As discussed in #3390 we could simplify the login logic a bit because the client will ignore the value of theses fields in case of PBKDF2 (whether they are unset or set to any value from trying out Argon2id as KDF)

With Argon2id those fields should never be null but always in a valid state. Be aware that if they are null the client will assume the bitwarden presets (i.e. m=64 and p=4) and if the fields are set to something else (not sure how this would happen but it's technically possible with a sqlite database) the login would most likely fail.

So there should not be a reason to panic.

Disclaimer: I've only tested this change with the web-vault. Since this seems to be also the behavior of vault.bitwarden.com I'm assuming that the other clients will not behave differently in this regard.

the client will ignore the value of theses fields in case of `PBKDF2`
(whether they are unset or left from trying out `Argon2id` as KDF).

with `Argon2id` those fields should never be `null` but always in a
valid state. if they are `null` (how would that even happen?) the
client still assumes default values for `Argon2id` (i.e. m=64 and p=4)
and if they are set to something else login will fail anyway.
@stefan0xC stefan0xC force-pushed the dont-expect-kdf-memory-or-parallelism branch from ef7d8d9 to 0daaa9b Compare March 30, 2023 23:11
@jjlin
Copy link
Contributor

jjlin commented Mar 30, 2023

With Argon2id those fields should never be null but always in a valid state. Be aware that if they are null the client will assume the bitwarden presets (i.e. m=64 and p=4) and if the fields are set to something else (not sure how this would happen but it's technically possible with a sqlite database) the login would most likely fail.

Can you elaborate on why you're calling out SQLite specifically?

Overall, this should be fine, but then I think the validation of the KDF data should be more strict. In particular, in accounts.rs:

  • post_kdf() should clear the KdfMemory and KdfParallelism fields in the PBKDF2 case so these fields are properly null if someone goes from Argon2 to PBKDF2.
  • _register() should have some KDF-specific processing that ignores KdfMemory and KdfParallelism fields in the PBKDF2 case. Conversely, it should error out if KdfMemory and KdfParallelism aren't valid in the Argon2 case, similar to what's done in post_kdf(). The validation logic should probably just be extracted into a separate function.

@stefan0xC
Copy link
Contributor Author

Can you elaborate on why you're calling out SQLite specifically?

I was thinking about setting it to a non-number (because of the Value::Number check) and how SQLite allows setting it to strings. Not sure what happens in other databases (I could be wrong but I think that both PostgreSQL and MySQL/MariaDB will not allow setting non-numbers in an integer field). But yeah, as far as I've tested it with SQLite strings will apparently returned as 0 here, so it might not have been necessary to specifically mention it.

when changing back from argon2id to PBKDF2 the unused parameters
should be set to 0.

also fix small bug in _register
@stefan0xC
Copy link
Contributor Author

stefan0xC commented Mar 31, 2023

@jjlin thanks for the suggestion. regarding the missing validation in _register I'm not sure if this is really necessary right now (registering will use the default PBKDF2 and not even send those values) also there was a small bug, so this presumably has not been used yet.

it might make sense to validate the KDF (and possible other things) on user.save() like we already do with the email.

pub async fn save(&mut self, conn: &mut DbConn) -> EmptyResult {
if self.email.trim().is_empty() {
err!("User email can't be empty")
}

@BlackDex
Copy link
Collaborator

I was thinking about setting it to a non-number (because of the Value::Number check) and how SQLite allows setting it to strings.

That isn't a check really. Its to make sure that it is processed as a json integer and not going to be quoted as if it were a string.

it might make sense to validate the KDF (and possible other things) on user.save() like we already do with the email.

pub async fn save(&mut self, conn: &mut DbConn) -> EmptyResult {
if self.email.trim().is_empty() {
err!("User email can't be empty")
}

Thats maybe not a bad idea. Check which hashing type is used and set those other values to None

@jjlin
Copy link
Contributor

jjlin commented Mar 31, 2023

It sounds okay to clear the KdfMemory and KdfParallelism fields for PBKDF2 when saving the user, but IMO the detailed validation logic for KDF parameters doesn't belong there.

@BlackDex
Copy link
Collaborator

It sounds okay to clear the KdfMemory and KdfParallelism fields for PBKDF2 when saving the user, but IMO the detailed validation logic for KDF parameters doesn't belong there.

Validation indeed should be done elsewhere. Preferably in a separate function.

@BlackDex
Copy link
Collaborator

I quickly checked upstream. And they always return those values, and they set the KdfMemory and KdfParallelism back to null (None) when they KdfType is 0.

So, the validation should be done there where the request is handled. But i think it is fine to set those values to None if the KdfType is set to 0.

@dani-garcia dani-garcia merged commit 867c6ba into dani-garcia:main Apr 2, 2023
3 checks passed
@stefan0xC stefan0xC deleted the dont-expect-kdf-memory-or-parallelism branch April 2, 2023 13:54
RickCoxDev pushed a commit to RickCoxDev/home-cluster that referenced this pull request May 25, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [vaultwarden/server](https://togithub.com/dani-garcia/vaultwarden) |
minor | `1.27.0` -> `1.28.1` |

---

### Release Notes

<details>
<summary>dani-garcia/vaultwarden</summary>

###
[`v1.28.1`](https://togithub.com/dani-garcia/vaultwarden/releases/tag/1.28.1)

[Compare
Source](https://togithub.com/dani-garcia/vaultwarden/compare/1.28.0...1.28.1)

#### What's Changed

- Decode knowndevice `X-Request-Email` as base64url with no padding by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3376
- Fix abort on password reset mail error by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3390
- support `/users/<uuid>/invite/resend` admin api by
[@&#8203;nikolaevn](https://togithub.com/nikolaevn) in
[dani-garcia/vaultwarden#3397
- always return KdfMemory and KdfParallelism by
[@&#8203;stefan0xC](https://togithub.com/stefan0xC) in
[dani-garcia/vaultwarden#3398
- Fix sending out multiple websocket notifications by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3405
- Revert setcap, update rust and crates by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3403

#### New Contributors

- [@&#8203;nikolaevn](https://togithub.com/nikolaevn) made their first
contribution in
[dani-garcia/vaultwarden#3397

**Full Changelog**:
dani-garcia/vaultwarden@1.28.0...1.28.1

###
[`v1.28.0`](https://togithub.com/dani-garcia/vaultwarden/releases/tag/1.28.0)

[Compare
Source](https://togithub.com/dani-garcia/vaultwarden/compare/1.27.0...1.28.0)

#### Major changes

- The project has changed license to the
[**AGPLv3**](https://togithub.com/dani-garcia/vaultwarden/blob/main/LICENSE.txt).
If you're hosting a Vaultwarden instance, you now have a requirement to
distribute the Vaultwarden source code to your users if they request it.
The source code, and any changes you have made, need to be under the
same AGPLv3 license. If you simply use our code without modifications,
just pointing them to this repository is enough.
- Added support for **Argon2** key derivation on the clients. To enable
it for your account, make sure all your clients are using version
v2023.2.0 or greater, then go to account settings > security > keys, and
change the algorithm from PBKDF2 to Argon2id.
- Added support for **Argon2** key derivation for the admin page token.
To update your admin token to use it, [check the
wiki](https://togithub.com/dani-garcia/vaultwarden/wiki/Enabling-admin-page#secure-the-admin_token)
- New **alternative registries** for the docker images are available (In
**BETA** for now):
- **Github Container Registry**: https://ghcr.io/dani-garcia/vaultwarden
    -   **Quay**: https://quay.io/vaultwarden/server

#### What's Changed

- Remove patched multer-rs by
[@&#8203;manofthepeace](https://togithub.com/manofthepeace) in
[dani-garcia/vaultwarden#2968
- Removed unsafe-inline JS from CSP and other fixes by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3058
- Validate YUBICO_SERVER string
([#&#8203;3003](https://togithub.com/dani-garcia/vaultwarden/issues/3003))
by [@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3059
- Log message to stderr if LOG_FILE is not writable by
[@&#8203;pjsier](https://togithub.com/pjsier) in
[dani-garcia/vaultwarden#3061
- Update WebSocket Notifications by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3076
- Optimize config loading messages by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3092
- Percent-encode org_name in links by
[@&#8203;am97](https://togithub.com/am97) in
[dani-garcia/vaultwarden#3093
- Fix failing large note imports by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3087
- Change `text/plain` API responses to `application/json` by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3124
- Remove `shrink-to-fit=no` from viewport-meta-tag by
[@&#8203;redwerkz](https://togithub.com/redwerkz) in
[dani-garcia/vaultwarden#3126
- Update dependencies and MSRV by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3128
- Resolve uninlined_format_args clippy warnings by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3065
- Update Rust to v1.66.1 to patch CVE by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3136
- Fix remaining inline format by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3130
- Use more modern meta tag for charset encoding by
[@&#8203;redwerkz](https://togithub.com/redwerkz) in
[dani-garcia/vaultwarden#3131
- fix (2fa.directory): Allow api.2fa.directory, and remove 2fa.directory
by [@&#8203;GeekCornerGH](https://togithub.com/GeekCornerGH) in
[dani-garcia/vaultwarden#3132
- Optimize CipherSyncData for very large vaults by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3133
- Add avatar color support by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3134
- Add MFA icon to org member overview by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3135
- Minor refactoring concering user.setpassword by
[@&#8203;sirux88](https://togithub.com/sirux88) in
[dani-garcia/vaultwarden#3139
- Validate note sizes on key-rotation. by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3157
- Update KDF Configuration and processing by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3163
- Remove `arm32v6`-specific tag by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3164
- Re-License Vaultwarden to AGPLv3 by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#2561
- Admin password reset by
[@&#8203;sirux88](https://togithub.com/sirux88) in
[dani-garcia/vaultwarden#3116
- "Spell-Jacking" mitigation ~ prevent sensitive data leak … by
[@&#8203;dlehammer](https://togithub.com/dlehammer) in
[dani-garcia/vaultwarden#3145
- Allow listening on privileged ports (below 1024) as non-root by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3170
- don't nullify key when editing emergency access by
[@&#8203;stefan0xC](https://togithub.com/stefan0xC) in
[dani-garcia/vaultwarden#3215
- Fix trailing slash not getting removed from domain by
[@&#8203;BlockListed](https://togithub.com/BlockListed) in
[dani-garcia/vaultwarden#3228
- Generate distinct log messages for regex vs. IP blacklisting. by
[@&#8203;kpfleming](https://togithub.com/kpfleming) in
[dani-garcia/vaultwarden#3231
- allow editing/unhiding by group by
[@&#8203;farodin91](https://togithub.com/farodin91) in
[dani-garcia/vaultwarden#3108
- Fix Javascript issue on non sqlite databases by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3167
- add argon2 kdf fields by [@&#8203;tessus](https://togithub.com/tessus)
in
[dani-garcia/vaultwarden#3210
- add support for system mta though sendmail by
[@&#8203;soruh](https://togithub.com/soruh) in
[dani-garcia/vaultwarden#3147
- Updated Rust and crates by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3234
- docs: add build status badge in readme by
[@&#8203;R3DRUN3](https://togithub.com/R3DRUN3) in
[dani-garcia/vaultwarden#3245
- Validate all needed fields for client API login by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3251
- Fix Organization delete when groups are configured by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3252
- Fix Collection Read Only access for groups by
[@&#8203;Misterbabou](https://togithub.com/Misterbabou) in
[dani-garcia/vaultwarden#3254
- Make the admin session lifetime adjustable by
[@&#8203;mittler-works](https://togithub.com/mittler-works) in
[dani-garcia/vaultwarden#3262
- Add function to fetch user by email address by
[@&#8203;mittler-works](https://togithub.com/mittler-works) in
[dani-garcia/vaultwarden#3263
- Fix vault item display in org vault view by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3277
- Add confirmation for removing 2FA and deauthing sessions in admin
panel by [@&#8203;JCBird1012](https://togithub.com/JCBird1012) in
[dani-garcia/vaultwarden#3282
- Some Admin Interface updates by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3288
- Fix the web-vault v2023.2.0 API calls by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3281
- Fix confirmation for removing 2FA and deauthing sessions in admin
panel by [@&#8203;dpinse](https://togithub.com/dpinse) in
[dani-garcia/vaultwarden#3290
- Admin token Argon2 hashing support by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3289
- Add HEAD routes to avoid spurious error messages by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3307
- Fix web-vault Member UI show/edit/save by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3315
- Upd Crates, Rust, MSRV, GHA and remove Backtrace by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3310
- Add support for `/api/devices/knowndevice` with HTTP header params by
[@&#8203;jjlin](https://togithub.com/jjlin) in
[dani-garcia/vaultwarden#3329
- Update Rust, MSRV and Crates by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3348
- Merge ClientIp with Headers. by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3332
- add endpoints to bulk delete collections/groups by
[@&#8203;stefan0xC](https://togithub.com/stefan0xC) in
[dani-garcia/vaultwarden#3354
- Add support for Quay.io and GHCR.io as registries by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3363
- Some small fixes and updates by
[@&#8203;BlackDex](https://togithub.com/BlackDex) in
[dani-garcia/vaultwarden#3366
- Update web vault to v2023.3.0 by
[@&#8203;dani-garcia](https://togithub.com/dani-garcia)

#### New Contributors

- [@&#8203;manofthepeace](https://togithub.com/manofthepeace) made their
first contribution in
[dani-garcia/vaultwarden#2968
- [@&#8203;pjsier](https://togithub.com/pjsier) made their first
contribution in
[dani-garcia/vaultwarden#3061
- [@&#8203;am97](https://togithub.com/am97) made their first
contribution in
[dani-garcia/vaultwarden#3093
- [@&#8203;redwerkz](https://togithub.com/redwerkz) made their first
contribution in
[dani-garcia/vaultwarden#3126
- [@&#8203;sirux88](https://togithub.com/sirux88) made their first
contribution in
[dani-garcia/vaultwarden#3139
- [@&#8203;dlehammer](https://togithub.com/dlehammer) made their first
contribution in
[dani-garcia/vaultwarden#3145
- [@&#8203;BlockListed](https://togithub.com/BlockListed) made their
first contribution in
[dani-garcia/vaultwarden#3228
- [@&#8203;kpfleming](https://togithub.com/kpfleming) made their first
contribution in
[dani-garcia/vaultwarden#3231
- [@&#8203;farodin91](https://togithub.com/farodin91) made their first
contribution in
[dani-garcia/vaultwarden#3108
- [@&#8203;soruh](https://togithub.com/soruh) made their first
contribution in
[dani-garcia/vaultwarden#3147
- [@&#8203;R3DRUN3](https://togithub.com/R3DRUN3) made their first
contribution in
[dani-garcia/vaultwarden#3245
- [@&#8203;Misterbabou](https://togithub.com/Misterbabou) made their
first contribution in
[dani-garcia/vaultwarden#3254
- [@&#8203;mittler-works](https://togithub.com/mittler-works) made their
first contribution in
[dani-garcia/vaultwarden#3262
- [@&#8203;JCBird1012](https://togithub.com/JCBird1012) made their first
contribution in
[dani-garcia/vaultwarden#3282
- [@&#8203;dpinse](https://togithub.com/dpinse) made their first
contribution in
[dani-garcia/vaultwarden#3290

**Full Changelog**:
dani-garcia/vaultwarden@1.27.0...1.28.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on saturday" (UTC), Automerge - At
any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/RickCoxDev/home-cluster).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

4 participants