Commit Graph

583 Commits

Author SHA1 Message Date
Marcin Rataj
fd01acdfc0
feat(gateway): ?filename with download=true
This implements 'attachment' mode triggered then
?filename parameter is accompanied with &download=true

When Content-Disposition: attachment is detected by a modern browser
it will skip rendering and immediately open the "save as" dialog,
making this useful feature for using IPFS gateway as target of
"Download" links on various websites.

Parameter name was suggested in:
https://github.com/ipfs/go-ipfs/pull/4177#issuecomment-414870327
2020-09-16 22:15:18 +02:00
Adin Schmahmann
45e574b6bd
Merge pull request #7610 from ipfs/chore/update-deps
chore: update dependencies
2020-08-25 23:14:52 -04:00
Adin Schmahmann
b88bdfeb9d chore: update go-multiaddr and go-multiaddr-net 2020-08-25 15:24:48 -04:00
Adin Schmahmann
bd08c0a4a6
Merge pull request #7550 from trashhalo/dry-up-close
use t.Cleanup() to reduce the need to clean up servers in tests
2020-08-25 12:06:26 -04:00
Kevin Neaton
2feff33235 test: update gateway tests for dir-index-html v1.1.0 2020-08-19 20:31:23 -04:00
Kevin Neaton
044790a838 feat: Directory page UI improvements
These changes are needed to prepare for the Directory page UI improvements
implemented in https://github.com/ipfs/dir-index-html/issues/37.

- update dir-index-html type structs
- emit gateway URL for root links
- emit CID of each directoryItem
- emit size of directory
- emit breadcrumbs
2020-08-19 20:09:35 -04:00
Marcin Rataj
6b6569f3e5
refactor: cleanup/comment
https://github.com/ipfs/go-ipfs/pull/7319#discussion_r472734905

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-08-19 15:59:47 +02:00
Marcin Rataj
2ff6f1a80d
test(gateway): IPNS cleanup and implicit defaults fix
This ensures implicit defaults are always present, even when
Gateway.PublicGateways is defined in the config.

User still can disable them, but needs to do it per hostname.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-08-06 14:00:16 +02:00
Michael Muré
13e6bcfb4f
feat: wildcard support for public gateways
Add support for one or more wildcards in the hostname definition
of a public gateway. This is useful for example to support easily
multiples environment.

Wildcarded hostname are set in the config as for example "*.domain.tld".
2020-07-24 20:51:22 +02:00
Rafael Ramalho
e3905e1fdc chore: bump webui version 2020-07-24 12:37:02 -04:00
Stephen Solka
4dbdbe0e02 use t.Cleanup() to reduce the need to clean up servers 2020-07-18 14:47:07 -04:00
Marcin Rataj
231fab811d feat: support ED25519 libp2p-key in subdomains
This:

- adds subdomain gateway support for ED25519 CIDs in a way that fits in
  a single DNS label to enable TLS for every IPNS website.

- cleans up subdomain redirect logic and adds more explicit error
  handling.

TL;DR on router logic:

When CID is longer than 63 characters, router at /ipfs/* and /ipns/*
converts to Base36, and if that does not help, returns a human readable
400 Bad Request error.

Addressing code review:
https://github.com/ipfs/go-ipfs/pull/7441#pullrequestreview-440043209

refactor: use b36 for all libp2p-keys in subdomains
Consensus reached in
https://github.com/ipfs/go-ipfs/pull/7441#discussion_r452372828
https://github.com/ipfs/go-ipfs/pull/7441#discussion_r451477890
https://github.com/ipfs/go-ipfs/pull/7441#discussion_r452500272
2020-07-10 16:25:20 -04:00
Michael Muré
87dfc46e03 feat: support X-Forwarded-Host when doing gateway redirect 2020-07-10 14:13:11 -04:00
Rafael Ramalho
4c38ea748a chore:bump webui version to 2.10.1 2020-06-23 16:28:38 +01:00
Rafael Ramalho
cc4a136360 chore: bump webui version 2020-06-22 17:39:30 +01:00
Steven Allen
84341d0c5a fix: use the correct context when resolving dnsaddr links 2020-06-17 19:44:28 -07:00
Marcin Rataj
5be7e0f8de feat: webui v2.9.0
(cherry picked from commit 0f76ed79f9)
2020-06-02 17:36:30 -07:00
Shotaro Yamada
bd9382fe41 chore: update WebUI to 2.8.0
(cherry picked from commit 58aac04a53)
2020-06-02 17:36:30 -07:00
Peter Rabbitson
2d5f8b4ebe Include the git blob id of the dir-index bundle in the ETag
While the content of raw files retrieved via the gateway should never
change, the look and feel of the directory index can and will change
between versions of go-ipfs.

Incorporate the hash of assets/bindata.go into the ETag when appropriate
2020-05-25 18:42:07 +00:00
Steven Allen
6a2fe0a20d fix: support directory listings even if a 404 page is present
fixes https://github.com/ipfs/go-ipfs/pull/4233#issuecomment-631454543

Basically, there's a trade-off here:

1. We can support directory listings while supporting 404 pages (this PR).
2. If a 404 page is present, directory listings don't work.

Given that option 1 is more flexible and users shouldn't be _too_ confused if
they land on a directory with no index.html page, I've gone with that option.
2020-05-20 19:11:50 -07:00
Peter Wu
d4952f2a73 fix(gateway): ensure directory listings have Content-Type text/html
Files already have an explicit Content-Type set. Be sure to do this for
directory listings as well to avoid a fallback to autodetection in
net/http. That fallback fails when a ResponseWriter is installed that
performs compression.
2020-05-20 15:20:33 +02:00
Peter Wu
7c7888c4db fix(gateway): fix status code for HEAD on redirects
Report a consistent status code for HEAD requests that end up in a
redirect.
2020-05-20 14:03:58 +02:00
JP Hastings-Spital
dfceafdbd3 Gateway renders pretty 404 pages if available
In the same way that an `index.html` file is rendered, if one is present, when the
requested path is a directory, now an `ipfs-404.html` file is rendered if
the requested file is not present within the specified IPFS object.

`ipfs-404.html` files are looked for in the directory of the requested path and each
parent until one is found, falling back on the well-known 404 error message.

License: MIT
Signed-off-by: JP Hastings-Spital <jphastings@gmail.com>
2020-05-19 14:41:21 -07:00
Gowtham G
e93f2002f5 optimize import order 2020-05-02 14:19:01 +05:30
Gowtham G
214d29ebf8 #7252 - print error message 2020-05-01 22:37:20 +05:30
Gowtham G
9201b1dde6 #7252 - read content directly instead of sending 512bytes 2020-05-01 20:29:32 +05:30
Gowtham G
2e87ac88a3 Fixes #7252 - Uses gabriel-vasile/mimetype to support additional content types 2020-05-01 12:19:36 +05:30
Steven Allen
46ae021733 feat: show the absolute path every time
Even for dnslink websites.

fixes https://github.com/ipfs/go-ipfs/issues/7205
2020-04-26 17:19:17 -07:00
Steven Allen
d8bc5c991e feat: always show the hash
Previously, we only showed this /ipns paths. However, knowing the hash of the
current directory is useful regardless.
2020-04-26 16:09:02 -07:00
Dimitris Apostolou
1e437c7e97
Fix typos and cleanup 2020-04-20 22:00:01 +03:00
Henrique Dias
135c451997
feat: webui 2.7.5 2020-04-17 20:10:21 +01:00
Marcin Rataj
8290ec11c3
fix: subdomain redirect for dir CIDs
Closes #7164

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-04-15 23:50:53 +02:00
Marcin Rataj
7d397ac219
feat: webui v2.7.4
(supersedes v2.7.3)

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-04-14 17:51:25 +02:00
Hector Sanjuan
7340543615 corehttp: Gateway handler: add Allow headers when returning MethodNotAllowed
Spec says that response with 405 must set Allow headers.
2020-04-05 09:57:57 +02:00
Hector Sanjuan
1b490476e5 HTTP API: Disallow GET requests on API
This commit upgrades go-ipfs-cmds and configures the commands HTTP API Handler
to only allow POST/OPTIONS, disallowing GET and others in the handling of
command requests in the IPFS HTTP API (where before every type of request
method was handled, with GET/POST/PUT/PATCH being equivalent).

The Read-Only commands that the HTTP API attaches to the gateway endpoint will
additional handled GET as they did before (but stop handling PUT,DELETEs).

By limiting the request types we address the possibility that a website
accessed by a browser abuses the IPFS API by issuing GET requests to it which
have no Origin or Referrer set, and are thus bypass CORS and CSRF protections.

This is a breaking change for clients that relay on GET requests against the
HTTP endpoint (usually :5001). Applications integrating on top of the
gateway-read-only API should still work (including cross-domain access).

Co-Authored-By: Steven Allen <steven@stebalien.com>
Co-Authored-By: Marcin Rataj <lidel@lidel.org>
2020-04-05 09:57:57 +02:00
Marcin Rataj
f9567a0a0f fix(gateway): curl without redirect on localhost
When request is sent to http://localhost:8080/ipfs/$cid response has
HTTP 301 status code and "Location" header with redirect destination at
$cid.ipfs.localhost:8080

Redirect is followed by browsersi, but not by commandline tools.
Status 301 is ignored by curl in default mode: it will print response
and won't follow redirect, user needs to add -L for that.

To fix curl, we return correct payload in body of HTTP 301 response,
but set Clear-Site-Data header to ensure Origin sandbox can't be abused.

This requires a surgical workaround:
If Location header is present in ResponseWriter's Header map,
we ensure http.ServeContent() returns HTTP 301

Context: https://github.com/ipfs/go-ipfs/pull/6982

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-03-18 08:50:40 -07:00
Marcin Rataj
3ecccd6e1d feat(gateway): subdomain and proxy gateway
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-03-18 08:50:38 -07:00
Steven Allen
72490f7ed0 gateway: simplify/improve dnslink rewrite handling
Instead of adding a new fake header (that could be spoofed by the client...),
just read the original request URI from the request object.

This also removes support for suborigins. They have never been implemented in
browsers and it looks like efforts have stalled. We can add support back if we
need it but, well, maintaining support was going to be more trouble than it was
worth.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-03-17 19:34:44 -07:00
Steven Allen
11c229bb14 rename ProxyOption to P2PProxyOption
(we're implementing an _actual_ proxy)

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-03-17 19:34:44 -07:00
Steven Allen
906f45edd9 fix(tracing): remove event tracing
We've deprecated this system and have yet to move to a new system. We might as
well remove everything, switch to a new system, then deliberately trace the
entire system.
2020-01-28 21:31:12 -08:00
Steven Allen
a53d48059b fix: migrate from deprecated warning function 2020-01-28 21:20:21 -08:00
Steven Allen
725e6844ee gateway: cleanup logic
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:13 +01:00
Steven Allen
5eea0a4ba0 http: use Method* constants
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:08 +01:00
Steven Allen
c64eb11992 test(gateway): test the lazy seeker 2020-01-05 16:43:45 -08:00
Steven Allen
6cb03d4dfd fix(gateway): fix seek read length typo 2020-01-05 16:43:45 -08:00
Steven Allen
453b78962b chore(gateway): remove dead code 2020-01-05 16:43:45 -08:00
Steven Allen
1a06fb6e2f fix(gateway): correct symlink content type
We should be _resolving_ symlinks (sometimes, still need to figure out when to
do this WRT IPNS). However, that's a larger feature.
2020-01-05 16:43:44 -08:00
Steven Allen
3859f08bf7 fix(gateway): better seeking/sized
1. Require files to have known sizes. We can add support for unknown sizes
_later_ but we can't use ServeContent for those files.
2. Replace the `sizeReadSeeker` with a `lazySeeker`. This one makes no
assumptions about how it's used so we're less likely to run into weird bugs.
2020-01-05 16:43:44 -08:00
Steven Allen
e8a6c0c050 fix(gateway): gracefully handle files with unknown sizes in directory listings 2020-01-05 16:43:44 -08:00
Steven Allen
62451039ec fix(gateway): serve the index with serveFile 2020-01-05 16:43:44 -08:00