mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
fix #5618
This commit is contained in:
parent
83fcdbd561
commit
d5d9f5b46c
1 changed files with 8 additions and 6 deletions
|
@ -271,6 +271,7 @@ class Daemon(Logger):
|
||||||
@profiler
|
@profiler
|
||||||
def __init__(self, config: SimpleConfig, fd=None, *, listen_jsonrpc=True):
|
def __init__(self, config: SimpleConfig, fd=None, *, listen_jsonrpc=True):
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
|
self.auth_lock = asyncio.Lock()
|
||||||
self.running = False
|
self.running = False
|
||||||
self.running_lock = threading.Lock()
|
self.running_lock = threading.Lock()
|
||||||
self.config = config
|
self.config = config
|
||||||
|
@ -302,7 +303,7 @@ class Daemon(Logger):
|
||||||
if self.network:
|
if self.network:
|
||||||
self.network.start(jobs)
|
self.network.start(jobs)
|
||||||
|
|
||||||
def authenticate(self, headers):
|
async def authenticate(self, headers):
|
||||||
if self.rpc_password == '':
|
if self.rpc_password == '':
|
||||||
# RPC authentication is disabled
|
# RPC authentication is disabled
|
||||||
return
|
return
|
||||||
|
@ -317,14 +318,15 @@ class Daemon(Logger):
|
||||||
username, _, password = credentials.partition(':')
|
username, _, password = credentials.partition(':')
|
||||||
if not (constant_time_compare(username, self.rpc_user)
|
if not (constant_time_compare(username, self.rpc_user)
|
||||||
and constant_time_compare(password, self.rpc_password)):
|
and constant_time_compare(password, self.rpc_password)):
|
||||||
time.sleep(0.050)
|
await asyncio.sleep(0.050)
|
||||||
raise AuthenticationError('Invalid Credentials')
|
raise AuthenticationError('Invalid Credentials')
|
||||||
|
|
||||||
async def handle(self, request):
|
async def handle(self, request):
|
||||||
try:
|
async with self.auth_lock:
|
||||||
self.authenticate(request.headers)
|
try:
|
||||||
except AuthenticationError:
|
await self.authenticate(request.headers)
|
||||||
return web.Response(text='Forbidden', status=403)
|
except AuthenticationError:
|
||||||
|
return web.Response(text='Forbidden', status=403)
|
||||||
request = await request.text()
|
request = await request.text()
|
||||||
response = await jsonrpcserver.async_dispatch(request, methods=self.methods)
|
response = await jsonrpcserver.async_dispatch(request, methods=self.methods)
|
||||||
if isinstance(response, jsonrpcserver.response.ExceptionResponse):
|
if isinstance(response, jsonrpcserver.response.ExceptionResponse):
|
||||||
|
|
Loading…
Add table
Reference in a new issue