diff --git a/daemon.py b/daemon.py index a8f447584..025e2c812 100644 --- a/daemon.py +++ b/daemon.py @@ -488,7 +488,9 @@ class PubServer(BaseHTTPRequestHandler): createSession(self.server.domain,self.server.port,self.server.useTor) # treat shared inbox paths consistently - if self.path=='/sharedInbox' or self.path=='/users/inbox': + if self.path=='/sharedInbox' or \ + self.path=='/users/inbox' or \ + self.path=='/users/'+self.server.domain: self.path='/inbox' # is this a html request? diff --git a/epicyon.py b/epicyon.py index dbe3679e6..93b15002a 100644 --- a/epicyon.py +++ b/epicyon.py @@ -817,17 +817,9 @@ if args.actor: port=443 session = createSession(domain,port,useTor) if nickname!='inbox': - wfRequest = webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \ - domain,__version__) - else: - wfRequest={ - 'aliases': [httpPrefix+'://'+domain+'/@inbox', - httpPrefix+'://'+domain+'/users/inbox'], - 'links': [{'href': httpPrefix+'://'+domain+'/users/inbox', - 'rel': 'self', - 'type': 'application/activity+json'}], - 'subject': 'acct:inbox@'+domain - } + nickname=domain + wfRequest = webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \ + domain,__version__) if not wfRequest: print('Unable to webfinger '+nickname+'@'+domain) @@ -858,7 +850,7 @@ if args.addaccount: if not args.domain or not getConfigParam(baseDir,'domain'): print('Use the --domain option to set the domain name') sys.exit() - if not validNickname(nickname): + if not validNickname(domain,nickname): print(nickname+' is a reserved name. Use something different.') sys.exit() if not args.password: diff --git a/follow.py b/follow.py index 4289427b5..0a7f51776 100644 --- a/follow.py +++ b/follow.py @@ -207,7 +207,7 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \ nickname=path.replace('/@','',1).replace('/'+followFile,'') if not nickname: return None - if not validNickname(nickname): + if not validNickname(domain,nickname): return None if port: diff --git a/person.py b/person.py index af2c728cc..a46374bd4 100644 --- a/person.py +++ b/person.py @@ -248,7 +248,7 @@ def registerAccount(baseDir: str,httpPrefix: str,domain: str,port: int, \ """ if accountExists(baseDir,nickname,domain): return False - if not validNickname(nickname): + if not validNickname(domain,nickname): print('REGISTER: Nickname '+nickname+' is invalid') return False if len(password)<8: @@ -265,7 +265,7 @@ def createPerson(baseDir: str,nickname: str,domain: str,port: int, \ httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}): """Returns the private key, public key, actor and webfinger endpoint """ - if not validNickname(nickname): + if not validNickname(domain,nickname): return None,None,None,None # If a config.json file doesn't exist then don't decrement @@ -321,7 +321,8 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}: # is this a shared inbox lookup? isSharedInbox=False if path=='/inbox' or path=='/users/inbox' or path=='/sharedInbox': - path='/users/inbox' + # shared inbox actor on @domain@domain + path='/users/'+domain isSharedInbox=True else: notPersonLookup=['/inbox','/outbox','/outboxarchive', \ @@ -337,7 +338,7 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}: nickname=path.replace('/@','',1) if not nickname: return None - if not isSharedInbox and not validNickname(nickname): + if not isSharedInbox and not validNickname(domain,nickname): return None if ':' in domain: domain=domain.split(':')[0] @@ -391,7 +392,7 @@ def personBoxJson(baseDir: str,domain: str,port: int,path: str, \ nickname=path.replace('/@','',1).replace('/'+boxname,'') if not nickname: return None - if not validNickname(nickname): + if not validNickname(domain,nickname): return None if boxname=='inbox': return createInbox(baseDir,nickname,domain,port,httpPrefix, \ @@ -438,7 +439,7 @@ def personInboxJson(baseDir: str,domain: str,port: int,path: str, \ nickname=path.replace('/@','',1).replace('/inbox','') if not nickname: return None - if not validNickname(nickname): + if not validNickname(domain,nickname): return None return createInbox(baseDir,nickname,domain,port,httpPrefix, \ noOfItems,headerOnly,ocapAlways,pageNumber) diff --git a/posts.py b/posts.py index 7bf51f38e..ca7896346 100644 --- a/posts.py +++ b/posts.py @@ -792,7 +792,10 @@ def getMentionedPeople(baseDir: str,httpPrefix: str, \ if not ('.' in externalDomain or externalDomain=='localhost'): continue mentionedNickname=handle.split('@')[0] - if not validNickname(mentionedNickname): + mentionedDomain=handle.split('@')[1].strip('\n') + if ':' in mentionedDomain: + mentionedDomain=mentionedDomain.split(':')[0] + if not validNickname(mentionedDomain,mentionedNickname): continue actor=httpPrefix+'://'+handle.split('@')[1]+'/users/'+mentionedNickname mentions.append(actor) @@ -1167,6 +1170,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \ sharedInbox=False if toNickname=='inbox': + # shared inbox actor on @domain@domain + toNickname=toDomain sharedInbox=True if toPort: @@ -1174,37 +1179,18 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \ if ':' not in toDomain: toDomain=toDomain+':'+str(toPort) - if not sharedInbox: - handle=httpPrefix+'://'+toDomain+'/@'+toNickname - else: - handle=httpPrefix+'://'+toDomain+'/'+toNickname - sharedInboxUrl=handle + handle=httpPrefix+'://'+toDomain+'/@'+toNickname if debug: print('DEBUG: handle - '+handle+' toPort '+str(toPort)) - if not sharedInbox: - # lookup the inbox for the To handle - wfRequest=webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ - domain,projectVersion) - if not wfRequest: - if debug: - print('DEBUG: webfinger for '+handle+' failed') - return 1 - else: - wfRequest={ - "aliases": [ - httpPrefix+'://'+toDomain+'/users/inbox' - ], - "links": [ - { - "href": httpPrefix+'://'+toDomain+'/users/inbox', - "rel": "self", - "type": "application/activity+json" - } - ], - "subject": 'acct:inbox@'+toDomain - } + # lookup the inbox for the To handle + wfRequest=webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \ + domain,projectVersion) + if not wfRequest: + if debug: + print('DEBUG: webfinger for '+handle+' failed') + return 1 if not clientToServer: postToBox='inbox' diff --git a/shares.py b/shares.py index a60f0e120..9a2117411 100644 --- a/shares.py +++ b/shares.py @@ -202,7 +202,7 @@ def getSharesFeedForPerson(baseDir: str, \ nickname=path.replace('/@','',1).replace('/shares','') if not nickname: return None - if not validNickname(nickname): + if not validNickname(domain,nickname): return None if port: diff --git a/utils.py b/utils.py index a98141511..d4ec8ca54 100644 --- a/utils.py +++ b/utils.py @@ -265,11 +265,13 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena # finally, remove the post itself os.remove(postFilename) -def validNickname(nickname: str) -> bool: +def validNickname(domain: str,nickname: str) -> bool: forbiddenChars=['.',' ','/','?',':',';','@'] for c in forbiddenChars: if c in nickname: return False + if nickname==domain: + return False reservedNames=['inbox','outbox','following','followers','capabilities'] if nickname in reservedNames: return False