forked from wrenn/wrenn
Fix user search to trigger on 3 characters without requiring @
The anti-enumeration guard required @ in the email prefix, causing the typeahead to silently return nothing until the user typed @. Replace with a minimum 3-character length check to match the frontend trigger condition.
This commit is contained in:
@ -18,13 +18,13 @@ func newUsersHandler(svc *service.TeamService) *usersHandler {
|
|||||||
|
|
||||||
// Search handles GET /v1/users/search?email=<prefix>
|
// Search handles GET /v1/users/search?email=<prefix>
|
||||||
// Returns up to 10 users whose email starts with the given prefix.
|
// Returns up to 10 users whose email starts with the given prefix.
|
||||||
// The prefix must contain "@" to scope searches and prevent broad enumeration.
|
// The prefix must be at least 3 characters long.
|
||||||
func (h *usersHandler) Search(w http.ResponseWriter, r *http.Request) {
|
func (h *usersHandler) Search(w http.ResponseWriter, r *http.Request) {
|
||||||
auth.MustFromContext(r.Context()) // ensure authenticated
|
auth.MustFromContext(r.Context()) // ensure authenticated
|
||||||
|
|
||||||
prefix := strings.TrimSpace(r.URL.Query().Get("email"))
|
prefix := strings.TrimSpace(r.URL.Query().Get("email"))
|
||||||
if !strings.Contains(prefix, "@") {
|
if len(prefix) < 3 {
|
||||||
writeError(w, http.StatusBadRequest, "invalid_request", "email prefix must contain '@'")
|
writeError(w, http.StatusBadRequest, "invalid_request", "email prefix must be at least 3 characters")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user