mirror of https://gitlab.com/bashrc2/epicyon
Log svg scripts for subsequent review
parent
88fe018f1b
commit
5852de9746
14
content.py
14
content.py
|
@ -1683,7 +1683,8 @@ def create_edits_html(edits_json: {}, post_json_object: {},
|
||||||
edits_str + '</details>'
|
edits_str + '</details>'
|
||||||
|
|
||||||
|
|
||||||
def remove_script(content: str) -> str:
|
def remove_script(content: str, log_filename: str,
|
||||||
|
actor: str, url: str) -> str:
|
||||||
"""Removes <script> from some content
|
"""Removes <script> from some content
|
||||||
"""
|
"""
|
||||||
separators = [['<', '>'], ['<', '>']]
|
separators = [['<', '>'], ['<', '>']]
|
||||||
|
@ -1704,5 +1705,16 @@ def remove_script(content: str) -> str:
|
||||||
text = prefix + text.split(ending)[0] + ending
|
text = prefix + text.split(ending)[0] + ending
|
||||||
else:
|
else:
|
||||||
text = prefix + text.split('/' + sep[1])[0] + '/' + sep[1]
|
text = prefix + text.split('/' + sep[1])[0] + '/' + sep[1]
|
||||||
|
if log_filename and actor:
|
||||||
|
# write the detected script to a log file
|
||||||
|
log_str = actor + ' ' + url + ' ' + text + '\n'
|
||||||
|
writeType = 'a+'
|
||||||
|
if os.path.isfile(log_filename):
|
||||||
|
writeType = 'w+'
|
||||||
|
try:
|
||||||
|
with open(log_filename, writeType) as fp_log:
|
||||||
|
fp_log.write(log_str)
|
||||||
|
except OSError:
|
||||||
|
print('EX: cannot append to svg script log')
|
||||||
content = content.replace(text, '')
|
content = content.replace(text, '')
|
||||||
return content
|
return content
|
||||||
|
|
10
inbox.py
10
inbox.py
|
@ -150,6 +150,10 @@ def _cache_svg_images(session, base_dir: str, http_prefix: str,
|
||||||
return False
|
return False
|
||||||
cached = False
|
cached = False
|
||||||
post_id = remove_id_ending(obj['id']).replace('/', '--')
|
post_id = remove_id_ending(obj['id']).replace('/', '--')
|
||||||
|
actor = 'unknown'
|
||||||
|
if obj.get('attributedTo'):
|
||||||
|
actor = obj['attributedTo']
|
||||||
|
log_filename = base_dir + '/accounts/svg_scripts_log.txt'
|
||||||
for index in range(len(obj['attachment'])):
|
for index in range(len(obj['attachment'])):
|
||||||
attach = obj['attachment'][index]
|
attach = obj['attachment'][index]
|
||||||
if not attach.get('mediaType'):
|
if not attach.get('mediaType'):
|
||||||
|
@ -169,7 +173,7 @@ def _cache_svg_images(session, base_dir: str, http_prefix: str,
|
||||||
continue
|
continue
|
||||||
if '://' + i2p_domain in url:
|
if '://' + i2p_domain in url:
|
||||||
continue
|
continue
|
||||||
if '/' in filename:
|
if '/' in url:
|
||||||
filename = url.split('/')[-1]
|
filename = url.split('/')[-1]
|
||||||
else:
|
else:
|
||||||
filename = url
|
filename = url
|
||||||
|
@ -186,8 +190,10 @@ def _cache_svg_images(session, base_dir: str, http_prefix: str,
|
||||||
print('EX: unable to read svg file data')
|
print('EX: unable to read svg file data')
|
||||||
if image_data:
|
if image_data:
|
||||||
image_data = image_data.decode()
|
image_data = image_data.decode()
|
||||||
cleaned_up = remove_script(image_data)
|
cleaned_up = \
|
||||||
|
remove_script(image_data, log_filename, actor, url)
|
||||||
if cleaned_up != image_data:
|
if cleaned_up != image_data:
|
||||||
|
# write the cleaned up svg image
|
||||||
svg_written = False
|
svg_written = False
|
||||||
cleaned_up = cleaned_up.encode('utf-8')
|
cleaned_up = cleaned_up.encode('utf-8')
|
||||||
try:
|
try:
|
||||||
|
|
4
tests.py
4
tests.py
|
@ -3979,7 +3979,7 @@ def _test_danger_svg(base_dir: str) -> None:
|
||||||
' <circle cx="5" cy="5" r="4" />' + \
|
' <circle cx="5" cy="5" r="4" />' + \
|
||||||
'</svg>'
|
'</svg>'
|
||||||
assert not dangerous_svg(svg_content, False)
|
assert not dangerous_svg(svg_content, False)
|
||||||
cleaned_up = remove_script(svg_content)
|
cleaned_up = remove_script(svg_content, None, None, None)
|
||||||
assert cleaned_up == svg_content
|
assert cleaned_up == svg_content
|
||||||
svg_content = \
|
svg_content = \
|
||||||
' <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">' + \
|
' <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">' + \
|
||||||
|
@ -4007,7 +4007,7 @@ def _test_danger_svg(base_dir: str) -> None:
|
||||||
' <circle cx="5" cy="5" r="4" />' + \
|
' <circle cx="5" cy="5" r="4" />' + \
|
||||||
'</svg>'
|
'</svg>'
|
||||||
|
|
||||||
cleaned_up = remove_script(svg_content)
|
cleaned_up = remove_script(svg_content, None, None, None)
|
||||||
assert '<script' not in cleaned_up
|
assert '<script' not in cleaned_up
|
||||||
assert '/script>' not in cleaned_up
|
assert '/script>' not in cleaned_up
|
||||||
if cleaned_up != svg_clean:
|
if cleaned_up != svg_clean:
|
||||||
|
|
Loading…
Reference in New Issue