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

Sites under public gateways list can't make XHR request #45

Closed
Kubuxu opened this issue Jan 13, 2016 · 5 comments
Closed

Sites under public gateways list can't make XHR request #45

Kubuxu opened this issue Jan 13, 2016 · 5 comments
Labels
kind/bug A bug in existing code (including security flaws) status/blocked Unable to be worked further until needs are met

Comments

@Kubuxu
Copy link
Member

Kubuxu commented Jan 13, 2016

I have site http://bin.kubuxu.ovh, its A records are same as ipfs.io. If I add it to the public gateways list XHR request to /ipfs/[some hash] fails because it is rerouted to local gateway which breaks AJAX somehow. In my case solution would be to redirect site to: http://localhost:8080/ipns/bin.kubuxu.ovh/ then XHR will be allowed to fetch data from /ipfs/....

The solution for this problem might be tricky as for example http://ipfs.pics has to make requests to severs itself (it does not have dnslink).

@lidel
Copy link
Member

lidel commented Jan 13, 2016

Indeed: I've put a breakpoint in the error callback of $.ajax request and the err.status() returns rejected (and not much beside that).

We probably need to dig into jQuery internals to understand this better,
perhaps XHR requests require some additional logic.

(For future reference: jQuery used by http://bin.kubuxu.ovh is v1.7.1)

@lidel lidel added the kind/bug A bug in existing code (including security flaws) label Jan 13, 2016
@Kubuxu
Copy link
Member Author

Kubuxu commented Jan 14, 2016

Also the request is not even sent (I Wireshark'ed it).

@lidel
Copy link
Member

lidel commented Jan 15, 2016

Ok, I (probably) know what is happening.

2016-01-15-184300_640x117_scrot

Doing XHR request with gateway redirect enabled is effectively doing cross-domain scripting.

Firefox protects users from XSS and executes requests like this only if target server is explicitly configured to accept them. It is indicated via CORS headers and what Firefox does here it to issue OPTIONS request to the gateway to check for them.

I have go-ipfs v0.3.11-dev and it does not support OPTIONS by default:

> curl -X OPTIONS http://127.0.0.1:8080/ipfs/QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK
Method OPTIONS not allowed: read only access

What is more, CORS headers are also missing in gateway responses:

> curl -X HEAD -I http://127.0.0.1:8080/ipfs/QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK
HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output
Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output
Cache-Control: public, max-age=29030400
Content-Length: 624
Content-Type: text/plain; charset=utf-8
Etag: QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK
Last-Modified: Thu, 01 Jan 1970 00:00:01 GMT
Suborigin: QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK
X-Ipfs-Path: /ipfs/QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK
Date: Fri, 15 Jan 2016 18:05:26 GMT

It is a known issue and was mentioned in ipfs/kubo#1215 (comment) and ipfs/kubo#934 (comment).

So it is not a bug in Addon/Firefox, but the default behaviour of IPFS Gateway. 😧

Running writable gateway with CORS headers is supported by go-ipfs, but you need to enable it manually:

ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Headers '["X-Requested-With"]'
ipfs config --json Gateway.Writable true

Then restart the daemon.

Sadly, OPTION still does not work:

curl -X OPTIONS http://127.0.0.1:8080/ipfs/QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK

18:45:57.364 ERROR core/serve: Method OPTIONS not allowed: bad request for /ipfs/QmRqoVq1G9pL7hyLB2EGi5mndRTQv7tKfFXPRUsSbpHqfK gateway_handler.go:94

I'll pursue it further, perhaps we need add OPTIONS to gateway_handler.go:80.

@lidel lidel added the status/blocked Unable to be worked further until needs are met label Jan 15, 2016
@ghost
Copy link

ghost commented Jan 16, 2016

I'll pursue it further, perhaps we need add OPTIONS to gateway_handler.go:80.

👍

@lidel
Copy link
Member

lidel commented Jan 24, 2016

OPTIONS support fixed upstream.
A related discussion about CORS/XHR support for API is continued in ipfs/kubo#2239

@lidel lidel closed this as completed Jan 24, 2016
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) status/blocked Unable to be worked further until needs are met
Projects
None yet
Development

No branches or pull requests

2 participants