Skip to content

Commit

Permalink
disallow creation of a group with empty name via the OCS api
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Nov 26, 2021
1 parent 54d450e commit 3799945
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions changelog/unreleased/fix-create-group-without-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Bugfix: Disallow creation of a group with empty name via the OCS api

We've fixed the behavior for group creation on the OCS api, where it was
possible to create a group with an empty name. This was is not possible
on oC10 and is therefore also forbidden on oCIS to keep compatibility.
This PR forbids the creation and also ensures the correct status codef
or both OCS v1 and OCS v2 apis.

https://github.com/owncloud/ocis/pull/2825
https://github.com/owncloud/ocis/issues/2823
20 changes: 16 additions & 4 deletions ocs/pkg/service/v0/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,27 @@ func (o Ocs) ListGroups(w http.ResponseWriter, r *http.Request) {
}

// AddGroup adds a group
// oC10 implementation: https://github.com/owncloud/core/blob/762780a23c9eadda4fb5fa8db99eba66a5100b6e/apps/provisioning_api/lib/Groups.php#L126-L154
func (o Ocs) AddGroup(w http.ResponseWriter, r *http.Request) {
groupid := r.PostFormValue("groupid")
displayname := r.PostFormValue("displayname")
gid := r.PostFormValue("gidnumber")

if displayname == "" && groupid == "" {
code := data.MetaFailure.StatusCode // v1
if response.APIVersion(r.Context()) == "2" {
code = data.MetaBadRequest.StatusCode
}
mustNotFail(render.Render(w, r, response.ErrRender(code, "No groupid or display name provided")))
return
}

if displayname == "" {
// oC10 OCS does not know about a group displayname
// therefore we fall back to the oC10 parameter groupid (which is the groupname in the oC10 world)
displayname = groupid
}

var gidNumber int64
var err error

Expand All @@ -289,10 +305,6 @@ func (o Ocs) AddGroup(w http.ResponseWriter, r *http.Request) {
}
}

if displayname == "" {
displayname = groupid
}

newGroup := &accounts.Group{
Id: groupid,
DisplayName: displayname,
Expand Down

0 comments on commit 3799945

Please sign in to comment.