Skip to content

Commit 48aa66c

Browse files
mklos-kwdj4oCclaude2403905f-firas
authored
fix: [stable-8.0] consolidated security backports (#806)
* fix(gateway): prevent setting an expiration on the last space manager (#631) Setting an expiration on the last permanent manager of a space was allowed, which left the space without any manager once the grant expired. updateSpaceShare only ran the "is a permanent manager remaining" check when a grant dropped the manager role (RemoveGrant=false). It now also runs when a manager grant is given an expiration, via the new mayRemoveLastPermanentManager predicate, since an expiring manager is not a permanent manager. Signed-off-by: David Walter <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> * fix: [OCISDEV-810] fix the space role and custom role checks (#653) * fix: [OCISDEV-971] escape oc:tags and lock owner name in PROPFIND responses (#652) * feat: [OCISDEV-720] fix public link --------- Signed-off-by: David Walter <[email protected]> Co-authored-by: David Walter <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Roman Perekhod <[email protected]> Co-authored-by: Firas Frikha <[email protected]>
1 parent 8577f4a commit 48aa66c

10 files changed

Lines changed: 319 additions & 25 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Bugfix: Harden space role classification and grant checks
2+
3+
The `IsManager` space predicate treated any single grant-management bit as a full
4+
manager, allowing a partial grant to act as a stealth manager. It now requires the
5+
full add/update/remove grant triad. `IsEditor`/`IsViewer` keep classifying by their
6+
defining capability bit so space-role variants still work. Partial grant-management
7+
grants are rejected on space roots on both the create and update paths.
8+
9+
https://github.com/owncloud/reva/pull/645
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Bugfix: Prevent setting an expiration on the last space manager
2+
3+
Setting an expiration date on the last permanent manager of a space was allowed.
4+
Once that grant expired the space would be left without any manager. The check
5+
that ensures at least one permanent manager remains was only run when a grant
6+
dropped the manager role; it now also runs when a manager grant is given an
7+
expiration, since an expiring manager is not a permanent manager.
8+
9+
https://github.com/owncloud/reva/pull/631
10+
https://github.com/owncloud/ocis/issues/11205

‎internal/grpc/services/gateway/usershareprovider.go‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
2929
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
3030
"github.com/owncloud/reva/v2/pkg/appctx"
31+
"github.com/owncloud/reva/v2/pkg/conversions"
3132
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
3233
"github.com/owncloud/reva/v2/pkg/errtypes"
3334
"github.com/owncloud/reva/v2/pkg/rgrpc/status"
@@ -37,6 +38,14 @@ import (
3738
"github.com/pkg/errors"
3839
)
3940

41+
// managerPerms is the canonical Manager bitmap used to reject partial grant-management grants on space roots
42+
var managerPerms = conversions.NewManagerRole().CS3ResourcePermissions()
43+
44+
// hasGrantManagementBits reports whether p carries any grant-management permission.
45+
func hasGrantManagementBits(p *provider.ResourcePermissions) bool {
46+
return p.GetAddGrant() || p.GetUpdateGrant() || p.GetRemoveGrant() || p.GetDenyGrant()
47+
}
48+
4049
// TODO(labkode): add multi-phase commit logic when commit share or commit ref is enabled.
4150
func (s *svc) CreateShare(ctx context.Context, req *collaboration.CreateShareRequest) (*collaboration.CreateShareResponse, error) {
4251
// Don't use the share manager when sharing a space root
@@ -171,6 +180,10 @@ func (s *svc) updateSpaceShare(ctx context.Context, req *collaboration.UpdateSha
171180
if req.GetShare().GetGrantee() == nil {
172181
return &collaboration.UpdateShareResponse{Status: status.NewInvalid(ctx, "updating requires a received grantee object")}, nil
173182
}
183+
// reject partial grant-management grants that would mint a stealth manager
184+
if perms := req.GetShare().GetPermissions().GetPermissions(); hasGrantManagementBits(perms) && !conversions.SufficientCS3Permissions(perms, managerPerms) {
185+
return &collaboration.UpdateShareResponse{Status: status.NewInvalid(ctx, "partial grant-management permissions are not allowed on space roots")}, nil
186+
}
174187
// If the share is a denial we call denyGrant instead.
175188
var st *rpc.Status
176189
var err error
@@ -218,10 +231,10 @@ func (s *svc) updateSpaceShare(ctx context.Context, req *collaboration.UpdateSha
218231
return &collaboration.UpdateShareResponse{Status: status.NewInvalid(ctx, "updating requires a received permission object")}, nil
219232
}
220233

221-
if !grant.GetPermissions().GetRemoveGrant() {
222-
// this request might remove Manager Permissions so we need to
223-
// check if there is at least one manager remaining of the
224-
// resource.
234+
if mayRemoveLastPermanentManager(grant) {
235+
// This request might drop the manager role or give the manager grant
236+
// an expiration, either of which could leave the space without a
237+
// permanent manager. Ensure at least one permanent manager remains.
225238
if !isSpaceManagerRemaining(listGrantRes.GetGrants(), grant.GetGrantee()) {
226239
return &collaboration.UpdateShareResponse{
227240
Status: status.NewPermissionDenied(ctx, errtypes.PermissionDenied(""), "can't remove the last manager"),
@@ -649,6 +662,10 @@ func (s *svc) addSpaceShare(ctx context.Context, req *collaboration.CreateShareR
649662
(req.GetResourceInfo().GetSpace().GetSpaceType() == _spaceTypePersonal || req.GetResourceInfo().GetSpace().GetSpaceType() == _spaceTypeVirtual) {
650663
return &collaboration.CreateShareResponse{Status: status.NewInvalid(ctx, "space type is not eligible for sharing")}, nil
651664
}
665+
// reject partial grant-management grants that would mint a stealth manager
666+
if perms := req.GetGrant().GetPermissions().GetPermissions(); hasGrantManagementBits(perms) && !conversions.SufficientCS3Permissions(perms, managerPerms) {
667+
return &collaboration.CreateShareResponse{Status: status.NewInvalid(ctx, "partial grant-management permissions are not allowed on space roots")}, nil
668+
}
652669
// If the share is a denial we call denyGrant instead.
653670
var st *rpc.Status
654671
var err error
@@ -812,6 +829,16 @@ func isSpaceManagerRemaining(grants []*provider.Grant, grantee *provider.Grantee
812829
return false
813830
}
814831

832+
// mayRemoveLastPermanentManager reports whether applying grant could leave the
833+
// space without a permanent (non-expiring) manager, so that the caller must
834+
// verify another permanent manager remains. This is the case when the grant
835+
// drops the manager role (RemoveGrant is the manager marker) or when a manager
836+
// grant is given an expiration, since an expiring manager does not count as a
837+
// permanent manager (see isSpaceManagerRemaining).
838+
func mayRemoveLastPermanentManager(grant *provider.Grant) bool {
839+
return !grant.GetPermissions().GetRemoveGrant() || grant.GetExpiration() != nil
840+
}
841+
815842
func (s *svc) checkLock(ctx context.Context, shareId *collaboration.ShareId) (*rpc.Status, error) {
816843
logger := appctx.GetLogger(ctx)
817844
getShareRes, err := s.GetShare(ctx, &collaboration.GetShareRequest{
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2018-2024 CERN
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// In applying this license, CERN does not waive the privileges and immunities
16+
// granted to it by virtue of its status as an Intergovernmental Organization
17+
// or submit itself to any jurisdiction.
18+
19+
package gateway
20+
21+
import (
22+
"testing"
23+
24+
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
25+
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
26+
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
27+
"github.com/owncloud/reva/v2/pkg/conversions"
28+
)
29+
30+
func userGrantee(id string) *provider.Grantee {
31+
return &provider.Grantee{
32+
Type: provider.GranteeType_GRANTEE_TYPE_USER,
33+
Id: &provider.Grantee_UserId{UserId: &userpb.UserId{OpaqueId: id}},
34+
}
35+
}
36+
37+
func managerGrant(grantee *provider.Grantee, exp *typesv1beta1.Timestamp) *provider.Grant {
38+
return &provider.Grant{
39+
Grantee: grantee,
40+
Permissions: &provider.ResourcePermissions{RemoveGrant: true},
41+
Expiration: exp,
42+
}
43+
}
44+
45+
func viewerGrant(grantee *provider.Grantee, exp *typesv1beta1.Timestamp) *provider.Grant {
46+
return &provider.Grant{
47+
Grantee: grantee,
48+
Permissions: &provider.ResourcePermissions{RemoveGrant: false},
49+
Expiration: exp,
50+
}
51+
}
52+
53+
// TestMayRemoveLastPermanentManager covers the guard that prevents orphaning a
54+
// space: a manager grant that gains an expiration must be treated the same as a
55+
// manager that loses the role, because an expiring manager is not a permanent
56+
// manager.
57+
func TestMayRemoveLastPermanentManager(t *testing.T) {
58+
alice := userGrantee("alice")
59+
exp := &typesv1beta1.Timestamp{Seconds: 1}
60+
61+
tests := []struct {
62+
name string
63+
grant *provider.Grant
64+
want bool
65+
}{
66+
{"permanent manager, unchanged", managerGrant(alice, nil), false},
67+
{"manager gains an expiration", managerGrant(alice, exp), true},
68+
{"manager role dropped", viewerGrant(alice, nil), true},
69+
{"non-manager with expiration", viewerGrant(alice, exp), true},
70+
}
71+
72+
for _, tt := range tests {
73+
t.Run(tt.name, func(t *testing.T) {
74+
if got := mayRemoveLastPermanentManager(tt.grant); got != tt.want {
75+
t.Errorf("mayRemoveLastPermanentManager() = %v, want %v", got, tt.want)
76+
}
77+
})
78+
}
79+
}
80+
81+
// TestIsSpaceManagerRemaining documents the invariant the guard relies on: only
82+
// another permanent (non-expiring), non-self manager keeps a space managed.
83+
func TestIsSpaceManagerRemaining(t *testing.T) {
84+
alice := userGrantee("alice")
85+
bob := userGrantee("bob")
86+
exp := &typesv1beta1.Timestamp{Seconds: 1}
87+
88+
tests := []struct {
89+
name string
90+
grants []*provider.Grant
91+
updating *provider.Grantee
92+
want bool
93+
}{
94+
{"another permanent manager remains", []*provider.Grant{managerGrant(alice, nil), managerGrant(bob, nil)}, alice, true},
95+
{"only the updated grantee is manager", []*provider.Grant{managerGrant(alice, nil)}, alice, false},
96+
{"the other manager is expiring", []*provider.Grant{managerGrant(alice, nil), managerGrant(bob, exp)}, alice, false},
97+
{"the other grantee is only a viewer", []*provider.Grant{managerGrant(alice, nil), viewerGrant(bob, nil)}, alice, false},
98+
}
99+
100+
for _, tt := range tests {
101+
t.Run(tt.name, func(t *testing.T) {
102+
if got := isSpaceManagerRemaining(tt.grants, tt.updating); got != tt.want {
103+
t.Errorf("isSpaceManagerRemaining() = %v, want %v", got, tt.want)
104+
}
105+
})
106+
}
107+
}
108+
109+
// spaceRootGrantRejected mirrors the guard used in both addSpaceShare and updateSpaceShare.
110+
func spaceRootGrantRejected(perms *provider.ResourcePermissions) bool {
111+
return hasGrantManagementBits(perms) && !conversions.SufficientCS3Permissions(perms, managerPerms)
112+
}
113+
114+
func TestSpaceShareRejectsPartialGrantManagement(t *testing.T) {
115+
// a single grant-management bit must be rejected
116+
if !spaceRootGrantRejected(&provider.ResourcePermissions{RemoveGrant: true}) {
117+
t.Error("single-bit RemoveGrant grant should be rejected on a space root")
118+
}
119+
// read bits plus a grant-management bit (the update-path stealth-manager payload) must be rejected
120+
if !spaceRootGrantRejected(&provider.ResourcePermissions{Stat: true, GetPath: true, ListGrants: true, RemoveGrant: true}) {
121+
t.Error("read+RemoveGrant grant should be rejected on a space root")
122+
}
123+
// a full manager grant must be accepted
124+
if spaceRootGrantRejected(conversions.NewManagerRole().CS3ResourcePermissions()) {
125+
t.Error("full manager grant should be accepted on a space root")
126+
}
127+
// viewer/editor grants carry no grant-management bits and must be accepted
128+
if spaceRootGrantRejected(conversions.NewSpaceViewerRole().CS3ResourcePermissions()) {
129+
t.Error("space viewer grant should be accepted on a space root")
130+
}
131+
if spaceRootGrantRejected(conversions.NewSpaceEditorRole().CS3ResourcePermissions()) {
132+
t.Error("space editor grant should be accepted on a space root")
133+
}
134+
}

‎internal/http/services/owncloud/ocdav/propfind/propfind.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
13041304
}
13051305

13061306
if k := md.GetArbitraryMetadata().GetMetadata(); k != nil {
1307-
propstatOK.Prop = append(propstatOK.Prop, prop.Raw("oc:tags", k["tags"]))
1307+
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:tags", k["tags"]))
13081308
appendMetadataProp(k, "oc", "audio", "libre.graph.audio", audioKeys)
13091309
appendMetadataProp(k, "oc", "location", "libre.graph.location", locationKeys)
13101310
appendMetadataProp(k, "oc", "image", "libre.graph.image", imageKeys)
@@ -1580,7 +1580,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
15801580
}
15811581
case "tags":
15821582
if k := md.GetArbitraryMetadata().GetMetadata(); k != nil {
1583-
propstatOK.Prop = append(propstatOK.Prop, prop.Raw("oc:tags", k["tags"]))
1583+
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:tags", k["tags"]))
15841584
}
15851585
case "audio":
15861586
if k := md.GetArbitraryMetadata().GetMetadata(); k != nil {
@@ -1800,7 +1800,7 @@ func activeLocks(log *zerolog.Logger, lock *provider.Lock) string {
18001800

18011801
if un := utils.ReadPlainFromOpaque(lock.Opaque, "lockownername"); un != "" {
18021802
activelocks.WriteString("<oc:ownername>")
1803-
activelocks.WriteString(un)
1803+
activelocks.WriteString(prop.Escape(un))
18041804
activelocks.WriteString("</oc:ownername>")
18051805
}
18061806
if lt := utils.ReadPlainFromOpaque(lock.Opaque, "locktime"); lt != "" {

‎pkg/auth/scope/resourceinfo.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ func checkResourcePath(path string) bool {
135135
"/archiver",
136136
"/ocs/v2.php/cloud/capabilities",
137137
"/ocs/v1.php/cloud/capabilities",
138-
"/ocs/v1.php/cloud/user/signing-key",
139-
"/ocs/v2.php/cloud/user/signing-key",
140138
"/ocs/v2.php/apps/notifications/api/v1/notifications/sse",
141139
}
142140
for _, p := range paths {

‎pkg/storage/utils/decomposedfs/permissions/spacepermissions.go‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
cs3permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
88
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
99
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
10+
"github.com/owncloud/reva/v2/pkg/conversions"
1011
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
1112
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
1213
"github.com/owncloud/reva/v2/pkg/storage/utils/decomposedfs/node"
@@ -144,19 +145,26 @@ func (p Permissions) checkPermission(ctx context.Context, perm string, ref *prov
144145
return checkRes.Status.Code == v1beta11.Code_CODE_OK
145146
}
146147

147-
// IsManager returns true if the given resource permissions evaluate the user as "manager"
148-
func IsManager(rp *provider.ResourcePermissions) bool {
149-
return rp.RemoveGrant
148+
// editorPerms is the smallest space-editor bitmap; every richer space-editor variant and
149+
// the manager role are supersets of it, while viewers are not.
150+
var editorPerms = conversions.NewSpaceEditorWithoutVersionsWithoutTrashbinRole().CS3ResourcePermissions()
151+
152+
// IsSpaceManager returns true if the given resource permissions evaluate the user as "Space manager".
153+
// A manager holds the full grant-management triad; a single grant-management bit is not enough.
154+
// DenyGrant is not required, so legitimate manager/coowner grants that predate it still classify correctly.
155+
func IsSpaceManager(rp *provider.ResourcePermissions) bool {
156+
return rp.GetAddGrant() && rp.GetUpdateGrant() && rp.GetRemoveGrant()
150157
}
151158

152-
// IsEditor returns true if the given resource permissions evaluate the user as "editor"
153-
func IsEditor(rp *provider.ResourcePermissions) bool {
154-
return rp.InitiateFileUpload
159+
// IsSpaceEditor returns true if the given resource permissions evaluate the user as "Space editor"
160+
func IsSpaceEditor(rp *provider.ResourcePermissions) bool {
161+
return conversions.SufficientCS3Permissions(rp, editorPerms)
155162
}
156163

157-
// IsViewer returns true if the given resource permissions evaluate the user as "viewer"
158-
func IsViewer(rp *provider.ResourcePermissions) bool {
159-
return rp.Stat
164+
// IsSpaceViewer returns true if the given resource permissions evaluate the user as "Space viewer"
165+
// We couldn't use NewSpaceViewerRole because it carries ListRecycle, which the WithoutTrashbin space editors lack.
166+
func IsSpaceViewer(rp *provider.ResourcePermissions) bool {
167+
return rp.GetStat() && rp.GetGetPath() && rp.GetListGrants()
160168
}
161169

162170
func spaceRef(spaceid string) *provider.Reference {

0 commit comments

Comments
 (0)