@cryptotaxi247 / kubo / commits / 421add3d1

daemon: reintroduce --unrestricted-api

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Jul 8, 2016 at 23:42 UTC 421add3d18d00ac62ad1a807f405574d4380710d
3 files changed +47 -6
cmd/ipfs/daemon.go
+15 -2
@@ -134,7 +134,7 @@ Headers.
134 cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)").Default(false),
135 cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
136 cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount). Defaults to config setting."),
137 - cmds.BoolOption(unrestrictedApiAccessKwd, "This option has no effect since v0.4.3").Default(false),
137 + cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes").Default(false),
138 cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)").Default(false),
139 cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false),
140 cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(true),
@@ -363,11 +363,24 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
363 apiMaddr = apiLis.Multiaddr()
364 fmt.Printf("API server listening on %s\n", apiMaddr)
365
366 + // by default, we don't let you load arbitrary ipfs objects through the api,
367 + // because this would open up the api to scripting vulnerabilities.
368 + // only the webui objects are allowed.
369 + // if you know what you're doing, go ahead and pass --unrestricted-api.
370 + unrestricted, _, err := req.Option(unrestrictedApiAccessKwd).Bool()
371 + if err != nil {
372 + return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
373 + }
374 + gatewayOpt := corehttp.GatewayOption(corehttp.WebUIPaths...)
375 + if unrestricted {
376 + gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns")
377 + }
378 +
379 var opts = []corehttp.ServeOption{
380 corehttp.MetricsCollectionOption("api"),
381 corehttp.CommandsOption(*req.InvocContext()),
382 corehttp.WebUIOption,
370 - corehttp.GatewayOption(corehttp.WebUIPaths...),
383 + gatewayOpt,
384 corehttp.VersionOption(),
385 defaultMux("/debug/vars"),
386 defaultMux("/debug/pprof/"),
test/sharness/t0110-gateway.sh
-4
@@ -32,10 +32,6 @@ test_expect_success "GET IPFS path output looks good" '
32 rm actual
33 '
34
35 -test_expect_success "GET IPFS path on API unavailable" '
36 - test_curl_resp_http_code "http://127.0.0.1:$apiport/ipfs/$HASH" "HTTP/1.1 404 Not Found"
37 -'
38 -
35 test_expect_success "GET IPFS directory path succeeds" '
36 mkdir dir &&
37 echo "12345" >dir/test &&
test/sharness/t0400-api-security.sh new
+32
@@ -0,0 +1,32 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2016 Lars Gierth
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +test_description="Test API security"
8 +
9 +. lib/test-lib.sh
10 +
11 +test_init_ipfs
12 +
13 +# by default, we don't let you load arbitrary ipfs objects through the api,
14 +# because this would open up the api to scripting vulnerabilities.
15 +# only the webui objects are allowed.
16 +# if you know what you're doing, go ahead and pass --unrestricted-api.
17 +
18 +test_launch_ipfs_daemon
19 +test_expect_success "Gateway on API unavailable" '
20 + HASH=$(echo "testing" | ipfs add -q)
21 + test_curl_resp_http_code "http://127.0.0.1:$API_PORT/ipfs/$HASH" "HTTP/1.1 404 Not Found"
22 +'
23 +test_kill_ipfs_daemon
24 +
25 +test_launch_ipfs_daemon --unrestricted-api
26 +test_expect_success "Gateway on --unrestricted-api API available" '
27 + HASH=$(echo "testing" | ipfs add -q)
28 + test_curl_resp_http_code "http://127.0.0.1:$API_PORT/ipfs/$HASH" "HTTP/1.1 200 OK"
29 +'
30 +test_kill_ipfs_daemon
31 +
32 +test_done