handle friendica and pass through json with auth fetch enabled
This commit is contained in:
parent
9d387b86aa
commit
1ea67bee39
|
@ -69,6 +69,7 @@ else:
|
|||
|
||||
MASTOCONFIG={
|
||||
'domain': env.get('WEB_DOMAIN', env.get('LOCAL_DOMAIN', 'localhost:3000')),
|
||||
'auth_fetch': bool_check(env.get('AUTHENTICATED_FETCH')),
|
||||
'dbhost': env.get('DB_HOST', '/var/run/postgresql'),
|
||||
'dbport': int(env.get('DB_PORT', 5432)),
|
||||
'dbname': env.get('DB_NAME', 'mastodon_production'),
|
||||
|
|
|
@ -53,6 +53,7 @@ def parse_ua(agent):
|
|||
ua1 = agent.split('https://')
|
||||
|
||||
if len(ua1) < 2:
|
||||
logging.warning(f'No url in user-agent: {agent}')
|
||||
return
|
||||
|
||||
if 'Mastodon' in agent:
|
||||
|
@ -64,9 +65,19 @@ def parse_ua(agent):
|
|||
elif 'Misskey' in agent:
|
||||
ua2 = ua1[1].split(')')
|
||||
|
||||
elif 'Friendica' in agent:
|
||||
logging.info(ua1[1])
|
||||
return ua1[1]
|
||||
|
||||
else:
|
||||
logging.warning(f'Unhandled user-agent: {agent}')
|
||||
|
||||
if len(ua2) > 1:
|
||||
logging.info(ua2[0])
|
||||
return ua2[0]
|
||||
|
||||
logging.warning(f'Invalid user-agent: {agent}')
|
||||
|
||||
|
||||
async def raise_auth_error(request, auth_realm):
|
||||
raise aiohttp.web.HTTPUnauthorized(
|
||||
|
@ -150,7 +161,7 @@ async def http_signatures(app, handler):
|
|||
|
||||
if any(map(request.path.startswith, auth_paths)) and request.method != 'POST':
|
||||
if json_req or request.path.endswith('.json'):
|
||||
if not user_check(request.path):
|
||||
if not user_check(request.path) and MASTOCONFIG['auth_fetch']:
|
||||
signature = request.headers.get('signature', '')
|
||||
|
||||
if not signature:
|
||||
|
@ -210,8 +221,7 @@ async def http_filter(app, handler):
|
|||
domain = parse_ua(ua)
|
||||
|
||||
if not domain:
|
||||
logging.info('Missing user-agent')
|
||||
raise json_error(401, 'Missing User-Agent')
|
||||
raise json_error(401, 'Can\'t parse user-agent')
|
||||
|
||||
if [agent for agent in blocked_agents if agent in request.headers.get('User-Agent', '').lower()]:
|
||||
logging.info(f'Blocked garbage: {domain}')
|
||||
|
|
Loading…
Reference in a new issue