fix (share): access shared link multiple times issue

When trying to access a shared link protected with a password many
times over, user would see an ErrNotValid (case 2 from ShareVerifyProof in
ctrl/share.go). With this commit, we are making sure the proof cookie
doesn't grow more when trying to access the same link over and over again
This commit is contained in:
Mickael Kerjean
2022-07-20 00:25:39 +10:00
parent 1d47e557fc
commit a75a33d49b

View File

@ -46,7 +46,6 @@ func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) {
str := ""
index := 0
for {
cookie, err := req.Cookie(CookieName(index))
if err != nil {
break
@ -162,8 +161,17 @@ func ShareVerifyProof(ctx App, res http.ResponseWriter, req *http.Request) {
if submittedProof.Key != "" {
submittedProof.Id = Hash(submittedProof.Key+"::"+submittedProof.Value, 20)
alreadyExist := false
for i := 0; i < len(verifiedProof); i++ {
if verifiedProof[i].Id == submittedProof.Id {
alreadyExist = true
break
}
}
if alreadyExist == false {
verifiedProof = append(verifiedProof, submittedProof)
}
}
// 4) Find remaining proofs: requiredProof - verifiedProof
remainingProof = model.ShareProofCalculateRemainings(requiredProof, verifiedProof)