Skip to content

Commit

Permalink
Merge pull request #4946 from ipfs/fix/cidsec-bitswapstorm
Browse files Browse the repository at this point in the history
cid-sec: fix bitswap strom caused by insecure CIDs
  • Loading branch information
whyrusleeping authored Apr 20, 2018
2 parents 15859d3 + e5ff2c3 commit 8b383da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
19 changes: 13 additions & 6 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,22 @@ func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan bloc

func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block {
out := make(chan blocks.Block)
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err != nil {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
}
}

go func() {
defer close(out)

k := 0
for _, c := range ks {
// hash security
if err := verifcid.ValidateCid(c); err == nil {
ks[k] = c
k++
} else {
log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
}
}
ks = ks[:k]

var misses []*cid.Cid
for _, c := range ks {
hit, err := bs.Get(c)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

�
Um
10 changes: 10 additions & 0 deletions test/sharness/t0275-cid-security.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ test_gc
test_launch_ipfs_daemon
test_cat_get
test_gc

test_expect_success "add block linking to insecure" '
mkdir -p "$IPFS_PATH/blocks/5X" &&
cp -f "../t0275-cid-security-data/CIQG6PGTD2VV34S33BE4MNCQITBRFYUPYQLDXYARR3DQW37MOT7K5XI.data" "$IPFS_PATH/blocks/5X"
'

test_expect_success "ipfs cat fails with code 1 and not timeout" '
test_expect_code 1 go-timeout 1s ipfs cat QmVpsktzNeJdfWEpyeix93QJdQaBSgRNxebSbYSo9SQPGx
'

test_kill_ipfs_daemon

test_done

0 comments on commit 8b383da

Please sign in to comment.