Skip to content

Commit

Permalink
Merge pull request #1502 from 0chain/fix/auth-prefix
Browse files Browse the repository at this point in the history
Fix auth ticket prefix
  • Loading branch information
dabasov authored Nov 6, 2024
2 parents 22ca751 + c1f964a commit 9064282
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions code/go/0chain.net/blobbercore/handler/authticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package handler
import (
"context"
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker"
Expand Down Expand Up @@ -32,10 +31,14 @@ func verifyAuthTicket(ctx context.Context, authTokenString string, allocationObj
if err != nil {
return nil, err
}

if matched, _ := regexp.MatchString(fmt.Sprintf("^%v", authTokenRef.Path), refRequested.Path); !matched {
prefixPath := authTokenRef.Path
if prefixPath != "/" {
prefixPath += "/"
}
if !strings.HasPrefix(refRequested.Path, prefixPath) {
return nil, common.NewError("invalid_parameters", "Auth ticket is not valid for the resource being requested")
}

}
if verifyShare {
shareInfo, err := reference.GetShareInfo(ctx, authToken.ClientID, authToken.FilePathHash)
Expand Down

0 comments on commit 9064282

Please sign in to comment.