Skip to content

Commit 9064282

Browse files
authored
Merge pull request #1502 from 0chain/fix/auth-prefix
Fix auth ticket prefix
2 parents 22ca751 + c1f964a commit 9064282

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

code/go/0chain.net/blobbercore/handler/authticket.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package handler
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
7-
"regexp"
6+
"strings"
87

98
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
109
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker"
@@ -32,10 +31,14 @@ func verifyAuthTicket(ctx context.Context, authTokenString string, allocationObj
3231
if err != nil {
3332
return nil, err
3433
}
35-
36-
if matched, _ := regexp.MatchString(fmt.Sprintf("^%v", authTokenRef.Path), refRequested.Path); !matched {
34+
prefixPath := authTokenRef.Path
35+
if prefixPath != "/" {
36+
prefixPath += "/"
37+
}
38+
if !strings.HasPrefix(refRequested.Path, prefixPath) {
3739
return nil, common.NewError("invalid_parameters", "Auth ticket is not valid for the resource being requested")
3840
}
41+
3942
}
4043
if verifyShare {
4144
shareInfo, err := reference.GetShareInfo(ctx, authToken.ClientID, authToken.FilePathHash)

0 commit comments

Comments
 (0)