Skip to content

Commit b2f2b85

Browse files
committed
rpc: Add WWW-Authenticate header to 401 response
A WWW-Authenticate header must be present in the 401 response to make clients know that they can authenticate, and how. WWW-Authenticate: Basic realm="jsonrpc" Fixes #7462. Github-Pull: #7472 Rebased-From: 7c06fbd
1 parent b9ed8c9 commit b2f2b85

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/httprpc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <boost/algorithm/string.hpp> // boost::trim
1818
#include <boost/foreach.hpp> //BOOST_FOREACH
1919

20+
/** WWW-Authenticate to present with 401 Unauthorized response */
21+
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
22+
2023
/** Simple one-shot callback timer to be used by the RPC mechanism to e.g.
2124
* re-lock the wellet.
2225
*/
@@ -147,6 +150,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
147150
// Check authorization
148151
std::pair<bool, std::string> authHeader = req->GetHeader("authorization");
149152
if (!authHeader.first) {
153+
req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
150154
req->WriteReply(HTTP_UNAUTHORIZED);
151155
return false;
152156
}
@@ -159,6 +163,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
159163
shouldn't have their RPC port exposed. */
160164
MilliSleep(250);
161165

166+
req->WriteHeader("WWW-Authenticate", WWW_AUTH_HEADER_DATA);
162167
req->WriteReply(HTTP_UNAUTHORIZED);
163168
return false;
164169
}

0 commit comments

Comments
 (0)