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

Prevent the space metafiles manipulation #4826

Draft
wants to merge 1 commit into
base: edge
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions changelog/unreleased/space-metafiles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Prevent the space metafiles manipulation

Prevent the space metafiles deleting and movin `.space` and `.space/readme.md` via webdav prevent deleting .space

https://github.com/cs3org/reva/pull/4826
https://github.com/owncloud/ocis/issues/8719
28 changes: 28 additions & 0 deletions internal/http/services/owncloud/ocdav/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import (
"errors"
"net/http"
"path"
"slices"
"strings"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net"
Expand Down Expand Up @@ -81,6 +84,17 @@ func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.R
return http.StatusInternalServerError, errtypes.InternalError(err.Error())
}

sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: ref})
switch {
case err != nil:
span.RecordError(err)
return http.StatusInternalServerError, err
case sRes.GetStatus().GetCode() == rpc.Code_CODE_OK:
if sRes.GetInfo().GetSpace().GetSpaceType() == "project" && isPathInList(ctx, client, ref, ".space", ".space/readme.md") {
return http.StatusMethodNotAllowed, errors.New("deleting spaces meta file is not allowed")
}
}

res, err := client.Delete(ctx, req)
switch {
case err != nil:
Expand Down Expand Up @@ -147,3 +161,17 @@ func (s *svc) handleSpacesDelete(w http.ResponseWriter, r *http.Request, spaceID

return s.handleDelete(ctx, w, r, &ref)
}

func isPathInList(ctx context.Context, client gateway.GatewayAPIClient, ref *provider.Reference, paths ...string) bool {
resPath := strings.TrimPrefix(ref.GetPath(), "./")
if ref.GetResourceId().GetOpaqueId() != "" && ref.Path == "." {
gpRes, err := client.GetPath(ctx, &provider.GetPathRequest{
ResourceId: ref.GetResourceId(),
})
if err != nil || gpRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
return false
}
resPath = strings.TrimPrefix(gpRes.GetPath(), "/")
}
return slices.Contains(paths, resPath)
}
5 changes: 5 additions & 0 deletions internal/http/services/owncloud/ocdav/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ func (s *svc) handleMove(ctx context.Context, w http.ResponseWriter, r *http.Req
w.WriteHeader(http.StatusBadRequest)
return
}
if srcStatRes.GetInfo().GetSpace().GetSpaceType() == "project" && isPathInList(ctx, client, src, ".space", ".space/readme.md") {
log.Error().Msg("moving spaces meta file is not allowed")
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

// check dst exists
dstStatReq := &provider.StatRequest{Ref: dst}
Expand Down
Loading