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

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

Open
lidel opened this issue Oct 12, 2022 · 0 comments
Open

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

lidel opened this issue Oct 12, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@lidel
Copy link

lidel commented Oct 12, 2022

Problem

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

Turns out the edelweiss uses percent-encoded CBOR.

Example:

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, 😿 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants