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

feat(gw): /ipfs/ipfs/{cid} → /ipfs/{cid} #7930

Merged
merged 6 commits into from
Mar 24, 2021

Conversation

lidel
Copy link
Member

@lidel lidel commented Feb 19, 2021

This PR enables Gateways to recover from invalid paths like /ipfs/ipfs/{cid} and redirect them to proper one, when possible.

raison d'être is to

  • smooth out unforeseen addressing issues during initial adoption, and fix cosmetic mistakes like the value in image tag here (nft) 🐈🏳️‍🌈
  • make broken URIs resolve in Brave and Opera (because thats where most of people will paste those broken ipfs:// URI to address bar)
  • provide hint to developers on what should be fixed

cc @autonome

This will try to recover from invalid paths like  /ipfs/ipfs/{cid}
and redirect to proper one, when possible.
@lidel lidel added topic/gateway Topic gateway need/review Needs a review labels Feb 19, 2021
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
@Stebalien
Copy link
Member

This seems weird. This will magically make some invalid URLs "just work". Those invalid URLs will then propagate and become "normal" (requiring support).

Instead of patching go-ipfs to fix URLs like this for people, we should provide clear error messages describing what may/may not have gone wrong.

@lidel
Copy link
Member Author

lidel commented Feb 26, 2021

@Stebalien tbh we already have pretty clear error message:
https://dweb.link/ipfs/ipfs/Qmcg8f4F9cig2JWXunxJcdBe58Q5myYXPmGfuMn1TVeswD/nft.mp4
produces:

invalid ipfs path: invalid path "/ipfs/ipfs/Qmcg8f4F9cig2JWXunxJcdBe58Q5myYXPmGfuMn1TVeswD/nft.mp4": invalid CID: selected encoding not supported

I don't think we can make things more clear than "invalid path /ipfs/ipfs".

You have a valid point that silently fixing this == enabling misconfiguration to go unnoticed.
What if we return HTML with error message + redirect after 5seconds?

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="5;url={intendedURL}" /></head><body>invalid ipfs path: invalid path "{urlPath}": invalid CID: selected encoding not supported</body></html>

This way broken links still load (after a delay) + delay and error are enough signal for dev to fix the address in their NFT contract etc.

@Stebalien
Copy link
Member

Yeah, that seems reasonable.

This implements error page that does not hide the problem,
but still redirects to a valid path after short delay:
#7930 (comment)
@lidel
Copy link
Member Author

lidel commented Feb 26, 2021

@Stebalien implemented, looks like this (5s was IMO not enough to read the message):

2021-02-27--00-57-45

@Stebalien
Copy link
Member

It may be nicer to replace the entire error message explaining what the issue is, but either way works for me. "/ipfs/ipfs/Qm... should be /ipfs/Qm..." would make more sense than "invalid CID".

core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
@Stebalien Stebalien added need/author-input Needs input from the original author and removed need/review Needs a review labels Mar 11, 2021
- moved to separate utility function
- return Bad Request error
- improved escaping of values passed via URL path
@lidel lidel requested a review from Stebalien March 18, 2021 20:51
@lidel lidel added need/maintainers-input Needs input from the current maintainer(s) and removed need/author-input Needs input from the original author labels Mar 18, 2021
core/corehttp/gateway_handler.go Outdated Show resolved Hide resolved
@Stebalien Stebalien removed the need/maintainers-input Needs input from the current maintainer(s) label Mar 18, 2021
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. One more thing.

core/corehttp/gateway_handler.go Show resolved Hide resolved
lidel added a commit to lidel/minty that referenced this pull request Mar 19, 2021
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
@lidel lidel requested a review from Stebalien March 24, 2021 19:26
@Stebalien Stebalien merged commit d30f1e5 into master Mar 24, 2021
@Stebalien Stebalien deleted the fix/redundant-ns-on-gateway branch March 24, 2021 20:12
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Forest410 added a commit to Forest410/minty that referenced this pull request Oct 26, 2021
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
Believe-In-Miracles pushed a commit to Believe-In-Miracles/simple-mint that referenced this pull request Jan 30, 2022
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
salahawk added a commit to salahawk/minty that referenced this pull request Feb 16, 2022
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
venustar1228 added a commit to venustar1228/minty that referenced this pull request Feb 16, 2022
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
happyxurde1003 pushed a commit to happyxurde1003/minty that referenced this pull request May 30, 2022
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
devninja309 added a commit to devninja309/minty that referenced this pull request Jun 4, 2022
This ensures we dont contribute to problem described in:
ipfs/kubo#7930
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
This implements error page that does not hide the problem,
but still redirects to a valid path after short delay:
ipfs/kubo#7930 (comment)


This commit was moved from ipfs/kubo@dae7387
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
feat(gw): /ipfs/ipfs/{cid} → /ipfs/{cid}

This commit was moved from ipfs/kubo@d30f1e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/gateway Topic gateway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants