Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fixes to local path traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed May 2, 2023
1 parent d2e7aab commit 5a41507
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/graph_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,30 +422,32 @@ func (api *GraphGateway) tryLoadPathFromBlockstore(ctx context.Context, p gatewa
var lastLink ipld.Link
var requestPath string
pathSel := pathAllSelector(rem)
if err := fetcherhelpers.BlockMatching(ctx, f, rootCidLink, pathSel, func(result fetcher.FetchResult) error {
err = fetcherhelpers.BlockMatching(ctx, f, rootCidLink, pathSel, func(result fetcher.FetchResult) error {
lastPath = result.LastBlockPath
lastLink = result.LastBlockLink
return nil
}); err != nil {
})
if err != nil {
if !errors.Is(err, format.ErrNotFound{}) {
graphLog.Error(err)
}
if lastLink == nil {
return p.String(), nil
}
}

requestPath = fmt.Sprintf("/ipfs/%s", lastLink.(cidlink.Link).Cid)
for i, ps := range lastPath.Segments() {
if i >= len(rem) {
requestPath = requestPath + strings.Join(rem[i:], "/")
return requestPath, nil
}
if ps.String() != rem[i] {
graphLog.Error(fmt.Errorf("selector path did not match ipfs path: expected %q got %q", rem[i], ps))
return p.String(), nil
}
requestPath = fmt.Sprintf("/ipfs/%s", lastLink.(cidlink.Link).Cid)
for i, ps := range lastPath.Segments() {
if i >= len(rem) {
requestPath = requestPath + strings.Join(rem[i:], "/")
return requestPath, nil
}
if ps.String() != rem[i] {
graphLog.Error(fmt.Errorf("selector path did not match ipfs path: expected %q got %q", rem[i], ps))
return p.String(), nil
}
}

return requestPath, nil
}

Expand Down

0 comments on commit 5a41507

Please sign in to comment.