Skip to content

Commit

Permalink
Merge pull request #3758 from micbar/fix-public-pw
Browse files Browse the repository at this point in the history
check for password during update public link
  • Loading branch information
micbar authored Mar 30, 2023
2 parents 02b82ee + 58416e0 commit 1f0e39b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-public-pw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix public links with enforced password

Fix the public link update operation in the case that a password is enforced.

https://github.com/cs3org/reva/pull/3758
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
Type: link.UpdatePublicShareRequest_Update_TYPE_PERMISSIONS,
Grant: &link.Grant{
Permissions: publicSharePermissions,
Password: r.FormValue("password"),
},
})
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/publicshare/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,22 @@ func (m *manager) UpdatePublicShare(ctx context.Context, u *user.User, req *link
old, _ := json.Marshal(share.Permissions)
new, _ := json.Marshal(req.Update.GetGrant().Permissions)

if m.writeableShareMustHavePassword && publicshare.IsWriteable(req.GetUpdate().GetGrant().GetPermissions()) && !share.PasswordProtected {
if m.writeableShareMustHavePassword &&
publicshare.IsWriteable(req.GetUpdate().GetGrant().GetPermissions()) &&
(!share.PasswordProtected && req.GetUpdate().GetGrant().GetPassword() == "") {
return nil, publicshare.ErrShareNeedsPassword
}

if req.GetUpdate().GetGrant().GetPassword() != "" {
passwordChanged = true
h, err := bcrypt.GenerateFromPassword([]byte(req.Update.GetGrant().Password), m.passwordHashCost)
if err != nil {
return nil, errors.Wrap(err, "could not hash share password")
}
newPasswordEncoded = string(h)
share.PasswordProtected = true
}

log.Debug().Str("json", "update grants").Msgf("from: `%v`\nto\n`%v`", old, new)
share.Permissions = req.Update.GetGrant().GetPermissions()
case link.UpdatePublicShareRequest_Update_TYPE_EXPIRATION:
Expand Down

0 comments on commit 1f0e39b

Please sign in to comment.