-
Notifications
You must be signed in to change notification settings - Fork 113
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 recursive copy/move operations on the API level #3009
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d33e26
Prevent recursive copy/move operations on the API level
aduffeck ca09131
Add changelog
aduffeck 47595a6
Enable machine auth in ocdav
aduffeck fee4ad1
Fix error message
aduffeck 1fb00ce
Also detect recursive operations when the SSP is involved
aduffeck d6ac392
Fix hound issues
aduffeck 6d40788
Set the owner on the stat response to the share jail
aduffeck f44e9e8
Implement GetPath() for the share jail root
aduffeck 102e7cf
Return a better error when the ocdav machine auth config is missing
aduffeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Prevent recursive copy/move operations | ||
|
||
We changed the ocs API to prevent copying or moving a folder into one of its children. | ||
|
||
https://github.com/cs3org/reva/pull/3009 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import ( | |
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" | ||
"github.com/cs3org/reva/v2/pkg/appctx" | ||
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" | ||
"github.com/cs3org/reva/v2/pkg/errtypes" | ||
"github.com/cs3org/reva/v2/pkg/rgrpc" | ||
"github.com/cs3org/reva/v2/pkg/rgrpc/status" | ||
|
@@ -272,6 +273,14 @@ func (s *service) GetPath(ctx context.Context, req *provider.GetPathRequest) (*p | |
// - getPath of every received share on the same space - needs also owner permissions -> needs machine auth | ||
// - find the shortest root path that is a prefix of the resource path | ||
// alternatively implement this on storageprovider - it needs to know about grants to do so | ||
|
||
if isShareJailRoot(req.ResourceId) { | ||
return &provider.GetPathResponse{ | ||
Status: status.NewOK(ctx), | ||
Path: "/", | ||
}, nil | ||
} | ||
|
||
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented") | ||
} | ||
|
||
|
@@ -662,6 +671,10 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide | |
} | ||
|
||
if isVirtualRoot(req.Ref) { | ||
owner, ok := ctxpkg.ContextGetUser(ctx) | ||
if !ok { | ||
return nil, fmt.Errorf("missing user in context") | ||
} | ||
receivedShares, shareMd, err := s.fetchShares(ctx) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -690,7 +703,8 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide | |
PermissionSet: &provider.ResourcePermissions{ | ||
// TODO | ||
}, | ||
Etag: shareMd[earliestShare.Id.OpaqueId].ETag, | ||
Etag: shareMd[earliestShare.Id.OpaqueId].ETag, | ||
Owner: owner.Id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 yes, the share jail is always owned by the current user |
||
}, | ||
}, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import ( | |
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net" | ||
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/spacelookup" | ||
"github.com/cs3org/reva/v2/pkg/appctx" | ||
"github.com/cs3org/reva/v2/pkg/errtypes" | ||
"github.com/cs3org/reva/v2/pkg/rhttp" | ||
"github.com/cs3org/reva/v2/pkg/rhttp/router" | ||
"github.com/cs3org/reva/v2/pkg/utils" | ||
|
@@ -486,6 +487,31 @@ func (s *svc) executeSpacesCopy(ctx context.Context, w http.ResponseWriter, clie | |
} | ||
|
||
func (s *svc) prepareCopy(ctx context.Context, w http.ResponseWriter, r *http.Request, srcRef, dstRef *provider.Reference, log *zerolog.Logger) *copy { | ||
client, err := s.getClient() | ||
if err != nil { | ||
log.Error().Err(err).Msg("error getting grpc client") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return nil | ||
} | ||
|
||
isChild, err := s.referenceIsChildOf(ctx, client, dstRef, srcRef) | ||
if err != nil { | ||
switch err.(type) { | ||
case errtypes.IsNotSupported: | ||
log.Error().Err(err).Msg("can not detect recursive copy operation. missing machine auth configuration?") | ||
w.WriteHeader(http.StatusForbidden) | ||
default: | ||
log.Error().Err(err).Msg("error while trying to detect recursive copy operation") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
} | ||
if isChild { | ||
w.WriteHeader(http.StatusBadRequest) | ||
b, err := errors.Marshal(http.StatusBadRequest, "can not copy a folder into one of its children", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
errors.HandleWebdavError(log, w, b, err) | ||
return nil | ||
} | ||
|
||
oh := r.Header.Get(net.HeaderOverwrite) | ||
overwrite, err := net.ParseOverwrite(oh) | ||
if err != nil { | ||
|
@@ -513,13 +539,6 @@ func (s *svc) prepareCopy(ctx context.Context, w http.ResponseWriter, r *http.Re | |
|
||
log.Debug().Bool("overwrite", overwrite).Str("depth", depth.String()).Msg("copy") | ||
|
||
client, err := s.getClient() | ||
if err != nil { | ||
log.Error().Err(err).Msg("error getting grpc client") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return nil | ||
} | ||
|
||
srcStatReq := &provider.StatRequest{Ref: srcRef} | ||
srcStatRes, err := client.Stat(ctx, srcStatReq) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 minimal implementation so we can get the path to the share jail root