Check that webfinger returns a valid actor url

master
Bob Mottram 2019-09-03 19:38:52 +01:00
parent fe135682c5
commit 536731f256
3 changed files with 13 additions and 3 deletions

View File

@ -115,7 +115,11 @@ def getUserUrl(wfRequest) -> str:
for link in wfRequest['links']:
if link.get('type') and link.get('href'):
if link['type'] == 'application/activity+json':
return link['href']
if '/users/' in link['href'] or '/profile/' in link['href']:
return link['href']
else:
print('Webfinger activity+json does not contain a valid actor')
print(link['href'])
return None
def parseUserFeed(session,feedUrl: str,asHeader: {}, \

View File

@ -51,14 +51,16 @@ def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}, \
wfDomain=wfDomain.split(':')[0]
wf=getWebfingerFromCache(nickname+'@'+wfDomain,cachedWebfingers)
if wf:
return wf
return wf
url = '{}://{}/.well-known/webfinger'.format(httpPrefix,domain)
par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)}
hdr = {'Accept': 'application/jrd+json'}
hdr = {'Accept': 'application/jrd+json'}
try:
result = getJson(session, url, hdr, par,projectVersion,httpPrefix,fromDomain)
except Exception as e:
print("Unable to webfinger " + url)
print('nickname: '+str(nickname))
print('domain: '+str(wfDomain))
print('headers: '+str(hdr))
print('params: '+str(par))
print(e)

View File

@ -2309,6 +2309,10 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \
return None
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
personUrl = getUserUrl(wf)
if not personUrl:
if debug:
print('DEBUG: Webfinger did not return an actor url')
return None
profileJson = getJson(session,personUrl,asHeader,None,projectVersion,httpPrefix,domain)
if not profileJson:
if debug: