Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth ticket prefix #1502

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading