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

refactor: mfa store #3799

Merged
merged 1 commit into from
May 29, 2024
Merged

refactor: mfa store #3799

merged 1 commit into from
May 29, 2024

Conversation

heiytor
Copy link
Contributor

@heiytor heiytor commented May 3, 2024

Currently, when a user attempts to log in with 2FA enabled, the API returns a stateful token along with the user's information. This can lead to two issues:

  1. Information leak: Since 2FA requires a code in addition to the password for authentication, returning user information without full authentication may pose a security risk.

  2. Violation of RFC 7519: JWT standards mandate stateless tokens. By adding an mfa.validate field to determine token validity, the API contradicts this standard.

To address these issues, the login route now returns a 401 status code with an X-MFA-Token header, indicating whether the user must authenticate using a 2FA method. As a result, the JWT will no longer include the mfa attribute. Authentication for these users will be handled exclusively on the cloud side with the token returned in the header.

Additionally, a security issue involving JSON binding in the User struct, where the secret and recovery codes for MFA were returned, has been resolved. The gateway will no longer provide the X-MFA and X-Validate-MFA headers; the protection around the /mfa/auth and /mfa/recovery endpoints has been removed.

Recovery codes will now be stored in a hashed state in the database. To facilitate this, a new migration has been added to hash all recovery codes that are not yet hashed. The attributes was also replaced inside a mfa object.

@heiytor heiytor self-assigned this May 3, 2024
@heiytor heiytor force-pushed the refactor/mfa-store branch 16 times, most recently from 11ac31e to 6a7d88d Compare May 9, 2024 16:55
@heiytor heiytor force-pushed the refactor/mfa-store branch 5 times, most recently from 8404864 to b2efd92 Compare May 20, 2024 21:05
@heiytor heiytor marked this pull request as ready for review May 20, 2024 21:05
@heiytor heiytor requested review from a team as code owners May 20, 2024 21:05
@luannmoreira luannmoreira requested a review from a team as a code owner May 21, 2024 13:17
@heiytor heiytor force-pushed the refactor/mfa-store branch 2 times, most recently from 05f2e7b to c7031f8 Compare May 21, 2024 14:17
@heiytor heiytor force-pushed the refactor/mfa-store branch 6 times, most recently from 80c5a8d to a4e1465 Compare May 27, 2024 13:14
@heiytor heiytor changed the base branch from master to feat/recovery_email May 27, 2024 13:14
@heiytor heiytor force-pushed the refactor/mfa-store branch from a4e1465 to 3817471 Compare May 27, 2024 13:16
@heiytor heiytor force-pushed the feat/recovery_email branch 7 times, most recently from 9e28773 to 8aa0274 Compare May 28, 2024 13:32
Base automatically changed from feat/recovery_email to master May 28, 2024 13:37
@heiytor heiytor force-pushed the refactor/mfa-store branch 5 times, most recently from 0735886 to f7507ae Compare May 29, 2024 13:37
Currently, when a user attempts to log in with 2FA enabled, the API
returns a stateful token along with the user's information. This can
lead to two issues:

1. **Information leak:** Since 2FA requires a code in addition to the
   password for authentication, returning user information without full
   authentication may pose a security risk.

2. **Violation of RFC 7519:** JWT standards mandate stateless tokens. By
   adding an `mfa.validate` field to determine token validity, the API
   contradicts this standard.

To address these issues, the login route now returns a `401` status code
with an `X-MFA-Token` header, indicating whether the user must
authenticate using a 2FA method. As a result, the JWT will no longer
include the `mfa` attribute. Authentication for these users will be
handled exclusively on the cloud side with the token returned in the
header.

Additionally, a security issue involving JSON binding in the `User`
struct, where the secret and recovery codes for MFA were returned, has
been resolved. The gateway will no longer provide the `X-MFA` and
`X-Validate-MFA` headers; the protection around the `/mfa/auth` and
`/mfa/recovery` endpoints has been removed.

Recovery codes will now be stored in a hashed state in the database. To
facilitate this, a new migration has been added to hash all recovery
codes that are not yet hashed. The attributes was also replaced inside a
`mfa` object.
@heiytor heiytor force-pushed the refactor/mfa-store branch from f7507ae to 1aa5dbc Compare May 29, 2024 13:49
@gustavosbarreto gustavosbarreto merged commit 6f0500c into master May 29, 2024
9 checks passed
@gustavosbarreto gustavosbarreto deleted the refactor/mfa-store branch May 29, 2024 14:35
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