mirror of https://gitlab.com/bashrc2/epicyon
Validate post content
parent
20accfd2f2
commit
4aa56256e8
33
inbox.py
33
inbox.py
|
@ -1095,7 +1095,26 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \
|
||||||
repliesFile.write(messageId+'\n')
|
repliesFile.write(messageId+'\n')
|
||||||
repliesFile.close()
|
repliesFile.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def validPostContent(messageJson: {}) -> bool:
|
||||||
|
"""Is the content of a received post valid?
|
||||||
|
"""
|
||||||
|
if not messageJson.get('object'):
|
||||||
|
return True
|
||||||
|
if not isinstance(messageJson['object'], dict):
|
||||||
|
return True
|
||||||
|
if not messageJson['object'].get('content'):
|
||||||
|
return True
|
||||||
|
invalidStrings=['<script>','<style>','</html>','</body>','<br>','<hr>']
|
||||||
|
for badStr in invalidStrings:
|
||||||
|
if badStr in messageJson['object']['content']:
|
||||||
|
if messageJson['object'].get('id'):
|
||||||
|
print('REJECT: '+messageJson['object']['id'])
|
||||||
|
print('REJECT: bad string in post - '+badStr)
|
||||||
|
return False
|
||||||
|
print('ACCEPT: post content is valid')
|
||||||
|
return True
|
||||||
|
|
||||||
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
baseDir: str,httpPrefix: str,sendThreads: [], \
|
baseDir: str,httpPrefix: str,sendThreads: [], \
|
||||||
postLog: [],cachedWebfingers: {},personCache: {}, \
|
postLog: [],cachedWebfingers: {},personCache: {}, \
|
||||||
|
@ -1182,13 +1201,15 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
|
|
||||||
if os.path.isfile(destinationFilename):
|
if os.path.isfile(destinationFilename):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if messageJson.get('postNickname'):
|
if messageJson.get('postNickname'):
|
||||||
with open(destinationFilename, 'w+') as fp:
|
if validPostContent(messageJson['post']):
|
||||||
commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False)
|
with open(destinationFilename, 'w+') as fp:
|
||||||
|
commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False)
|
||||||
else:
|
else:
|
||||||
with open(destinationFilename, 'w+') as fp:
|
if validPostContent(messageJson):
|
||||||
commentjson.dump(messageJson, fp, indent=4, sort_keys=False)
|
with open(destinationFilename, 'w+') as fp:
|
||||||
|
commentjson.dump(messageJson, fp, indent=4, sort_keys=False)
|
||||||
|
|
||||||
if not os.path.isfile(destinationFilename):
|
if not os.path.isfile(destinationFilename):
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue