fix(webdav): don't pass internal search errors on to clients

When the search service failed with anything but a bad request, a search
REPORT answered with the error message of the service, which can carry
internal details such as paths in the storage. Answer with a generic
message instead: the error itself is still logged.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Pascal Bleser committed 2026-12-02 16:31:14 +01:00
1 parent e6acfb721d
commit 21626d7d2d
2 files changed
+33 -7

No files matched your search

+12 -7
View File
@@ -109,19 +109,24 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
rsp, err := g.searchClient.Search(ctx, req)
if err != nil {
e := merrors.Parse(err.Error())
switch e.Code {
case http.StatusBadRequest:
renderError(w, r, errBadRequest(e.Detail))
default:
renderError(w, r, errInternalError(err.Error()))
}
renderError(w, r, searchErrorResponse(err))
logger.Error().Err(err).Msg("could not get search results")
return
}
g.sendSearchResponse(davPrefix, rsp, w, r, user)
}
// searchErrorResponse is the answer to an error of the search service. Only a
// bad request says what was wrong with it: any other error can carry internal
// details, such as paths in the storage, which stay in the log.
func searchErrorResponse(err error) *errResponse {
e := merrors.Parse(err.Error())
if e.GetCode() == http.StatusBadRequest {
return errBadRequest(e.GetDetail())
}
return errInternalError("could not get search results")
}
// searchRequestOf maps the search element of the report: limit -1 is no
// limit, 0 the default, offset skips leading matches of the merged list.
func searchRequestOf(search reportSearchFilesSearch) (*searchsvc.SearchRequest, error) {
@@ -2,6 +2,8 @@ package svc
import (
"context"
"errors"
"net/http"
"testing"
"time"
@@ -12,6 +14,8 @@ import (
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/timestamppb"
merrors "go-micro.dev/v4/errors"
"github.com/opencloud-eu/opencloud/pkg/conversions"
searchmsg "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/search/v0"
searchsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/search/v0"
@@ -124,3 +128,20 @@ var _ = Describe("searchRequestOf", func() {
Entry("a limit below -1", reportSearchFilesSearch{Pattern: "notes", Limit: -2}),
)
})
var _ = Describe("searchErrorResponse", func() {
It("passes on what was wrong with a bad request", func() {
res := searchErrorResponse(merrors.BadRequest("search", "invalid query: missing closing quote"))
Expect(res.HTTPStatusCode).To(Equal(http.StatusBadRequest))
Expect(res.Message).To(Equal("invalid query: missing closing quote"))
})
DescribeTable("keeps the details of other errors to the log",
func(err error) {
res := searchErrorResponse(err)
Expect(res.HTTPStatusCode).To(Equal(http.StatusInternalServerError))
Expect(res.Message).To(Equal("could not get search results"))
},
Entry("an internal error of the search service", merrors.InternalServerError("search", "open /var/lib/opencloud/storage/users/indexes/x: no such file or directory")),
Entry("an error that isn't one of the search service", errors.New("dial tcp 10.0.0.1:9220: connect: connection refused")),
)
})