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

fix: double quotes will be trimmed from the search token #8035

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/fix-search-by-exact-mail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix search by exact email

Users can be searched by exact email by using double quotes on the search
parameter. Note that double quotes are required because the "@" char is
being interpreted by the parser.

https://github.com/owncloud/ocis/pull/8035
9 changes: 7 additions & 2 deletions services/graph/pkg/identity/odata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package identity

import "github.com/CiscoM31/godata"
import (
"strings"

"github.com/CiscoM31/godata"
)

// GetExpandValues extracts the values of the $expand query parameter and
// returns them in a []string, rejects any $expand value that consists of more
Expand Down Expand Up @@ -37,5 +41,6 @@ func GetSearchValues(req *godata.GoDataQuery) (string, error) {
return "", godata.NotImplementedError("complex search queries are not supported")
}

return req.Search.Tree.Token.Value, nil
searchValue := strings.Trim(req.Search.Tree.Token.Value, "\"")
return searchValue, nil
}
12 changes: 11 additions & 1 deletion services/graph/pkg/service/v0/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,17 @@ func (g Graph) GetUsers(w http.ResponseWriter, r *http.Request) {
}

ctxHasFullPerms := g.contextUserHasFullAccountPerms(r.Context())
if !ctxHasFullPerms && (odataReq.Query == nil || odataReq.Query.Search == nil || len(odataReq.Query.Search.RawValue) < g.config.API.IdentitySearchMinLength) {
minSearchLength := g.config.API.IdentitySearchMinLength
searchHasAcceptableLength := false
if odataReq.Query != nil && odataReq.Query.Search != nil {
if strings.HasPrefix(odataReq.Query.Search.RawValue, "\"") {
// if search starts with double quotes then it must finish with double quotes
// add +2 to the minimum search length in this case
minSearchLength += 2
}
searchHasAcceptableLength = len(odataReq.Query.Search.RawValue) >= minSearchLength
}
if !ctxHasFullPerms && !searchHasAcceptableLength {
// for regular user the search term must have a minimum length
logger.Debug().Interface("query", r.URL.Query()).Msgf("search with less than %d chars for a regular user", g.config.API.IdentitySearchMinLength)
errorcode.AccessDenied.Render(w, r, http.StatusForbidden, "search term too short")
Expand Down