edelweiss icon indicating copy to clipboard operation
edelweiss copied to clipboard

Value in HTTP GET ?q= is percent-encoded CBOR

Open lidel opened this issue 3 years ago • 0 comments

Problem

The specification we've cleaned up in https://github.com/ipfs/specs/pull/326 states that the value from ?q=value is percent-encoded DAG-JSON.

Turns out the edelweiss uses percent-encoded CBOR.

Example:

  • pd8 "github.com/ipld/go-ipld-prime/codec/dagcbor" (and not dag-json) is used in places like https://github.com/ipfs/go-delegated-routing/blob/2646f6227c9411fc8825d9fed51a05cf2b740cab/gen/proto/proto_edelweiss.go#L1873-L1876

This creates a special kind of hell for implementers, especially JS, where not all binary can go through the binary string js unescape/charCodeAt safely, :crying_cat_face: Original spec was aiming to mitigate it by using plain text DAG-JSON OR multibase-encoded DAG-CBOR, as we know JS libraries for these do the right thing and no data corruption can occur.

Solution

Follow the spec, switch to percent-encoded DAG-JSON, but make it backward-compatible with format sent by Kubo 0.16: If DAG-JSON fails to parse, a fallback to current (invalid) percent-encoded-CBOR-as-string parser should occur.

Test sample

Kubo 0.16 sends:

%A1tFindProvidersRequest%A1cKey%D8%2AX%25%00%01p%12+%D56%5C%E5%8Bc%8D%1Fs%AC%95%1B%F5C%40Q%08%A5%02%B0DV%B3t%5B%B6%14%D5%BB%A5%E9%B6
$ "https://cid.contact/reframe?q=%A1tFindProvidersRequest%A1cKey%D8%2AX%25%00%01p%12+%D56%5C%E5%8Bc%8D%1Fs%AC%95%1B%F5C%40Q%08%A5%02%B0DV%B3t%5B%B6%14%D5%BB%A5%E9%B6" | jq
{"FindProvidersResponse":{"Providers":[{"Node":{"peer":{"ID":{"/":{"bytes":"EiAngCqwSSL46hQ5+DWaJsZ1SPV2RwrqwID/OEuj5Rdgqw"}},"Multiaddresses":[{"/":{"bytes":"NhFlbGFzdGljLmRhZy5ob3VzZQYBu94D"}}]}},"Proto":[{"2304":{}}]}]}}
decodeURIComponent("%A1tFindProvidersRequest%A1cKey%D8%2AX%25%00%01p%12+%D56%5C%E5%8Bc%8D%1Fs%AC%95%1B%F5C%40Q%08%A5%02%B0DV%B3t%5B%B6%14%D5%BB%A5%E9%B6") 

→ URIError: malformed URI sequence

lidel avatar Oct 12 '22 21:10 lidel