Conversation
|
The security team is monitoring all repositories for certain keywords. This PR includes the word(s) "password" and so security team members have been added as reviewers to take a look. |
4dc7961 to
e098773
Compare
|
Sure. Will it be noted in the Swagger docs somehow?
…On Mon, May 26, 2025, 13:45 Darnell Andries ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In controllers/auth.go
<#60 (comment)>:
> +
+ render.Status(r, http.StatusOK)
+ render.JSON(w, r, response)
+}
+
+// @summary Finalize login with 2FA
+// @description Final step of 2FA login flow, verifies TOTP code or recovery key and creates a session. If a recovery key is used, 2FA will be disabled.
+// @tags Auth
+// @accept json
+// @produce json
+// @Param Authorization header string true "Bearer + login state token"
+// @Param Brave-Key header string false "Brave services key (if one is configured)"
+// @Param request body services.TwoFAAuthRequest true "2FA verification request"
+// @success 200 {object} LoginFinalize2FAResponse
+// @failure 400 {object} util.ErrorResponse
+// @failure 401 {object} util.ErrorResponse
wdyt about just letting the client interpret the error code within the
response body? I think that's probably a more useful indicator compared to
the status code
—
Reply to this email directly, view it on GitHub
<#60 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABI7DNBLRQGSAIATVFLQZ33AN4OXAVCNFSM6AAAAAB34YGZ7OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDQNRZGE2DAOJYGM>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
I'll have to look into that. I'm not sure if the swagger lib allows us to generate docs from our error types. Worst case scenario, we can just provide a link to error.go on Github. |
| KeyServiceSecretHeader = "key-service-secret" | ||
| KeyServiceURLEnv = "KEY_SERVICE_URL" | ||
|
|
||
| recoveryKeyArgonTime = 1 |
There was a problem hiding this comment.
yes! it is see here: https://github.com/golang/crypto/blob/master/argon2/argon2.go#L76 and also: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-argon2-03#section-9.4
In 'recoveryKeyArgonThreads' as 4, I assume we have 4CPUs available, right @DJAndries ? If we are using more threads, we can do:
// 4 threads x 64 MiB = 256 MiB
key := argon2.IDKey(password, salt, 1, 256*1024, 4, 32)
There was a problem hiding this comment.
each server pod runs on 0.5 vCPU. do you think it would be safe to reduce the thread count to 1? if not, no worries. i'm not too concerned about performance issues given the expected infrequency of recovery code usage.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for TOTP 2FA and recovery/scratch codes. It updates migrations, middleware, various datastore operations, controllers for both server keys and account authentication flows, and extends the test suites to cover the new TOTP functionality.
- Introduced new TOTP key management in the datastore and added recovery key support.
- Updated authentication and account controllers with new endpoints for TOTP generation, validation, and disabling.
- Adjusted build tooling and workflow configurations to generate updated Swagger documentation.
Reviewed Changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| migrations/11_cron.down.sql | Removed obsolete cron unschedules and added new ones for interim password & TOTP codes |
| middleware/auth.go | Updated KeyServiceMiddleware signature to accept an environment flag |
| main.go | Modified server startup to use the new twoFAService and updated middleware usage |
| go.mod | Added dependencies for TOTP and barcode generation |
| datastore/twofa.go | Added new datastore models and functions for TOTP key handling |
| datastore/password_states.go | Renamed and refactored interim password state handling to support 2FA workflows |
| datastore/accounts.go | Extended account fields and functions to support TOTP settings and recovery keys |
| controllers/server_keys.go | Introduced new endpoints for TOTP key operations in the server keys API |
| controllers/auth.go | Updated authentication flow to use login tokens and support 2FA finalization |
| controllers/accounts.go | Added multiple new endpoints for 2FA setup, finalization, and recovery key management |
| Various test files | Updated tests to integrate the new 2FA flows and endpoints |
| Makefile, Dockerfile, GitHub workflows | Added swag init commands to ensure Swagger docs are generated with new API changes |
| .dockerignore | Updated ignore patterns |
There was a problem hiding this comment.
This looks good to me. Great work @DJAndries !
PR can be merged after @claucece 's review of these two items:
claucece
left a comment
There was a problem hiding this comment.
Except for a very small discussion and the addition of the constant time check, it is looking awesome! Thank you @DJAndries !
|
[puLL-Merge] - brave/accounts@60 DescriptionThis is a comprehensive pull request that adds Two-Factor Authentication (2FA) support to the Brave Accounts service. The PR introduces TOTP-based 2FA with recovery keys, integrates it into the login and registration flows, and includes extensive API endpoints for managing 2FA settings. The implementation supports both standalone operation and integration with a separate key service for enhanced security. Possible Issues
Security Hotspots
ChangesChanges
|
Adds support for time-based one time passwords and recovery/scratch codes.
Security review: https://github.com/brave/reviews/issues/1957