helia icon indicating copy to clipboard operation
helia copied to clipboard

fix: @helia/* modules validate CID codec

Open tabcat opened this issue 1 year ago • 7 comments

Title

fix: @helia/* modules validate CID codec

Description

Closes: #377

@helia/* modules related to importing structured data, e.g. @helia/json; @helia/strings, check CID that is handed to .get method. If the CID code does not match the codec of the importer then it rejects with a TypeError.

  • [x] @helia/json
  • [ ] @helia/strings
  • [ ] @helia/dag-json
  • [ ] @helia/dag-cbor
  • [ ] ~~@helia/unixfs~~

Notes & open questions

Change checklist

  • [ ] I have performed a self-review of my own code
  • [ ] I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • [ ] I have added tests that prove my fix is effective or that my feature works

tabcat avatar Oct 03 '24 08:10 tabcat

Before I finish the other modules, does this approach look ok?

tabcat avatar Oct 03 '24 09:10 tabcat

Before I finish the other modules, does this approach look ok?

This looks good to me. It should be pretty straightforward

SgtPooki avatar Oct 23 '24 17:10 SgtPooki

The @helia/strings.get method accepts a codec as an option. Either the option is removed (specifying a codec like raw, the current default) or validation cannot happen on the CID passed to get.

tabcat avatar Oct 24 '24 11:10 tabcat

~Actually I can just check the CID.code is raw if no codec option is passed to get.~ IMO it would be best to not allow custom codecs to be passed to @helia/strings and just use 'utf8' encoding. If users are bringing their own codec then why not just interact with the blockstore directly?

tabcat avatar Oct 25 '24 08:10 tabcat

Removing @helia/unixfs from todo list for this PR as it's a bit different and more involved than the other importers.

tabcat avatar Dec 06 '24 05:12 tabcat

@tabcat are you still planning to work on this?

SgtPooki avatar Mar 20 '25 14:03 SgtPooki

Depends on https://github.com/ipfs/helia/pull/668

I'll resolve the conflicts on that PR

tabcat avatar Mar 20 '25 16:03 tabcat

I've fixed up the remaining modules.

Thanks for your patience on this one, it'll definitely help new developers!

achingbrain avatar Oct 07 '25 14:10 achingbrain