mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 13:42:10 +02:00
http: check rpcallowip immediately after accepting connection
Instead of sending 403 Forbidden, disconnect as soon as possible. To facilitate unit testing, this commit includes a refactor that moves the subnet allow list and relevant methods into the HTTPServer class instead of file-scope static scope.
This commit is contained in:
@@ -215,6 +215,11 @@ public:
|
||||
Assume(m_listen.empty()); // Missing call to StopListening()
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the user's -rpcallowip settings and populate m_allow_subnets
|
||||
*/
|
||||
bool InitHTTPAllowList();
|
||||
|
||||
/**
|
||||
* Bind to a new address:port, start listening and add the listen socket to `m_listen`.
|
||||
* @param[in] to Where to bind.
|
||||
@@ -376,6 +381,16 @@ private:
|
||||
*/
|
||||
std::chrono::seconds m_rpcservertimeout{DEFAULT_HTTP_SERVER_TIMEOUT};
|
||||
|
||||
/**
|
||||
* List of subnets to allow HTTP connections from
|
||||
*/
|
||||
std::vector<CSubNet> m_allow_subnets;
|
||||
|
||||
/**
|
||||
* Check an incoming connection's source IP against the allow list
|
||||
*/
|
||||
bool ClientAllowed(const CNetAddr& netaddr) const;
|
||||
|
||||
/**
|
||||
* Accept a connection.
|
||||
* @param[in] listen_sock Socket on which to accept the connection.
|
||||
|
||||
Reference in New Issue
Block a user