Skip to content

Commit 5eb32d2

Browse files
committed
Merge #15223: Doc: add information about security to the JSON-RPC doc
5a5ea93 Doc: add information about security to the JSON-RPC doc (David A. Harding) Pull request description: This documents some information about using the RPC interface securely, as suggested in bitcoin-core/bitcoincore.org#637 by @luke-jr and @TheBlueMatt. I think it should fit in well with #14458, but is not dependent on it (and shouldn't have any significant merge conflicts with it). Tree-SHA512: e09d82c3029ed17a8bcf50722ea25a8c6c514731f3bce01908cbb6fe48bc96a3068a025beabebc602d18e1bc0dc3f2602848abc05dca1d3efe2a988ee50068c0
2 parents 73a6bac + 5a5ea93 commit 5eb32d2

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

doc/JSON-RPC-interface.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,85 @@ The headless daemon `bitcoind` has the JSON-RPC API enabled by default, the GUI
55
option. In the GUI it is possible to execute RPC methods in the Debug Console
66
Dialog.
77

8+
## Security
9+
10+
The RPC interface allows other programs to control Bitcoin Core,
11+
including the ability to spend funds from your wallets, affect consensus
12+
verification, read private data, and otherwise perform operations that
13+
can cause loss of money, data, or privacy. This section suggests how
14+
you should use and configure Bitcoin Core to reduce the risk that its
15+
RPC interface will be abused.
16+
17+
- **Securing the executable:** Anyone with physical or remote access to
18+
the computer, container, or virtual machine running Bitcoin Core can
19+
compromise either the whole program or just the RPC interface. This
20+
includes being able to record any passphrases you enter for unlocking
21+
your encrypted wallets or changing settings so that your Bitcoin Core
22+
program tells you that certain transactions have multiple
23+
confirmations even when they aren't part of the best block chain. For
24+
this reason, you should not use Bitcoin Core for security sensitive
25+
operations on systems you do not exclusively control, such as shared
26+
computers or virtual private servers.
27+
28+
- **Securing local network access:** By default, the RPC interface can
29+
only be accessed by a client running on the same computer and only
30+
after the client provides a valid authentication credential (username
31+
and passphrase). Any program on your computer with access to the file
32+
system and local network can obtain this level of access.
33+
Additionally, other programs on your computer can attempt to provide
34+
an RPC interface on the same port as used by Bitcoin Core in order to
35+
trick you into revealing your authentication credentials. For this
36+
reason, it is important to only use Bitcoin Core for
37+
security-sensitive operations on a computer whose other programs you
38+
trust.
39+
40+
- **Securing remote network access:** You may optionally allow other
41+
computers to remotely control Bitcoin Core by setting the `rpcallowip`
42+
and `rpcbind` configuration parameters. These settings are only meant
43+
for enabling connections over secure private networks or connections
44+
that have been otherwise secured (e.g. using a VPN or port forwarding
45+
with SSH or stunnel). **Do not enable RPC connections over the public
46+
Internet.** Although Bitcoin Core's RPC interface does use
47+
authentication, it does not use encryption, so your login credentials
48+
are sent as clear text that can be read by anyone on your network
49+
path. Additionally, the RPC interface has not been hardened to
50+
withstand arbitrary Internet traffic, so changing the above settings
51+
to expose it to the Internet (even using something like a Tor hidden
52+
service) could expose you to unconsidered vulnerabilities. See
53+
`bitcoind -help` for more information about these settings and other
54+
settings described in this document.
55+
56+
Related, if you use Bitcoin Core inside a Docker container, you may
57+
need to expose the RPC port to the host system. The default way to
58+
do this in Docker also exposes the port to the public Internet.
59+
Instead, expose it only on the host system's localhost, for example:
60+
`-p 127.0.0.1:8332:8332`
61+
62+
- **Secure authentication:** By default, Bitcoin Core generates unique
63+
login credentials each time it restarts and puts them into a file
64+
readable only by the user that started Bitcoin Core, allowing any of
65+
that user's RPC clients with read access to the file to login
66+
automatically. The file is `.cookie` in the Bitcoin Core
67+
configuration directory, and using these credentials is the preferred
68+
RPC authentication method. If you need to generate static login
69+
credentials for your programs, you can use the script in the
70+
`share/rpcauth` directory in the Bitcoin Core source tree. As a final
71+
fallback, you can directly use manually-chosen `rpcuser` and
72+
`rpcpassword` configuration parameters---but you must ensure that you
73+
choose a strong and unique passphrase (and still don't use insecure
74+
networks, as mentioned above).
75+
76+
- **Secure string handling:** The RPC interface does not guarantee any
77+
escaping of data beyond what's necessary to encode it as JSON,
78+
although it does usually provide serialized data using a hex
79+
representation of the bytes. If you use RPC data in your programs or
80+
provide its data to other programs, you must ensure any problem
81+
strings are properly escaped. For example, multiple websites have
82+
been manipulated because they displayed decoded hex strings that
83+
included HTML `<script>` tags. For this reason, and other
84+
non-security reasons, it is recommended to display all serialized data
85+
in hex form only.
86+
887
## RPC consistency guarantees
988

1089
State that can be queried via RPCs is guaranteed to be at least up-to-date with

0 commit comments

Comments
 (0)