Skip to content

Commit

Permalink
Disallow sharing the shares directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Aug 4, 2020
1 parent 83c5528 commit e6bf352
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions changelog/unreleased/shares-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Disallow sharing the shares directory

Previously, it was possible to create public links for and share the shares
directory itself. However, when the recipient tried to accept the share, it
failed. This PR prevents the creation of such shares in the first place.

https://github.com/cs3org/reva/pull/1051
4 changes: 4 additions & 0 deletions internal/grpc/services/gateway/publicshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
)

func (s *svc) CreatePublicShare(ctx context.Context, req *link.CreatePublicShareRequest) (*link.CreatePublicShareResponse, error) {
if s.isSharedFolder(ctx, req.ResourceInfo.GetPath()) {
return nil, errors.New("gateway: can't create a public share of the share folder itself")
}

log := appctx.GetLogger(ctx)
log.Info().Msg("create public share")

Expand Down
20 changes: 19 additions & 1 deletion internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,26 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
Path: target,
},
}

req.Ref = ref
return s.stat(ctx, req)
res, err := s.stat(ctx, req)
if err != nil {
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating"),
}, nil
}
if res.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(res.Status.Code, "gateway")
log.Err(err).Msg("gateway: error stating")
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating"),
}, nil
}

// we need to make sure we don't expose the reference target in the resource
// information.
res.Info.Path = p
return res, nil
}

panic("gateway: stating an unknown path:" + p)
Expand Down
5 changes: 5 additions & 0 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import (

// TODO(labkode): add multi-phase commit logic when commit share or commit ref is enabled.
func (s *svc) CreateShare(ctx context.Context, req *collaboration.CreateShareRequest) (*collaboration.CreateShareResponse, error) {

if s.isSharedFolder(ctx, req.ResourceInfo.GetPath()) {
return nil, errors.New("gateway: can't share the share folder itself")
}

c, err := pool.GetUserShareProviderClient(s.c.UserShareProviderEndpoint)
if err != nil {
return &collaboration.CreateShareResponse{
Expand Down

0 comments on commit e6bf352

Please sign in to comment.