# OWASP ASVS and NIST SP 800-63B

Source: https://keyringauth.com/docs/0.x/rust/owasp-asvs

## Introduction

The crate stands where the PHP package does against [OWASP ASVS 5.0.0](https://github.com/OWASP/ASVS/tree/v5.0.0/5.0), [NIST SP 800-63B-4](https://pages.nist.gov/800-63-4/sp800-63b.html) and the OWASP authentication cheat sheets, since it makes the same guarantees and passes the same contract suite. The [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs) goes requirement by requirement, with the same status column. This page says where the crate's standing, or the setup to reach it, differs. Where a requirement isn't named here, the PHP page's row holds.

## What a Default Install Gives You

There's no installer to accept defaults from. An application that adds the provider with nothing else gets:

- the password, authenticator apps, recovery codes and passkeys as sign-in methods, where the PHP installer's default is the password alone,
- every feature off, where the PHP installer turns on registration, resets, email verification and password changes, since each runs code of yours,
- the security log on,
- the eleven security emails the PHP page lists (`clone_suspected` starts off, as in the PHP package),
- no risk signals, where the PHP installer adds three,
- the same rate limits, timebox, session registry and session limits as the PHP package.

So to match the PHP page's default install, turn on the four features with their actions, and add `SessionFingerprintChanged`, `RepeatedFactorFailures` and `SuccessAfterFailures` to `risk.signals` (see [Choosing Signals](https://keyringauth.com/docs/0.x/rust/risk#choosing-signals)). Users can't add a second factor until `features.manage_authenticators` is on.

## Level 1

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#level-1) says, with these in Rust terms:

1. Keep a server-side session driver. Keyring ends an old copy of a session through its registry either way.
2. Keep the default cache store in a store that holds its keys, supports locks and is shared by every server, not laravel-rust's `memory` store. Everything the PHP page puts in `cache.limiter` is there.
3. Mask password fields, and let paste and password managers work.
4. Give users a form that posts to `PUT /user/password`, with `features.update_passwords` on.
5. When your app disables an account, call `Sessions::<Users>::sign_out_everywhere(&user, None)` as you set the flag (7.4.2), and give the provider `allow_sign_in_when()`.
6. Put a sign-out button on every signed-in page.

Call `protection::guard()` wherever you save users, since laravel-rust has no model events to check every save.

## Level 2

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#level-2) says. The second factor is required of everyone with `RequireEnrollment` in the `web` group, which `keyring:install --factor=...` prints, and the [starter kit](https://github.com/keyringauth/keyring/blob/main/rust/starter-kit/README.md#requiring-a-second-factor) sets up.

## Level 3

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#level-3) says, with attested security keys from `webauthn.security_keys` with `require_attestation`, `webauthn.attestation_roots` or `webauthn.trusts`, and `RequireAssurance::aal3()`. Ed25519 keys can't be used.

## Requirement by Requirement

### V6 Authentication

The rows are the PHP page's, with these differences:

| Requirement | In the Crate |
|---|---|
| 6.2.8 The password is verified exactly as received | Deviates, as in the PHP package: every password is put in NFC form before it's hashed or checked. Your own code that sets a password normalises it itself, as there's no public `normalize()`. |
| 6.3.3 Multi-factor authentication is required | Needs setup: `RequireEnrollment`, as above. |
| 6.5.5 Code lifetimes | Deviates, as in the PHP package: set `factors.totp`'s `window` to `0` to meet it exactly. |

### V7 Session Management

The rows are the PHP page's, with these differences:

| Requirement | In the Crate |
|---|---|
| 7.2.4 A new token on authentication, and the old one ended | Met by default, but a request that overlapped a sign in can save the old session again, as `sessions.overlapping_requests` isn't there. The old record is ended, so the copy is signed out on its next request. |
| 7.4.1 A terminated session can't be used again | Met for Keyring's record and the browser's next request. The ended session's data stays in the store until it expires, as laravel-rust can't destroy another browser's session. |
| 7.4.3 The option to end other sessions after a factor changes | Met: a password change always ends every other session, as `sign_out_others: false` can't keep them. |
| 7.5.1 Re-authentication before changing sign-in details | Met by default: `changes_fresh_for` is 15 minutes. Don't set it to `None`. |

### The Other Chapters

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#the-other-chapters) says. The cryptography the crate uses is in [Cryptography](https://keyringauth.com/docs/0.x/rust/security#cryptography). RS256 for passkeys stays off by default, as in the PHP package.

## NIST SP 800-63B-4

### What Keyring's Levels Mean

The levels are the PHP package's, worked out the same way. See the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#what-keyrings-levels-mean).

### Section by Section

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#section-by-section) says, with one difference: Sec. 3.1.1.2's advice to rehash passwords isn't followed on sign in, as laravel-rust's guard would sign out every other session of the user.

## The OWASP Cheat Sheets

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#the-owasp-cheat-sheets) says. Keyring's cookie names don't name the software, as the Session Management Cheat Sheet recommends.

## What Is Left to Your App

As the [PHP page](https://keyringauth.com/docs/0.x/owasp-asvs#what-is-left-to-your-app) lists, plus:

- **Your user provider and actions.** Registration, password changes, resets and email changes run your code, which saves users with `protection::guard()` and checks passwords with `PasswordRules`.
- **Trusted proxies** with laravel-rust's `trust_proxies`.
- **A queue worker**, or the `sync` queue, for the security emails.
