Skip to content

Commit ec41449

Browse files
committed
Prevent the space metafiles manipulation
1 parent 80247db commit ec41449

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Prevent the space metafiles manipulation
2+
3+
Prevent the space metafiles deleting and movin `.space` and `.space/readme.md` via webdav prevent deleting .space
4+
5+
https://github.com/cs3org/reva/pull/4826
6+
https://github.com/owncloud/ocis/issues/8719

internal/http/services/owncloud/ocdav/delete.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import (
2323
"errors"
2424
"net/http"
2525
"path"
26+
"slices"
27+
"strings"
2628

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

87+
sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: ref})
88+
switch {
89+
case err != nil:
90+
span.RecordError(err)
91+
return http.StatusInternalServerError, err
92+
case sRes.GetStatus().GetCode() == rpc.Code_CODE_OK:
93+
if sRes.GetInfo().GetSpace().GetSpaceType() == "project" && isPathInList(ctx, client, ref, ".space", ".space/readme.md") {
94+
return http.StatusMethodNotAllowed, errors.New("deleting spaces meta file is not allowed")
95+
}
96+
}
97+
8498
res, err := client.Delete(ctx, req)
8599
switch {
86100
case err != nil:
@@ -147,3 +161,17 @@ func (s *svc) handleSpacesDelete(w http.ResponseWriter, r *http.Request, spaceID
147161

148162
return s.handleDelete(ctx, w, r, &ref)
149163
}
164+
165+
func isPathInList(ctx context.Context, client gateway.GatewayAPIClient, ref *provider.Reference, paths ...string) bool {
166+
resPath := strings.TrimPrefix(ref.GetPath(), "./")
167+
if ref.GetResourceId().GetOpaqueId() != "" && ref.Path == "." {
168+
gpRes, err := client.GetPath(ctx, &provider.GetPathRequest{
169+
ResourceId: ref.GetResourceId(),
170+
})
171+
if err != nil || gpRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
172+
return false
173+
}
174+
resPath = strings.TrimPrefix(gpRes.GetPath(), "/")
175+
}
176+
return slices.Contains(paths, resPath)
177+
}

internal/http/services/owncloud/ocdav/move.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ func (s *svc) handleMove(ctx context.Context, w http.ResponseWriter, r *http.Req
224224
w.WriteHeader(http.StatusBadRequest)
225225
return
226226
}
227+
if srcStatRes.GetInfo().GetSpace().GetSpaceType() == "project" && isPathInList(ctx, client, src, ".space", ".space/readme.md") {
228+
log.Error().Msg("moving spaces meta file is not allowed")
229+
w.WriteHeader(http.StatusMethodNotAllowed)
230+
return
231+
}
227232

228233
// check dst exists
229234
dstStatReq := &provider.StatRequest{Ref: dst}

0 commit comments

Comments
 (0)