Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.18.0-rc2: 400 when "Accept: application/json, text/plain" #9520

Closed
3 tasks done
hamptonsmith opened this issue Dec 26, 2022 · 2 comments · Fixed by #9533
Closed
3 tasks done

0.18.0-rc2: 400 when "Accept: application/json, text/plain" #9520

hamptonsmith opened this issue Dec 26, 2022 · 2 comments · Fixed by #9533
Assignees
Labels
kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up

Comments

@hamptonsmith
Copy link

Checklist

Installation method

ipfs-desktop

Version

docker run -p 8080:8080 --rm ipfs/kubo:v0.18.0-rc1

Config

Default for docker container.

Description

Pinata made my Christmas interesting by making rc0.18 their prod-facing release, so apologies if this RC isn't to the point of stability where you care about this sort of thing, but since I did all the work to track it down, here's the info. :) Best!

$ docker run -p 8080:8080 --rm ipfs/kubo:v0.18.0-rc1 &
$ http localhost:8080/ipfs/bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa Accept:'application/json'
> [200 OK, ...successful output...]
$ http localhost:8080/ipfs/bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa Accept:'application/json, text/plain'
> HTTP/1.1 400 Bad Request
Content-Length: 87
Content-Type: text/plain; charset=utf-8
Date: Mon, 26 Dec 2022 12:02:19 GMT
Location: http://bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa.ipfs.localhost:8080/
X-Content-Type-Options: nosniff

error while processing the Accept header: mime: unexpected content after media subtype
$ http localhost:8080/ipfs/bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa Accept:'foo/bar, application/json, text/plain'
> [200 OK, ...successful output...]

Suspect this was introduced in fdd1965 with error on line

strings.HasPrefix(accept, "application/json") ||

@hamptonsmith hamptonsmith added kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization labels Dec 26, 2022
@stevedylandev
Copy link

We've also come across this problem and believe its from this PR #9335

@lidel lidel moved this to 🥞 Todo in IPFS Shipyard Team Jan 11, 2023
@lidel lidel changed the title 0.18.0-rc1: 400 when Accept header starts with application/json, 0.18.0-rc2: 400 when "Accept: application/json, text/plain" Jan 11, 2023
@lidel
Copy link
Member

lidel commented Jan 11, 2023

Thank you for reporting this.

Confirmed, this is still the problem with 0.18.0-rc2, error appears only when application/json is the first on the list that has more than one item.

Repro:

$ curl -H "Accept: application/json" "http://127.0.0.1:8080/ipfs/bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa"
{"Data":{"/":{"bytes":"CAIStwJ7Im5hbWUiOiJNQURFLi4uIiwiZGVzY3JpcHRpb24iOiIuLi4gc2l0dGluZyBvbiBhIGNoYWlyIGluIHRoZSBza3kgLiIsImltYWdlIjoiaHR0cHM6Ly9jaWwuYXBpLmJhbmR3YWdvbmZhbmNsdWIuY29tL2NvbGxlY3Rpb25zL3BvZXQvaW1hZ2VzL0d4YkhnNHROYlNhaXVOaTJteXpMaUJrWk4xNjZYNDV5UkxZbzNyaHZqZEtVIiwidGFncyI6WyJwYWludGluZyIsImRpZ2l0YWxwYWludCIsImZyYW1lYnlmcmFtZSIsImFuaW1hdGlvbiIsImdpZiJdLCJwb2V0T3duZXIiOiIweGFiMzYyNzMxN2M0M2QzOTRlYjE3MTE3MGY4MTgxNTNiOTc2ZDI4YTMifRi3Ag"}},"Links":[]}

$ curl -H "Accept: application/json, plain/text" "http://127.0.0.1:8080/ipfs/bafybeieznmzzuxoxqwmkgy5yycefaehgoswvc6yiu6mfhbblzkkj77w7oa"
error while processing the Accept header: mime: unexpected content after media subtype

This is a bug in the way we parse Accept header, block/car responses always had single explicit type, with JSON we should fix this.

Will prepare fix shortly in #9533 and will ship it in final 0.18.

@lidel lidel self-assigned this Jan 11, 2023
@lidel lidel added P1 High: Likely tackled by core team if no one steps up and removed need/triage Needs initial labeling and prioritization labels Jan 11, 2023
lidel added a commit that referenced this issue Jan 11, 2023
Block/CAR responses always had single explicit type, and we did not bother
with implementing/testing lists.

With the introduction of JSON people may start passing a list.
This is the most basic fix which will return on the first matching
type (in order). This does not implements weights (can be added in
future, if needed).

Closes #9520
lidel added a commit that referenced this issue Jan 11, 2023
Block/CAR responses always had single explicit type, and we did not bother
with implementing/testing lists.

With the introduction of JSON people may start passing a list.
This is the most basic fix which will return on the first matching
type (in order). This does not implements weights (can be added in
future, if needed).

Closes #9520
@github-project-automation github-project-automation bot moved this from 🥞 Todo to 🎉 Done in IPFS Shipyard Team Jan 11, 2023
lidel added a commit that referenced this issue Jan 11, 2023
Block/CAR responses always had single explicit type, and we did not bother
with implementing/testing lists.

With the introduction of JSON people may start passing a list.
This is the most basic fix which will return on the first matching
type (in order). This does not implements weights (can be added in
future, if needed).

Closes #9520
galargh pushed a commit that referenced this issue Jan 23, 2023
Block/CAR responses always had single explicit type, and we did not bother
with implementing/testing lists.

With the introduction of JSON people may start passing a list.
This is the most basic fix which will return on the first matching
type (in order). This does not implements weights (can be added in
future, if needed).

Closes #9520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants