ipfs / boxo

A set of reference libraries for building IPFS applications and implementations in Go.
https://github.com/ipfs/boxo#readme
Other
205 stars 89 forks source link

gateway: dedicated error type for denylists #591

Open aschmahmann opened 6 months ago

aschmahmann commented 6 months ago

Right now we don't use proper error types to convey that some content requested by a gateway was blocked. Instead we have this string based checking tied to nopfs

https://github.com/ipfs/boxo/blob/b101ba0858150cd6a34b6cb68eefd28c411bd58c/gateway/errors.go#L211-L216

@MichaelMure recently let me know that:

  1. Infura also does some string based error checking for their errors
  2. They return 451 when rather than just 410

So it seems to me like this should be bundled into boxo tooling.

  1. Have an error type indicating that it's a blocked error (which other tools like nopfs or others can wrap)
  2. Given that 451 and 410 both seem plausible either that should be configurable by the error tooling, or at the gateway level
    • At the moment I don't know anyone mixing 410s + 451s but that may not always be the case

@MichaelMure let me know if there's any context I missed.

cc @lidel

MichaelMure commented 6 months ago

Note: the same concerns exist for https://github.com/ipfs/go-ipfs-cmds. If we are not able to also return adequate HTTP status code there, then we'd still have to do string matching.

As for 451 vs 410, it's not too important imho. 451 seems more appropriate to me but if kubo goes for 410, I think we'd align to that.

MichaelMure commented 6 months ago

As for https://github.com/ipfs/go-ipfs-cmds, I think it would be a goal with beneficial side effects: right now, spread into kubo, some errors are just bubbling up and surface as 500s, because there is no way to classify them in a meaningful way for the user/client interface.

On the top of my head, there is:

Typically, those kind of errors would be implemented in a proxy, but that remains awkward. As more and more logic get built and integrated into kubo (or on top of boxo), more and more sources of this kind of errors get triggered deep into kubo/boxo, with no way to interpret them besides string matching. We already have errors akin to 451, 504 and 507 in those places.

A set of error wrapper, interpreted by the gateway and https://github.com/ipfs/go-ipfs-cmds would help quite a lot.