minor middleware changes and update izzylib requirements

This commit is contained in:
Izalia Mae 2021-09-18 01:34:23 -04:00
parent 057f737cf8
commit e5bdb40964
3 changed files with 24 additions and 17 deletions

View file

@ -1,10 +1,4 @@
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-base&subdirectory=base
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-password-hasher&subdirectory=hasher
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-server&subdirectory=http_server
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-urllib-client&subdirectory=http_urllib_client
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-sql&subdirectory=sql
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-templates&subdirectory=template
izzylib[hasher,http_server,http_urllib_client,sql,template] @ https://git.barkshark.xyz/izaliamae/izzylib/archive/0.7.0.tar.gz
envbash==1.2.0
pyyaml==5.4.1
pg8000==1.21.2

View file

@ -2,10 +2,10 @@ from izzylib import DotDict, logging
def cmd_actor(self, url):
cache = self.cache.actor_cache.fetch(url)
#cache = self.cache.actor_cache.fetch(url)
if cache:
return cache
#if cache:
#return cache
row = self.fetch('actor_cache', url=url)
@ -13,7 +13,7 @@ def cmd_actor(self, url):
return
data = DotDict(row.data)
self.cache.actor_cache.store(url, data)
#self.cache.actor_cache.store(url, data)
return data

View file

@ -44,20 +44,24 @@ class AuthCheck(MiddlewareBase):
with db.session as s:
request.ctx.token = s.fetch('token', code=token)
request.ctx.user = s.fetch('user', id=request.token.id) if request.token else None
request.ctx.user = s.fetch('user', id=request.ctx.token.id) if request.token else None
request.ctx.signature = parse_signature(request.headers.get('signature'))
request.ctx.instance = None
request.ctx.actor = None
if request.ctx.signature:
if request.ctx.signature.top_domain in blocked_instances:
domain = request.ctx.signature.domain
top_domain = request.ctx.signature.top_domain
actor = request.ctx.signature.actor
if top_domain in blocked_instances:
return response.text(f'This teapot kills fascists', status=418)
if any(map(s.get.ban, [None], [request.ctx.signature.domain, request.ctx.signature.top_domain])):
return response.text(f'no', status=403)
if any(map(s.get.ban, [None], [domain, top_domain])):
return response.text('no', status=403)
request.ctx.instance = s.get.instance(request.ctx.signature.domain)
request.ctx.actor = fetch_actor(request.ctx.signature.actor)
request.ctx.instance = s.get.instance(domain)
request.ctx.actor = fetch_actor(actor)
if request.path in ['/inbox', '/actor'] and request.method.lower() == 'post':
if not request.ctx.actor:
@ -71,6 +75,11 @@ class AuthCheck(MiddlewareBase):
return response.text(f'Invalid data', status=400)
try:
if type(request.ctx.actor).__name__ == 'Row':
logging.warning('Actor data is a db row:', actor)
logging.debug(request.ctx.actor.keys())
return response.text(f'An unknown error happened', status=500)
validated = verify_headers(
request.Headers.to_dict(),
request.method,
@ -83,6 +92,10 @@ class AuthCheck(MiddlewareBase):
logging.debug(f'Failed sig check: {e}')
return response.text(f'Failed signature check: {e}', status=401)
if not validated:
logging.debug(f'Not validated: {actor}')
return response.text(f'Failed signature check: {e}', status=401)
if not request.ctx.instance and data and data.type.lower() != 'follow':
return response.text(f'Follow the relay first', status=401)